SQL中触发器的问题。。高手》》

来源:百度知道 编辑:UC知道 时间:2024/06/16 06:58:18
GO
ALTER trigger [dbo].[ia] on [dbo].[a]
after insert
as
if object_id('#t')is not null
drop table #t
go
select * into #t from a
go
declare @id int
select @id=x from inserted
if @id in(select x from #t)
raiserror('不能输入重复的值',16,1)
rollback tran

这样只能调试一次,第二次按F5就报错了,但是如果把所有的GO去掉的话就可以调试N次。。。请问这是为什么呢?

ALTER trigger 语句里,不能加 go

GO
ALTER trigger [dbo].[ia] on [dbo].[a]
after insert
as
begin

if object_id('#t')is not null
drop table #t

select * into #t from a

declare @id int
select @id=x from inserted
if @id in(select x from #t)
begin
raiserror('不能输入重复的值',16,1)
rollback tran
end

end