使用现有主键向表添加新列

时间:2014-07-24 11:50:49

标签: sql sql-server database

我正在尝试将新列(字段)添加到包含4列和额外id列的表中 但似乎有一个主要的限制因素? 有人可以帮忙吗?

CREATE TABLE [dbo].[table1]( [id] [int] IDENTITY(1,1) NOT NULL, [a] [int] NOT NULL, [b] 
[int] NOT NULL, [c] [int] NOT NULL, [d] [int] NOT NULL, [SCD_Date] [date] NOT NULL, [EndDate] 
[date] NULL, CONSTRAINT [PK_table1] PRIMARY KEY CLUSTERED

1 个答案:

答案 0 :(得分:0)

您需要在约束中添加主键。

CREATE TABLE [dbo].[table1]( 
[id] [int] IDENTITY(1,1) NOT NULL, 
[a] [int] NOT NULL,
[b] [int] NOT NULL,
[c] [int] NOT NULL,
[d] [int] NOT NULL,
[SCD_Date] [date] NOT NULL, 
[EndDate] 
[date] NULL,
CONSTRAINT [PK_table1] PRIMARY KEY CLUSTERED (id asc)
)