How to create a trigger in SQL Server that fires only right before the transaction will be committed -
so ran issue goes follows:
- have table a.
- have table b has foreign key table a.
- have trigger on table ensures every item in table has @ least 1 row in table b pointing (through foreign key).
- trigger runs "insert" commands.
issue when insert table a, trigger raises error because table b doesn't have row foreign key new row in table yet. row on table b inserted end of transaction trigger not give me chance.
solution problem? there way tell trigger run after last command in transaction executed?
if need trigger fire on table a, not know if there corresponding rows in table b, should use "instead of" trigger. allow check table b before inserting rows table a. if there match in table b, proceed insert a, otherwise, add row b , a, or skip data doesnt match , return error application.
http://msdn.microsoft.com/en-us/library/ms175521(v=sql.105).aspx
Comments
Post a Comment