Subject | Re: [firebird-support] INTEGER or BIGINT for table primary key? |
---|---|
Author | Paul Vinkenoog |
Post date | 2011-07-09T20:56:04Z |
Hi Jacob,
ALTER SEQUENCE CarID_CARS_GEN RESTART WITH 1
If you do use SET GENERATOR, don't forget 'TO':
SET GENERATOR CarID_CARS_GEN TO 1
BTW, if you set the generator/sequence to 1, the first issued ID will be 2.
Cheers,
Paul Vinkenoog
> Is it ok to use INTEGER as a primary key incremented with at generator trigger?If you're absolutely sure that the positive INTEGER range is big enough (and will be for the lifetime of your database!) then it's perfectly fine to use an INTEGER PK. OTOH, the extra 'cost' for a BIGINT is relatively low.
>
> I understand that a generator returns a BIGINT and that using BIGINT as the primary key is common now, but the range of INTEGER is sufficient for my purposes.
> CREATE TABLE CARS (It's valid to mix generator and sequence syntax, but it's probably better (and standards-compliant) to stick with sequence:
> CarID INTEGER NOT NULL,
> Data CHAR(35),
> CONSTRAINT PK_CARS PRIMARY KEY (CarID)
> );
>
> CREATE SEQUENCE CarID_CARS_GEN;
>
> SET GENERATOR CarID_CARS_GEN 1;
ALTER SEQUENCE CarID_CARS_GEN RESTART WITH 1
If you do use SET GENERATOR, don't forget 'TO':
SET GENERATOR CarID_CARS_GEN TO 1
BTW, if you set the generator/sequence to 1, the first issued ID will be 2.
Cheers,
Paul Vinkenoog