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

时间:2022-01-02 19:42:00

I am trying to add a new column(field) to a table with 4 columns and an extra id column.
But there seems to be a primary key restriction?
can someone help with this?

我正在尝试将新列(字段)添加到具有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 个解决方案

#1


0  

You need to add the Primary Key in the constraint.

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

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)
)

#1


0  

You need to add the Primary Key in the constraint.

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

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)
)