Instead Of Triggers

In this blog, you will learn about instead of triggers.

Instead of triggers are used to skip DML commands. They fire when you try to execute insert, update or delete statement but instead of executing these commands trigger actually works and trigger functionality executes.
  1. create table approved_emp ( eid int identity(1,1), ename varchar(30))  
  2. create table emp ( id int identity(1,1) , ename varchar(30), AddedBy varchar(30))  
  4. Create trigger instead_of on approved_emp  
  5. instead of insert  
  6. as  
  7. begin  
  8. declare @name varchar(30)  
  9. select @name=ename from inserted  
  10. insert into temp_audit values(@nameUSER )  
  11. end  
So, basically, trigger will work as, when we will try to add new record in approved_emp table, instead of inserting new records it will add ename into emp table. No data will reflect in approved_emp table as trigger is fired on the table every time while adding data into that table.
You can also create instead of triggers for update and delete as well.
Here is a complete tutorial: Triggers In SQL Server