mssql sql 返回刚刚插入的ID
mssql sql 返回刚刚插入的id
set xact_abort on
begin tran
declare @id int
insert 表a values('小五')select @id= scope_identity()
insert 表b values(@id,'ll')
insert 表c values(@id,'ee')
commit
//
create trigger tri_表a
on 表a
for insert
as
begin
declare @id int
select @id= id from isnerted
insert 表b values(@id,'ll')
insert 表c values(@id,'ee')
end
//
create table dbo.tbtest(
id int identity(1,1) not null
,value varchar(50)
)
--下面语句重复执行几次,就很可以得到很明显效果了
declare @id int --获取新增id
insert into dbo.tbtest(value) values ('aaa')
set @id=scope_identity()
select @id
补充:数据库,Mssql