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
For Insert 也没有用
delete From Autocph where cphNum = @cph
end
---改为if @icount is null or @icount = 0
delete From Autocph where cphNum = @cph
end 试试
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
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
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
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
if exists(select 1 from guest where cph in(select cphNum from inserted))