日期:2014-05-18 浏览次数:20584 次
-- 建测试表
create table stuinfos_base (id int, student_name varchar(10), student_year int)
-- 插入测试数据
insert into stuinfos_base
select 1,'Lix',2008 union all
select 2,'Sun',2009 union all
select 3,'Wei',2010 union all
select 4,'Jie',2011 union all
select 5,'Fan',2012
-- 建触发器
create trigger tr_stuinfosbase
on stuinfos_base
after update
as
begin
declare @year int
select @year=student_year from inserted
if @year=2012 -- 如果更新的是2012届的资料
begin
waitfor delay '00:00:10' -- 延时10秒
end
end
-- 更新2008届的资料
update stuinfos_base set student_name='Lix2' where student_year=2008
--> 执行很快
-- 更新2009届的资料
update stuinfos_base set student_name='Sun2' where student_year=2009
--> 执行很快
-- 更新2012届的资料,问题就来啦,因为进入了触发器,延时10秒.
update stuinfos_base set student_name='Fan2' where student_year=2012
--> 等10秒完成
-- 把2012届的数据独立出来
select * into stuinfos_base_2012 from stuinfos_base where student_year=2012
update stuinfos_base_2012 set student_name='Fan2' where student_year=2012
--> 执行很快,因为没有触发器.