create table userInfo(
uid int identity primary key,
uname varchar(20) not null
)
insert into userInfo output inserted.uid,inserted.uname values('I am jacklai')
你执行这条语句时候 让数据库表userInfo插入了一条数据 同时也返回了你刚刚插入的那条数据
如的项目中要返回刚刚插入的信息,这样就可以了!
SQL插入与返回新记录
本文介绍了一种在SQL中插入新记录的同时返回该记录的方法。通过使用`INSERT INTO...OUTPUT`语句,可以在向表中添加数据的同时获取刚插入的数据详情。
create table userInfo(
uid int identity primary key,
uname varchar(20) not null
)
insert into userInfo output inserted.uid,inserted.uname values('I am jacklai')
你执行这条语句时候 让数据库表userInfo插入了一条数据 同时也返回了你刚刚插入的那条数据
如的项目中要返回刚刚插入的信息,这样就可以了!

被折叠的 条评论
为什么被折叠?