您的位置:首页 > 其它

如何获得刚刚插入数据的id

2014-07-26 23:02 337 查看
create table tblInsert
(
id int identity(1,1) primary key,
name nvarchar(10)
);

insert into tblInsert(name) values('张三');

select * from tblInsert;

insert into tblInsert(name) values('李四');
select @@IDENTITY;--方式一

-- 使用inserted临时表   方式二
insert into tblInsert(name) output inserted.id values('王五');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: