Recent

6/recent/ticker-posts

Header Ads Widget

Update Trigger Sql Server

update Trigger is very useful if you keep your deleted record or which data is replaced with new , here i have one table called tbluser which have a user details, user may update their information time to time and i have to keep their deleted data securely, so lets discuss how it is possible

here is table with user details

now i have to create one more table call tbluser_log which store the updated data from tbluser



create table tbluser_log
(
userid int,
username varchar(max),
password varchar(max),
name varchar(max),
education varchar(10)
)

now i am going to create trigger 

Create  trigger [dbo].[updateforuser]on tbluserfor Update asbegininsert into tbluser_log (select * from deleted)end

here updateforuser is a trigger name to execute whenever update to tbluser, because we are creating this trigger on tbluser and for update this statement tell to execute whenever update command pass to tbluser
same thing i insert to tbluser_log by selecting data from the select * from deleted, deleted is a magic table which store the deleted data when we update the tbluser 

Post a Comment

0 Comments