改动一下
create TRIGGER TrgDel ON xxxx
FOR insert
AS
if exists (select * from sysobjects where name='spt_tb' and type='TR')
drop trigger spt_tb
end
create TRIGGER Trg_Zhb_Del ON spt_tb
FOR insert
AS
select * from xxxx
create TRIGGER TrgDel ON xxxx
FOR insert
AS
if exists (select * from sysobjects where name='spt_tb' and type='TR')
drop trigger spt_tb
end
create TRIGGER Trg_Zhb_Del ON spt_tb
FOR insert
AS
select * from xxxx
FOR insert
AS
if exists (select * from sysobjects where name='spt_tb' and type='TR')
drop trigger spt_tb
end
exec('
create TRIGGER Trg_Zhb_Del ON spt_tb
FOR insert
AS
select * from xxxx')
FOR insert
AS
begin
if exists (select * from sysobjects where name='Trg_Zhb_Del' and type='TR')
drop trigger Trg_Zhb_Del exec('create TRIGGER Trg_Zhb_Del ON A FOR insert AS update A set fa=5 ' )
end
FOR insert
AS
if exists (select * from sysobjects where name='spt_tb' and type='TR')
drop trigger spt_tb
exec('
create TRIGGER Trg_Zhb_Del ON spt_tb
FOR insert
AS
select * from xxxx')
FOR insert
AS
if exists (select * from sysobjects where name='spt_tb' and type='TR')
drop trigger spt_tb
exec('
create TRIGGER Trg_Zhb_Del ON spt_tb
FOR insert
AS
select * from xxxx')
create table xxxx(a int)
create table spt_tb(a int)
go--触发器
create TRIGGER TrgDel ON xxxx
FOR insert
AS
if exists (select * from sysobjects where name='spt_tb' and type='TR')
drop trigger spt_tb
exec('
create TRIGGER Trg_Zhb_Del ON spt_tb
FOR insert
AS
select * from xxxx')
go--插入数据测试
insert xxxx select 1--测试触发器中建的触器是否生效
insert spt_tb select 1
go--删除测试
drop table xxxx,spt_tb/*--测试结果a
-----------
1(所影响的行数为 1 行)--*/
EXEC (‘ create TRIGGER Trg_Zhb_Del ON MASTER..spt_tb
FOR insert
’)