TRigger :--
Trigger is like stored Procedure.It is used after Insert update delete or Before it.The difference between both is that trigger has relation with tables while stored procedure not.
Suppose we have two tables ‘test’ and ‘test22’. Now I wants that when a new record is inserting in the table test then after insert a trigger automatically and pick the last inserted record from test and insert the same into test22 table.. Here we go
Step I -- Create Trigger
Create trigger myfirst <-----(Trigger Name)
on test <-----------(Table name on which we are applying)
after insert
as
begin
declare @idss as int, @nameb as nvarchar(50),@cls as nvarchar(50)
select @idss=id,@nameb=name1,@cls=class from test where id= (select isnull(max(id),0) from test)
insert into test22 values(@idss,@nameb,@cls)
end
Step II -- Now when you insert a record in test then automatically the same record will insert in ‘test22’
I am trying to do best to update my blog.