当自增ID重复的时候在SQL ERRORLOG里不会有记录 2014-7-28
当自增ID重复的时候在SQL ERRORLOG里不会有记录 2014-7-28
USE [test] --DROP TABLE testindentity CREATE TABLE testindentity(id INT IDENTITY(1,1) PRIMARY KEY,name NVARCHAR(200)) INSERT INTO testindentity SELECT 'ni' UNION ALL SELECT 'lo' SELECT * FROM testindentity SET IDENTITY_INSERT testindentity ON INSERT INTO testindentity(id,name) SELECT 2,'opopo' SET IDENTITY_INSERT testindentity OFF DBCC CHECKIDENT(testindentity,RESEED,1) INSERT INTO testindentity(name) SELECT 'opopo'
结果,不会报错,但是自增值会从1000开始
id name
1 ni
2 lo
1002 opopo
再改一下种子值
DBCC CHECKIDENT(testindentity,RESEED,1) INSERT INTO testindentity(name) SELECT 'dfdfdf'
马上报错
消息 2627,级别 14,状态 1,第 1 行
违反了 PRIMARY KEY 约束“PK__testinde__3213E83F92F3B59B”。不能在对象“dbo.testindentity”中插入重复键。重复键值为 (2)。
EXEC sys.[sp_readerrorlog]