Subject Re: [firebird-support] Digest Number 9396
Author Helen Borrie
Monday, November 21, 2016, 8:37:50 PM, tiberiu_horvath@... wrote:

> This is how I create my temporary tables :

> create global temporary table TEMP_112233
> (
> id : INTEGER,
> name : CHAR(20)
> )
> on commit preserve rows

You should create your GTT only once in your life, not every time you
want to use it! An instance of your GTT will be created as soon as
the client inserts some data into it. An instance of this GTT will
survive as long as this client remains connected and no other client
can see this instance.

> I also do some create views :

> CREATE OR ALTER VIEW CAUT_PRODUSE_VIEW_4982590
> (
> COD_PRODUS,
> ID_PRODUS
> )

> AS
> select
> produse.cod_produs,
> produse.id_produs

> from produse
> inner join sortiment on (sortiment.id_sortiment + 0 = produse.id_sortiment)
> where

> denumire_sortiment <> 'N'

OK, but that JOIN criterion is strange. Do you not want the optimizer
to use the index on sortiment.id_sortiment if it would be useful? This
syntax deliberately blocks use of that index.

A view is not a temporary table. Effectively, it is a "stored query"
that you define in order to get a pre-defined data set each time you
select from it or join to it.

> I do not know about any domain definitions, this should be an internal FireBird thing.


> if I have RDB$1 defined this way :


> CREATE DOMAIN RDB$1 AS INTEGER


> whenever I create another table with an Integer field, this domain should be used, am I wrong ?

Yes: you are quite wrong. You should not create any domains with
names that start 'RDB$' because Firebird uses that prefix to create
its internal domains, which are not intended for use by humans. If
you want to use domains (a very good idea!) you should create your own
domains with useful names. Do not "borrow" Firebird's internal domains.

> is there a command

> create table TEMP_112233
> (
> id : INTEGER use domain RDB$1
> )

This is what you do. Suppose you want a domain called ID_BASE of type
integer that you want to use for creating primary keys everywhere.
You define this domain ID_BASE with the attributes you need for any
primary key. You probably have some other types you would like to
have on hand, too. For example,

CREATE DOMAIN D_ID_BASE INTEGER NOT NULL

CREATE DOMAIN D_INDICATOR CHAR(3)
COLLATION ISO8859_2
CHECK VALUE = UPPER(VALUE)

CREATE DOMAIN D_SHORT_DATA VARCHAR(99)

Now, you have have 3 domains - think of them as custom data types, if
you like. Just use the domain name like a data type when you create
the columns that you want having those attributes:

create table aTable (
id D_ID_BASE,
description D_SHORT_DATA,
status D_INDICATOR,
{..other columns..},
constraint pk_atable primary key(id)
)

You can also use these 'custom data types' in stored procedures,
triggers, executable blocks and, in Fb3, stored functions, e.g.,

create procedure ...
...
...
declare aVariable D_INDICATOR;
declare bVariable TYPE OF D_SHORT_DATA; <-- gets the data type
without the other attributes

The Firebird 2.5 Language Reference has a lot of detail about
domains, GTTs and everything else about Firebird's SQL language.
You need it. ;-)

http://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/Firebird_Language_Reference_25EN.pdf

or you can study it on-line in html:

http://www.firebirdsql.org/file/documentation/reference_manuals/fblangref25-en/html/fblangref25.html

Helen