Trigger order guaranteed?
Posted in 2011
Topics: Stored Procedures & SPL, Security, Permissions & Auditing, Triggers, Constraints & Referential Integrity
I have a table with insert and delete triggers. The triggers call a stored procedure to insert audit data into another table. Now, I do 2000 inserts and 2000 deletes on the main table within one transaction. Should I expect the rows in the audit table to be inserted in the exact order of the inserts and deletes that fired the triggers?
Yes, however, you have no way to fetch those rows back in any particular order other than the order of the key columns of the table you are auditing. SQL does not guarantee the order in which rows are returned unless there is an ORDER BY clause. But what would you order on? If you have a timestamp on the audit rows, SQL rules require that all timestamps within a single transaction always return the time at the beginning of the transaction, so all 2000 rows inserted into the audit table will have the same timestamp. Art Art S. Kagel Advanced DataTools (www.advancedatatools.com) Blog: http://informix-myview.blogspot.com/ Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Advanced DataTools, the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Thu, Nov 17, 2011 at 5:11 PM, The Durster <seandurity@gmail.com> wrote: > I have a table with insert and delete triggers. The triggers call a > stored procedure to insert audit data into another table. Now, I do > 2000 inserts and 2000 deletes on the main table within one > transaction. Should I expect the rows in the audit table to be > inserted in the exact order of the inserts and deletes that fired the > triggers? > _______________________________________________ > Informix-list mailing list > Informix-list@iiug.org > http://www.iiug.org/mailman/listinfo/informix-list >