Home > Database > Mysql Tutorial > mssql sql 返回刚刚插入的ID

mssql sql 返回刚刚插入的ID

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:47:28
Original
1165 people have browsed it

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

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template