开发者

script to add and remove auto-increment property from a column

开发者 https://www.devze.com 2023-01-18 04:43 出处:网络
For a sql script I\'m working on, I need to pr开发者_StackOverflowogrammatically remove the identity, identity seed, and identity increment for a column in an existing table, then add them back to the

For a sql script I'm working on, I need to pr开发者_StackOverflowogrammatically remove the identity, identity seed, and identity increment for a column in an existing table, then add them back to the table at the end of the script. Does anyone have a reference or an example on how to do this?


You should do this:

SET IDENTITY_INSERT <TableName> ON
-- Do the inserting in the table with name <TableName>
SET IDENTITY_INSERT <TableName> OFF

For more details look in the MSDN.


Yes, you just do this:

SET IDENTITY_INSERT [TABLE] ON

And then back on:

SET IDENTITY_INSERT [TABLE] OFF

This will allow you to enter manual data in the identity column.

http://msdn.microsoft.com/en-us/library/ms188059.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消