您好,欢迎访问一九零五行业门户网

SqlServer 在事务中获得自增ID

感谢lee576的分享精神,代码如下: use tempdbgocreate table table1( id int, employee varchar(32))goinsert into table1 values(1, one)insert into table1 values(2, two)insert into table1 values(3, three)insert into table1 values(4, four)gocreate
感谢 lee576 的分享精神,代码如下:
use tempdbgocreate table table1( id int, employee varchar(32))goinsert into table1 values(1, 'one')insert into table1 values(2, 'two')insert into table1 values(3, 'three')insert into table1 values(4, 'four')gocreate table table2( id int identity(1,1), employee varchar(32))go--=================================-- 用output把id插入@mytablevar--=================================declare @mytablevar table( id int)insert into table2 (employee) output inserted.id into @mytablevarselect employee from table1--=================================-- 查询@mytablevar--=================================select * from @mytablevar--drop table table1,table2
其它类似信息

推荐信息