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
 Instead of trigger ~ uses?

Author  Topic 

mteriyaki
Starting Member

3 Posts

Posted - 2010-04-05 : 15:22:16
Hello,
I'm wondering exactly how useful the instead of trigger can be. From what I have read in my books (I have no real world experience sorry...) I was getting the impression that an instead of trigger is only really preferable to an after trigger when performing operations on views on multiple tables, like inserting or updating to several tables at once.
Could you please give me some other examples as to when this might be a better option to an after trigger?
~Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-05 : 23:57:14
One other application can be where you need to enforce some business logic while performing DML operation on a table based on another db table. Like consider case where you've table1 in db1 and table2 in db2 and you want to enforce a foreign key between them. here you can use an instead of trigger to do this check before you perform the actual operation

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-04-06 : 02:36:26
I have used them where we had TEXT columns (which are not available in AFTER triggers INSERTED & DELETED tables). Now fixed by using VARCHAR(MAX) instead of TEXT in SQL2005+
Go to Top of Page
   

- Advertisement -