建了一个触发器
if exists (select 1
          from sysobjects
          where id = object_id('T_accountingsubject')
          and type = 'TR')
   drop trigger T_accountingsubject
go
if exists(select 1 from inserted) and not exists(select 1 from deleted)
begin
    update accountingsubjects set isend=0 where id in(select parentid from inserted)
end
go执行时提示
消息 208,级别 16,状态 1,第 3 行
对象名 'dbo.inserted' 无效。
这是怎么回事,难道2008没了inserted 和deleted表?

解决方案 »

  1.   


    if exists (select 1
      from sysobjects
      where id = object_id('T_accountingsubject')
      and type = 'TR')
      drop trigger T_accountingsubject
    go
    create trigger T_accountingsubject on 表名
    for/after/instead of insert
    as
    begin
    if exists(select 1 from inserted) and not exists(select 1 from deleted)
    begin
      update accountingsubjects set isend=0 where id in(select parentid from inserted)
    end
    end
    go
      

  2.   


    if exists (select 1
      from sysobjects
      where id = object_id('T_accountingsubject')
      and type = 'TR')
      drop trigger T_accountingsubject
    go
    create trigger T_accountingsubject on 表名
    for/after/instead of insert
    as
    if exists(select 1 from inserted) and not exists(select 1 from deleted)
    begin
      update accountingsubjects set isend=0 where id in(select parentid from inserted)
    end
    go更正如上
      

  3.   

    不能直接调用,逻辑表要放在触发器里或这样用SELECT 1 AS ID INTO #
    GOUPDATE # SET ID=2 OUTPUT DELETED.ID,INSERTED.ID
    /*1 2*/
    DROP TABLE #
      

  4.   

    谢谢,我忘记create trigger了。