标签:ar sp for 数据 on bs as nbsp c
当执行插入命令时,两者都可以返回所插入数据的Id,不同的是scope_identity是当前作用域,而@@identity是可以跨作用域的
例如:
create table table1(
Id int identity(1,1) primary key,
Name nvarchar(32)
)
create table table2(
Id int identity(1,1) primary key,
Name nvarchar(32)
)
insert into table1 values(‘xiaowang‘)
insert into table1 values(‘xiaozhang‘)
insert into table2 values(‘xiaowang‘)
create trigger tr1
on table1 for insert
as
begin
insert table2 values(‘‘)
end
insert table1 values(‘xiaoli‘) select scope_identity select @@identity
查询结果是 3 ,2
标签:ar sp for 数据 on bs as nbsp c
原文地址:http://www.cnblogs.com/tomwangblog/p/4095584.html