最近学习到了sql server2005新增的output用法,和大家分享一样
create table userinfo
(
userid int primary key
username varchar(50),
age int
)
create table loginfo
( userid int,
username varchar(50) ,
age int
)
go
--INSERT,inserted表以查询新行.
insert into userinfo (username,age)
output inserted.userid,inserted.username,inserted.age into loginfo
select username,10 from A371322rcms..userinfo
--DELETE,deleted表以查询旧行.
delete from userinfo
output deleted.userid ,deleted.username,deleted.age into loginfo(userid,username,age)
where username='ory'
--UPDATE,deleted表查询被更新行在更改前的属性,用inserted表标识被更新行在更改后的值.
declare @temptable table
(
userid int ,
oldusername varchar(50),
newusername varchar(50),
oldage int ,
newage int ,
comm varchar(20)
)
update userinfo
set username='output' ,age=22
output deleted.userid,deleted.username,deleted.age,inserted.username,inserted.age
into @temptable (userid,oldusername,oldage,newusername,newage,comm)
where userid=10
select * from @temptable
------解决方案--------------------原来是这样,感谢分享.
------解决方案--------------------谢谢分享
------解决方案--------------------output子句 谢谢分享!
------解决方案-------------------- 谢谢分享