Sequences
Posted in 2005
Topics: Versions, Editions & End-of-Life
Is it possible to set up sequences to mimic the actions of a serial
field ? (IDS 9.4 FC2)
I want to be able to insert a new record with out changing the
application code but with more control of the limits of the serial
field.
I have a table -
create table tab1 ( tab1_id int8, descrip char(20) ) ;
alter table tab1 add constraint primary key (tab1_id) constraintpk_tab1;
And a sequence -
create sequence tab1_seq start with 10000 maxvalue 19999 cycle ;
I would like to run sql -
insert into tab1 ( descript ) values ("first record" )
And to see -
tab1_id descrip
10000 first record
How can I link one to the other ? The Syntax manual is unclear although
it mentions synonyms, and the SQL tutorial does not mention them.
Colin Bull
_______________________________________________________________________
This email has been scanned for all known viruses by the MessageLabs Email
Security System.
_______________________________________________________________________
sending to informix-list
colin,
according to the SQL syntax Guide "Authorized users of a sequence can
request a new value by including the sequence.NEXTBAL expression in SQL
statement"
http://publibfp.boulder.ibm.com/epubs/pdf/ct1sqna.under "create
sequence" (2-207)
so, I tried :
create table tab1 ( tab1_id int8, descript char(20) ) ;
alter table tab1 add constraint primary key (tab1_id) constraintpk_tab1;
create sequence tab1_seq start with 10000 maxvalue 19999 cycle;
insert into tab1 ( tab1_id, descript )
values (tab1_seq.nextval,"first" );
insert into tab1 ( tab1_id, descript )
values (tab1_seq.nextval,"second" );
select * from tab1;
seems to do what you want
Colin Bull wrote:
> Is it possible to set up sequences to mimic the actions of a serial
> field ? (IDS 9.4 FC2)
> I want to be able to insert a new record with out changing the
> application code but with more control of the limits of the serial
> field.
>
> I have a table -
> create table tab1 ( tab1_id int8, descrip char(20) ) ;
> alter table tab1 add constraint primary key (tab1_id)constraint
> pk_tab1;
>
> And a sequence -
> create sequence tab1_seq start with 10000 maxvalue 19999 cycle ;>
> I would like to run sql -
> insert into tab1 ( descript ) values ("first record" )>
> And to see -
>
> tab1_id descrip
> 10000 first record
>
>
> How can I link one to the other ? The Syntax manual is unclear
although
> it mentions synonyms, and the SQL tutorial does not mention them.
>
>
> Colin Bull
>
>
_______________________________________________________________________
> This email has been scanned for all known viruses by the MessageLabs
Email
> Security System.
>
_______________________________________________________________________
>
> sending to informix-list
not only can I not spell, I can't copy!!!! sequence.NEXTVAL