Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Firing of delete trigger within instead of trigger

Author  Topic 

carolx
Starting Member

1 Post

Posted - 2011-05-14 : 20:40:13
Need some help on instead of triggers. I created an instead of trigger for insert/update on a table called transactions. I created a separate instead of delete trigger on the same table. If I execute insert or update on the table and then try to delete records from the table within the trigger the delete trigger is not fired but the records are deleted anyway. What is happening here.
Carol x

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-05-14 : 23:32:03
Please post real DDL. Learn to use ISO-11179 rules for the data element names, avoid needless dialect and use ISO-8601 temporal formats, codes and so forth. People cannot read your mind, so post your code and clear specs if you really want help.

In all the decades I have written SQL, I I have used only 5 triggers and three of them are not needed today. The fact that you used the term "record" is a sign that you are still writing file system procedural code and not declarative SQL.

Show us DDL and tell what you want to do, not how you want to do it.


--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-05-15 : 06:07:07
The behavior you are seeing is the expected behavior in SQL. Instead of triggers are not called recursively on the same table (not to be confused with nested triggers which invoke triggers on other tables).

After triggers can get invoked recursively and/or be nested depending on server and database settings.

This page has some basic information on triggers:http://msdn.microsoft.com/en-us/library/ms189799.aspx.

This page has information about nested triggers and recursive triggers: http://msdn.microsoft.com/en-us/library/ms190739.aspx
Go to Top of Page
   

- Advertisement -