Subject Re: Generators questions
Author m24paul
Because GEN_ID increment with 1 your generator, for each record in
your table. and show it !
If u need a 'autoincrement' field you shoud create a trigger for that:
if your database is Dialect 3:
CREATE TRIGGER TABLE1_SEQ FOR TABLE1
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.IDDOC IS NULL) THEN
NEW.IDDOC = next value for GEN_N;
END

if your database is Dialect 1:
CREATE TRIGGER TABLE1_SEQ FOR TABLE1
ACTIVE BEFORE INSERT POSITION 0
AS
BEGIN
IF (NEW.IDDOC IS NULL) THEN
NEW.IDDOC = GEN_ID(GEN_N,1);
END


Regards,
Paul

--- In firebird-support@yahoogroups.com, Ionut Ichim <ionut_ykm@...>
wrote:
>
> I've created a table (table1) with IDcod as pk numeric(18,0),then
a generator
>
>
>
> CREATE GENERATOR GEN_N;
>
> SET GENERATOR GEN_N TO 1;
>
>
>
> I've inserted 3 records for IDcod values 5,6,7.
>
> With IBExpert Personal,in a script I put this :
>
>
>
>
>
> SELECT gen_id(gen_N,1) FROM table1;
>
>
>
> Result :
>
> 2 3 4
>
> run again
>
> 5 6 7
>
>
>
> Why generator creates such result, for each record a value
generated.
> Where is the value i look for ?
> Wouldn't it be slow for a big database ?
>
> Why generator creates values that can duplicate pk,or I have to use
generator from the start ?
>
> Thanks.
>
>
>
>
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> [Non-text portions of this message have been removed]
>