SQL Server 表在導入數據時,有時須要將自增加列指定數值,來保證導入先後的數據徹底一致,如何實現?sql
SQL Server 提供了方法:spa
參考文檔:SET IDENTITY_INSERT | Miscosoft Docscode
語法:server
SET IDENTITY_INSERT [ database_name . [ schema_name] . ] table { ON | OFF }
用法:blog
-- SET IDENTITY_INSERT to ON. SET IDENTITY_INSERT dbo.Tool ON GO -- Try to insert an explicit ID value of 3. INSERT INTO dbo.Tool (ID, Name) VALUES (3, 'Garden shovel') GO -- SET IDENTITY_INSERT to OFF. SET IDENTITY_INSERT dbo.Tool OFF GO
注意事項:ci