Auto increment primary key in SQL Server Management Studio 2012

[Origin]: http://stackoverflow.com/questions/2867501/parse-json-in-tsql

Make sure that the Key column’s datatype is int and then setting identity manually, as image shows

enter image description here

Or just run this code

-- ID is the name of the  [to be] identity column
ALTER TABLE [yourTable] DROP COLUMN ID 
ALTER TABLE [yourTable] ADD ID INT IDENTITY(1,1)

the code will run, if ID is not the only column in the table

image reference fifo’s

shareimprove this answer

Just a bit of correction: The IDENTITY property could be applied to any numeric data types (so it could be tinyint, smallint, int, bigint, numeric, decimal), the only constraint is that it could not represent fractional number (so it can’t be float or real, neither numeric or decimal with non-zero scale) and ofc, the identity spec should be compatible with the selected data type. – Pred Feb 4 ’15 at 14:36

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s