Created
September 9, 2015 18:29
-
-
Save Vaccano/3eb4cd6fef90446aaf3a to your computer and use it in GitHub Desktop.
Update Property on an Identity Column
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE pubs | |
GO | |
EXEC sp_configure 'allow update', '1' | |
RECONFIGURE WITH OVERRIDE | |
GO | |
DECLARE @col varchar(128), @table varchar(128) | |
-- for find identity column (if colstat =1 then identity is on) | |
SELECT @col=name | |
FROM syscolumns | |
WHERE id=OBJECT_ID('pubs..test') AND (colstat & 1 <> 0) | |
-- SELECT @col | |
IF (@col IS NOT null) BEGIN | |
UPDATE syscolumns | |
SET colstat = colstat ^ 1 | |
WHERE id = OBJECT_ID('pubs..test') and name = @col | |
END | |
EXEC sp_configure 'allow update', '0' | |
RECONFIGURE WITH OVERRIDE | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment