if not Exists(select name from sysobjects where name='antiDel' and xtype='TR')
begin
CREATE TRIGGER antiDel ON [dbo].[tTmpAdd]
FOR DELETE 
AS 
insert into tATmpAdd select * from deleted
end服务器: 消息 156,级别 15,状态 1,行 3
在关键字 'TRIGGER' 附近有语法错误。
怎么会有错误呢?求解

解决方案 »

  1.   

    if not Exists(select name from sysobjects where name='antiDel' and xtype='TR')
    drop trigger  antiDel 
    go
    CREATE TRIGGER antiDel ON [dbo].[tTmpAdd]
    FOR DELETE  
    AS  
    insert into tATmpAdd select * from deleted
      

  2.   

    凑合用if not Exists(select name from sysobjects where name='antiDel' and xtype='TR')
    begin 
    exec('
    CREATE TRIGGER antiDel ON [dbo].[tTmpAdd]
    FOR DELETE  
    AS  
    insert into tATmpAdd select * from deleted
    ')
    end
      

  3.   

    xys_777的是OK的 可就是没搞明白 为什么if后面不能直接跟CREATE TRIGGER呢????