Subject | Re: [firebird-support] Auto Increment? |
---|---|
Author | Martijn Tonies |
Post date | 2004-04-07T09:54:25Z |
Hi Jason,
than auto-inc columns. Besides, Firebird doesn't have a mechanism to
return the (new) value of a column, so if you need to establish a FK
relation, you cannot do that with an auto-inc column, nor with the trigger.
The usual way to do this, is to get the PK value for the parent (record)
to the client side, either by using a Stored Procedure, or a simple
SELECT GEN_ID(MyGenerator, 1) AS NEW_VALUE
FROM RDB$DATABASE
And use the value for both the parent PK and the FK column in any
child records.
Therefor, there is neither a need nor sensible use for auto-inc columns,
except for people who migrated ;-)
With regards,
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com
> I'm a MySQL user (I bet you all hear that a lot!) - I love MySQL, butWelcome! ;-)
> wishing it had just half of what Firebird has. btw: I just learned about /
> discovered Firebird and think it just rocks!
> However, I do like the auto increment functionality in MySQL for Primarya
> Key's - it seems to have this same functionality in Firebird I must create
> Trigger with the incremental code.Generators - the object you use in the trigger - are far more powerful
than auto-inc columns. Besides, Firebird doesn't have a mechanism to
return the (new) value of a column, so if you need to establish a FK
relation, you cannot do that with an auto-inc column, nor with the trigger.
The usual way to do this, is to get the PK value for the parent (record)
to the client side, either by using a Stored Procedure, or a simple
SELECT GEN_ID(MyGenerator, 1) AS NEW_VALUE
FROM RDB$DATABASE
And use the value for both the parent PK and the FK column in any
child records.
Therefor, there is neither a need nor sensible use for auto-inc columns,
except for people who migrated ;-)
> Is this the case, or am I just no seeing things correctly? If the Triggergreatly
> event is the way to get the auto-increments for my keys, then I would like
> to suggest for a near future release the concept of adding auto-increments
> directly by stating so in the Index, like MySQL.
>
> I can only imagine that this would also increase Insert performance
> also, as the Inserts won't have to respond to trigger events.I doubt you can measure the difference.
With regards,
Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com