set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER TRIGGER [Autocph_Insert] ON [dbo].[Autocph] 
AFTER INSERT
AS
begin
waitfor delay '00:00:02' 
declare @cph nvarchar 
declare @icount int
select @cph=cphNum  from inserted
select @icount = count([igid]) from guest where cph = @cph
if @icount =0
   delete From Autocph where cphNum = @cph
end 

解决方案 »

  1.   

    AFTER INSERT
    For Insert 也没有用
      

  2.   

    if @icount =0
       delete From Autocph where cphNum = @cph
    end 
    ---改为if @icount is null or @icount = 0
       delete From Autocph where cphNum = @cph
    end 试试
      

  3.   


    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    ALTER TRIGGER [Autocph_Insert] ON [dbo].[Autocph] 
    AFTER INSERT
    AS
    begin
    waitfor delay '00:00:02' 
    delete a 
    From inserted i
    left join Autocph a on a.cphNum = i.cphNum  go
      

  4.   

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go
    ALTER TRIGGER [Autocph_Insert] ON [dbo].[Autocph] 
    AFTER INSERT
    AS
    begin
    waitfor delay '00:00:02' 
    if not exists(select 1 from guest g where exists(select 1 from inserted where g.cph = cphNum )
    delete a 
    From inserted i
    left join Autocph a on a.cphNum = i.cphNum  go
      

  5.   

    ALTER TRIGGER [Autocph_Insert] ON [dbo].[Autocph] 
    AFTER INSERT
    AS
    beginwaitfor delay '00:00:02' 
    if exists(select 1 from guest where cph in(select cphNum from inserted))
    delete Autocph where cphNum in(select cphNum from inserted)end 
      

  6.   

    ALTER TRIGGER [Autocph_Insert] ON [dbo].[Autocph] 
    AFTER INSERT
    AS
    beginwaitfor delay '00:00:02' 
    if exists(select 1 from guest where cph in(select cphNum from inserted))
    delete Autocph where cphNum in(select cphNum from inserted)end 
      

  7.   

    没有用啊 是不是SQL2005 的有改变和2000不一样啊
      

  8.   

    这一句不行啊
    if exists(select 1 from guest where cph in(select cphNum from inserted))