Hamid Reza
Hamid Reza

Reputation: 2973

How to make an existing column primary key and auto increment in sql?

I have a column named FinderLogId in a table named FinderLog.

I wanna make it primary key and auto increment. What I tried is the following:

ALTER TABLE [gheymatyab.com_db].[dbo].[FinderLog] 
   ALTER COLUMN [FinderLogId] int NOT NULL IDENTITY PRIMARY KEY

And what I see in the result is this:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'IDENTITY'.

Whats the problem?

Upvotes: 2

Views: 6355

Answers (1)

Scott Bercaw
Scott Bercaw

Reputation: 44

Your question looks very similar to this issue:

Adding an identity to an existing column

You'll either need to add a new primary key column, or else create a new table. The linked question goes into specifics.

Upvotes: 3

Related Questions