sqlsevrer中output的用法

近日,看到代码中有output写法,不知其意,经过一番查找,终于找到了原因,它的作用是将修改影响的结果给输出出来。

比如update语句, 除了修改数据以外, 对于发生更新的列, update语句还可以返回这个列更新之前和更新之后的值. 在排除问题, 审核等其他情况下, 这样的功能很有用处.

带有output的insert语句.

@@identity只能返回当前会话最后生产的标识列.  如果一次性插入多条语句的话. 需要返回这些自动生产的标识列. 那么outpu就派上用场了.

declare @temp table(k int, v nvarchar(200))
insert into t1(datacol)
output inserted.keycol, inserted.datacol
into @temp
select lastname from TSQLFundamentals2008.hr.Employees where country='uk'
 
select * from @temp
原文地址:https://www.cnblogs.com/wcLT/p/4173881.html