Forum > Database

[solved] Firebird 4 primary key generation - best practice


My old database works with triggers and generators to get a new primary key on inserting.

What do you think:
Shall I make those snippets DDL and just take them over in the year 2024?

Or is there a more actual practice to do it?

to add:
I have a very huge, historic code. In several cases I need the id of a newly inserted row delivered back into my code.
Every time I used this, it was really hard work, until it worked. And the first way to do it was about Firebird 2.5. or even earlier.
This shall continue to work.

Would you recommend not to touch this primary key things or to use anything else?
Those natural key things, which get a primary key for the first time in the year 2024: How would you recommend to deal with the generation of the new id in the year 2024 and in FB 4?

Thanks for hints.

It depends on the answer if you use gen_id somewhere in your code.
If not, you could go to the new key generation method.
You'll use returning to get the newly created id.

If you do use gen_id to get a new number before inserting master AND child then you better keep using trigger in combination with generator or sequence.

(Use of generator or sequence doesn't differ much and for new databases you can use the word sequence.)


[0] Message Index

Go to full version