Subject | Re: [firebird-support] Stored Procedure for Insert |
---|---|
Author | Paul Vinkenoog |
Post date | 2004-02-17T13:39:10Z |
Hello Marc,
inserts it? If so: don't read the current max value from the table,
but use a generator and call it in a "before insert" trigger.
If the value must also be returned to the client, call the generator
from within an SP. However, it's safest to also keep the generator
call in the trigger (within a "if (New.MyValue is null) then..."
clause).
incremented, they have their new value for every user. No possibility
of duplicates unless you reset them explicitly. Hiatuses are possible
though!
Greetings,
Paul Vinkenoog
> One question: If I write a stored procedure which gets the maximumYou mean: every time it is called it increments the value by 1, and
> value of a field and adds 1 (or if it is null set it to 1), do a
> insert and give the new number back.
inserts it? If so: don't read the current max value from the table,
but use a generator and call it in a "before insert" trigger.
If the value must also be returned to the client, call the generator
from within an SP. However, it's safest to also keep the generator
call in the trigger (within a "if (New.MyValue is null) then..."
clause).
> Would that work if more users would use that stored procedure?Yes, because generators operate outside of transaction contexts. Once
incremented, they have their new value for every user. No possibility
of duplicates unless you reset them explicitly. Hiatuses are possible
though!
Greetings,
Paul Vinkenoog