我想在SQL Server2008中创建表,但我不知道如何创建复合主键。我如何才能做到这一点?
发布于 2010-10-13 17:39:25
create table my_table (
column_a integer not null,
column_b integer not null,
column_c varchar(50),
primary key (column_a, column_b)
);
发布于 2010-10-13 17:43:42
CREATE TABLE UserGroup
(
[User_Id] INT NOT NULL,
[Group_Id] INT NOT NULL
CONSTRAINT PK_UserGroup PRIMARY KEY NONCLUSTERED ([User_Id], [Group_Id])
)
发布于 2016-07-21 00:05:49
我知道我来晚了,但对于现有的桌子,请尝试:
ALTER table TABLE_NAME
ADD CONSTRAINT [name of your PK, e.g. PK_TableName] PRIMARY KEY CLUSTERED (column1, column2, etc.)
https://stackoverflow.com/questions/3922337
复制相似问题