触发器
--针对班级表的新增操作触发器 alter TRIGGER tg_Class ON Class after-- after(操作完成后才调用此触发器) | instead of(操作完成前调用此触发器) INSERT--UPDATE|INSERT|DELETE AS begin --触发器代码 insert into classbackup select * from inserted --select * into classbackup from inserted --select * from inserted--保存了引发新增触发器的新增数据,只能在触发器中访问 end
------------------------ After 新增触发器---------------------- alter trigger classback on t_class after insert as begin insert into T_Classback select * from inserted --将增加到触发器inserted表中的数据 备份到T_Classback表中 --select * from inserted--查询 触发器中的 inserted表中的数据 end
insert into T_class values('猪仔班','我懒我懒懒懒',30) insert into T_class values('星仔班','我了个去',20) insert into T_class values('山山班','到处是山',250)
truncate table T_Classback
--------------------------instead of 新增触发器--------------- alter trigger Class on T_class instead of insert as begin insert into T_Classback select * from inserted --select * from inserted end insert into T_class values('猪仔班','我懒我懒懒懒',30) insert into T_class values('星仔班','我了个去',20) insert into T_class values('山山班','到处是山',250)
alter trigger T_class1 on T_Class after insert as begin insert into T_Classback select * from inserted end
insert into T_Class values('猪仔班1','我懒我懒懒懒',310)
truncate table T_Classback
alter trigger tg_Class on T_Class after insert as begin insert into T_Classback select * from inserted end
insert into T_Class values('黑马班','o no my god', 57)
create trigger tg_Test_after_insert on test after insert as begin insert into '备份表' select *from inserted end
insert into test values('23',1000)