1. 程式人生 > >觸發器的簡單應用示例

觸發器的簡單應用示例

CREATE TRIGGER [test1 ] ON [dbo].[tastid] 
FOR INSERT, UPDATE, DELETE 
AS
/* 申明變數*/
declare @sid int , @sname char(10)
begin 
/* 從插入臨時表inserted 中查詢剛插入的資料*/
select @sname = name from deleted
select @sid = id from deleted
if @sid is not null
begin 
  insert into testname values(@sid,@sname)
end
end