primary key(col1,col2)在SQL Server2000中为什么出错
想在一个表的两个属性上建主码,如:
create table 班干部
( 职位 char(8) not null primary key,
就职时间 smalldatetime not null,
离职时间 smalldatetime,
学号 char(8),
primary key(职位,就职时间)
)
提示错误:无法向表 '班干部' 中添加多个 PRIMARY KEY 约束
不是可以在一个属性组上创建主码吗?
问题点数:10、回复次数:3Top
1 楼zjcxc(邹建)回复于 2006-05-01 20:22:53 得分 0
一个表只能有一个主键. 而你的建表语句却想建立两个主键, 自然会报错啦Top
2 楼zjcxc(邹建)回复于 2006-05-01 20:23:35 得分 0
create table 班干部
( 职位 char(8) not null primary key,
就职时间 smalldatetime not null,
离职时间 smalldatetime,
学号 char(8),
unique(职位,就职时间) -- 如果是为了保障唯一性, 可以用唯一约束
)Top
3 楼xeqtr1982(Visual C# .NET)回复于 2006-05-01 23:25:08 得分 0
--这样?联合主建?
create table 班干部
( 职位 char(8) not null,
就职时间 smalldatetime not null,
离职时间 smalldatetime,
学号 char(8),
CONSTRAINT PK_1 PRIMARY KEY(职位,就职时间)
)Top




