Textual description of firstImageUrl

Update Trigger for SQL Server



More Stuff

To Get Regular Updates

Like Our Facebook Page




Follow SANGITAB Blog With Bloglovin

Update Trigger is very useful if you keep your deleted record or which data is replaced withnew,, here I have one table called tblstudent 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 lets create table tblstudent

Update Trigger for Sql Server



create table tblstudent
(
studentid int primary key,
studentname varchar(max),
studentaddress varchar(max),
grade varchar(10),
isactive bit
)



Now I have to create one more table call tblstudent_log which store the updated data from tblstudent



create table tblstudent_log
(
studentid int,
studentname varchar(max),
studentaddress varchar(max),
grade varchar(10),
isactive bit,
updatedate
)



Now I am going to create the trigger



Create  trigger [dbo].[updateforstudent]
on tblstudent
for Update
as
begin
insert into tblstudent_log
(
select studentid,
studentname,
studentaddress,
grade,
isactive,
getdate()
from deleted
)
end


Here updateforstudent is a trigger name to execute whenever the update to tblstudent, because we are creating this trigger on tblstudentand for the update this statement tell to execute whenever update command pass to tblstudent

same thing I insert to tblstudent_log by selecting data from theselect studentid,

studentname,
studentaddress,
grade,
isactive,
getdate()
from deleted,

 deleted is a magic table which store the deleted data when we update the tblstudent


Follow

More From Our Site:

Textual description of firstImageUrl

No comments


About Us | HTML to XML Converter | Webmail Service | Nepali Unicode | Terms and Conditions | Privacy Policy | Contact Us | DMCA.com Protection Status