Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Change Identity Property in T-SQL


Change Identity Property in T-SQL

Author
Message
Welsh Corgi
Welsh Corgi
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5158 Visits: 4863
Sean Pearce (6/29/2014)
Welsh Corgi (6/28/2014)
Sean Pearce (5/21/2014)
Welsh Corgi (5/20/2014)
You are right you can't set the Identity Property to true.

You can set the identity property to false by simply going into design mode and set the property to false.

I just wanted to know how to do it in T-SQL.

I guess I could find out how to do so by setting up a trace.

Thank you.

SSMS will create a new table, copy the data across, delete your original table and rename the new one.



I did not see the command to change the column to an identity in you example?

There isn't one.

CREATE TABLE NewTable (ID INT IDENTITY(1, 1));
GO
SET IDENTITY_INSERT NewTable ON;
GO
INSERT INTO NewTable (ID)
SELECT * FROM OldTable;
GO
SET IDENTITY_INSERT NewTable OFF;
GO
DROP TABLE OldTable;
GO
EXEC sp_rename 'NewTable', 'OldTable';
GO



And Vice Versa


ok, thank you:-)

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search