@@IDENTITY IDENT_CURRENT SCOPE_IDENTITY区别

来源:互联网 发布:网络监控器软件下载 编辑:程序博客网 时间:2024/05/20 18:43

@@IDENTITY针对全局会话中的所有表中生成的最后一个标识值

SCOPE_IDENTITY  针对当前会话或者存储过程生产的最后一个标识值

IDENT_CURRENT 针对指定表生成的最后一个标识值


用法:

insert into news(title,categoryId,detail,createTime) value ('aaaa',1,'ddddd',getdate()) SELECT @@IDENTITY

insert into news(title,categoryId,detail,createTime) value ('aaaa',1,'ddddd',getdate()) SELECTSCOPE_IDENTITY

insert into news(title,categoryId,detail,createTime) value ('aaaa',1,'ddddd',getdate()) SELECTIDENT_CURRENT('NEWS')


原创粉丝点击