How to use a federated primary key to do a foreign key

Source: Internet
Author: User
How do I use a federated primary key to do a foreign key?
I have a table where the primary key is the Federated primary Key, which is the foreign key in the other table, what should I do?
For example:
CREATE TABLE IF not EXISTS customers (
FirstName varchar (+) NOT NULL,
LastName varchar (+) NOT NULL,
Certificatetype varchar (+) NOT NULL,
Certificatenumber varchar (+) 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 (TEN) is not NULL,
Certificatetype varchar (+) NOT NULL,
Certificatenumber varchar (+) NOT NULL,
Foreign key () references customer ()
)";
I want to certificatetype,certificatenumber as the primary key of the customers, as the foreign key of the cab_status, what should the red place do?
Because it is possible to repeat a person's name, I like to use the document type and ID number as the primary key.


------Solution--------------------
Foreign key (Certificatetype, Certificatenumber) references customer (Certificatetype, Certificatenumber)
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.