Home >Backend Development >PHP Tutorial > 如何使用联合主键做外键

如何使用联合主键做外键

WBOY
WBOYOriginal
2016-06-13 13:37:331653browse

怎么使用联合主键做外键?
我有一个表的主键是联合主键,这个联合主键是在另一个表中的外键,这个应该怎么做?
 例如:
CREATE TABLE IF NOT EXISTS customers(
  firstname varchar(25) not null,
  lastname varchar(25) not null,
  certificatetype varchar(25) not null,
  certificatenumber varchar(25) not null,
  gender varchar(6) not null,
constraint uc_customerID primary key (certificatetype,certificatenumber)
  );
CREATE TABLE IF NOT EXISTS cab_status(
  ID int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  roomname varchar(10) not null,
  certificatetype varchar(25) not null,
  certificatenumber varchar(25) not null,
foreign key() references customer()  
  )";
我想把certificatetype,certificatenumber作为customers的主键,作为cab_status的外键,红色的地方应该怎么做呢?
因为人名有可能重复,所以我就像把证件类型和证件号码作为主键。


------解决方案--------------------
foreign key(certificatetype ,certificatenumber ) references customer(certificatetype ,certificatenumber )

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn