SET IDENTITY_INSERT 和 DBCC CHECKIDENT

SET IDENTITY_INSERT (Transact-SQL)

Allows explicit values to be inserted into the identity column of a table.

 

Remarks

 At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, SQL Server returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for.

If the value inserted is larger than the current identity value for the table, SQL Server automatically uses the new inserted value as the current identity value.

The setting of SET IDENTITY_INSERT is set at execute or run time and not at parse time.  

 

DBCC CHECKIDENT (Transact-SQL)

Checks the current identity value for the specified table in SQL Server 2017 and, if it is needed, changes the identity value.

You can also use DBCC CHECKIDENT to manually set a new current identity value for the identity column.

可以使用这个功能进行reseed,也可以用来检查current identify value

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(338)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2016-10-17 Setting Margin Properties in code
2014-10-17 C#中dll附加配置文件
点击右上角即可分享
微信分享提示