开发者

is there anyway to add a primary autonumber key to an already existing database table

开发者 https://www.devze.com 2022-12-25 19:55 出处:网络
i have inherited a database application from someone else and there are a few table开发者_运维知识库s that dont have any primary keys.I want to add a new column into an already existing table and have

i have inherited a database application from someone else and there are a few table开发者_运维知识库s that dont have any primary keys. I want to add a new column into an already existing table and have it autonumber (starting from 1). how would i go about doing this?


The SQL Server syntax is:

ALTER TABLE SomeTable ADD
    ID int NOT NULL IDENTITY(1, 1),
    CONSTRAINT PK_SomeTable PRIMARY KEY [NON]CLUSTERED (ID)
0

精彩评论

暂无评论...
验证码 换一张
取 消