Subject Re: [firebird-support] Synchonizing my generators
Author Helen Borrie
At 02:42 AM 23/04/2004 -0400, you wrote:

>Hello all,
>
>Sometimes we need to import data into our database and many times the key
>primary key field is supplied during the import. Is there a way for me to
>check each generator against the table that uses it, see what the highest
>value of the pk field is and increment the generator used for that field by
>one more?
>
>Or is it something I will to hard code for each table? I would be nice to
>create either a SP or a tight looping routine from the client do it.

And there I was, thinking we had cured you of your bad old desktop-database
habits! :-<

Just DON'T do it. The point of having a generator is to ensure the
integrity of your unique series. You don't then go and blow that by
introducing key values that originated somewhere else.

If you need to keep a memory of the old key, store an extra column for
it. Then, if you have to import details that have a foreign key
referencing that original key, you can pick it up on a Before Insert
trigger on the detail rows and update the key.

It's not just a question of knowing the "highest" value: what happens if
an introduced gen value turns up that the receiving database's generator
has already used...?

>Thank you for any suggestions,

Well, you did ask... :-))

/heLen