Subject Re: [firebird-support] Primary Key Initial Value
Author Norman Dunbar
Afternoon jwcane2003,

On 18/06/13 14:26, jwcane2003 wrote:
> In creating a new table, how is primary key set to begin at a value other than 0 or 1?

Imagine this:

create table whatever (
pk_column bigint not null ,
other_stuff char(100),

alter table whatever
add constraint pk_whatever
primary key (pk_column);

Insert into whatever (pk_column, other_stuff)
values (667, 'The neighbour of the beast!');


In this example, the pk_column will be set to whatever value is passed
to the INSERT statement and need not start at zero or one.

If, as is possible, you are using a sequence to generate the values -
say via a trigger, then you simply set the sequence value to the desired
starting number.

So, if you used a sequence named seq_pk_whatever, you could - before
using it for the first time - execute the following to ensure that the
next value generated will be 667:

set generator seq_pk_whatever to 666;



Norman Dunbar
Dunbar IT Consultants Ltd

Registered address:
Thorpe House
61 Richardshaw Lane
West Yorkshire
United Kingdom
LS28 7EL

Company Number: 05132767