Recent

Author Topic: [solved] Firebird 4 primary key generation - best practice  (Read 1339 times)

Nicole

  • Hero Member
  • *****
  • Posts: 1002
[solved] Firebird 4 primary key generation - best practice
« on: January 26, 2024, 02:52:08 pm »
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.
« Last Edit: February 03, 2024, 04:41:34 pm by Nicole »

rvk

  • Hero Member
  • *****
  • Posts: 6328
Re: Firebird 4 primary key generation - best practice
« Reply #1 on: January 26, 2024, 03:09:04 pm »
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.)

 

TinyPortal © 2005-2018