如何在 sql 中创建现有列主键并自动递增?

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

我在名为 FinderLog 的 table 中有一个名为 FinderLogId 的列。

我想让它成为主键和自增。我尝试的是以下内容:

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

我在结果中看到的是这样的:

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

有什么问题吗?

你的问题看起来与这个问题非常相似:

Adding an identity to an existing column

您需要添加一个新的主键列,或者创建一个新的 table。链接的问题进入细节。