insert into Users (username) output inserted.id values('aaa')

这个最靠谱。

 

网上说的大部是

select @@IDENTITY

这个非常不靠谱,其他库的操作也会导致这个值得变化

相对靠谱的是

select ident_current('table_name') 

这个限制了表,至少其他库的,其他表的不会影响。

 

 

output在update中也可以使用

update table set strs='dddd' output inserted.strs,deleted.strs where id=1 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-08-22
  • 2021-09-01
猜你喜欢
  • 2021-05-29
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2021-08-23
  • 2021-07-04
  • 2021-11-17
相关资源
相似解决方案