我如何在T-sql中创建一个包含两个主键的表

时间:2015-05-15 04:38:08

标签: c# sql-server visual-studio tsql

此代码有什么问题?

CREATE TABLE pharmacy_night
(
    [Id_day] INT NOT NULL ,
    [Id_pharmacy] INT,
    constraint pk_pharmacy_night primary key (Id_day, Id_pharmacy),
    constraint fk_pharmacy_night_days foreign key (Id_day) references days(Id_day),
    constraint fk_pharmacy_night_pharmacy foreign key (Id_pharmacy) references pharmacy (Id_pharmacy)


)

1 个答案:

答案 0 :(得分:1)

尝试使用复合键

create table abc (
  ID int,
  number int,
  constraint PK_abc primary key (ID, number)
);

尝试使用主键

create table abc
(
ID int primary key,
number int
)