近日,看到代码中有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

相关文章:

  • 2021-09-07
  • 2022-12-23
  • 2021-07-18
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-11-03
猜你喜欢
  • 2021-06-21
  • 2021-10-11
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案