Articles → SQL SERVER → Triggers in SQL Server

Triggers in SQL Server









Create trigger <trigger_Name>
on
{table|View}
{for, after, instead of} {[insert],[update],[delete]}
As
<Sql_Statements>
	   




PK_IDsNamesAddress
1Name1Address1
2Name2Address2



Insert trigger




Create trigger trg_Insert_tbl_Test
on tbl_Test
For insert
as
Begin
	select * from inserted
End






Insert into tbl_Test values('name3','address3')








PK_IDsNamesAddress
3Name3Address3



Update trigger


Create trigger trg_Update_tbl_Test
on tbl_Test
For Update
as
Begin
select * from deleted
select * from inserted
End






Update tbl_Test  Set sAddress = 'TestAddress' where PK_ID =3






PK_IDsNamesAddress
3Name3Address3






PK_IDsNamesAddress
3Name3TestAddress







Posted By  -  Karan Gupta
 
Posted On  -  Monday, November 01, 2010

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250