我有一张桌子和一个触发器如何使用OUTPUT获取身份列的值 - SQL服务器
create table test(id int not null identity(1,1) primary key, data int);
create trigger insteadTestInsert ON test INSTEAD OF INSERT
AS
BEGIN
INSERT INTO test(data) select data FROM inserted;
END;
启用触发,下面的查询
declare @tmp_table table(id int, int_val int);
insert into test(data)
output inserted.* into @tmp_table
values (10);
select * from @tmp_table;
返回ID = 0, int_val = 10。
如果我禁用(或丢弃)触发器,查询将返回适当的值id
。
如何让OUTPUT
在表格变量中插入正确的结果?
非常感谢。非常好。 – a1ex07 2011-05-20 02:30:02
@ a1ex07 - 准备好看到微妙的错误:) – 2011-05-20 02:37:13
@ a1ex07 - 不能保证插入临时表的数据与从“插入”返回的数据的顺序相同。 – 2011-05-20 02:42:25