MS SQL 插入触发器在返回结果时会引起一些麻烦。有没有办法禁止发送任何结果?我用过'set nocount on',但这似乎没有多大作用......
create trigger tr_insert_raw_data
on raw_data
instead of insert
as
begin
set nocount on
declare @query varchar(max);
declare @rev int;
declare @id int;
declare @oldrev int;
declare @contextinfo VARBINARY(128)
select @contextinfo = context_info()
if @contextinfo = 0x00001
begin
insert into raw_data select * from inserted
return
end
select * into #query from inserted
set @id = (select count(distinct id) from raw_data);
set @id += 1;
insert into revisions (username, hostname, ts) values (SYSTEM_USER, HOST_NAME(), GETDATE())
set @rev = (select max(id) from revisions);
select @oldrev = revision_id from inserted;
if @oldrev is null set @oldrev=@rev-1;
select * into #inserted from inserted
update #inserted set revision_id = @rev, id = @id
select * from #inserted
insert into raw_data select * from #inserted
insert into edges (a, b) values (@oldrev, @rev)
end