Einzelnen Beitrag anzeigen

mse1

Registriert seit: 21. Nov 2007
115 Beiträge
 
#29

AW: SQL Automatisch zugeteilte Id ermitteln.

  Alt 14. Jul 2014, 12:35
This database also maintains a generator named EMP_NO_GEN and a Before Insert trigger named SET_EMP_NO on the EMPLOYEE table, to produce a value for this key whenever a new row is inserted. (Helen Borrie: The Firebird Book)

Wenn die Aktion (insert) nicht abgeschlossen (post) wird (was einem cancel entspricht), setzt der Trigger den einmal erhöhten Generatorwert wieder zurück (rollback):

Work performed by triggers will be rolled back if the transaction that prompted them is rolled back. (Helen Borrie: The Firebird Book)
Leider ist das für Sequenz-Werte nicht möglich:
Zitat:
As said, generators live outside of transaction control. This simply means you cannot safely “rollback” generators inside a transaction. There may be other transactions executing at the same time that change the value while your transaction runs. So once you have requested a generator value, consider it as “gone forever”.
http://www.firebirdsql.org/manual/ge...de-basics.html
Martin Schreiber
  Mit Zitat antworten Zitat