How do I use a joint primary key as a foreign key? I have a table whose primary key is the Union primary key. this Union primary key is the foreign key in another table. what should I do? & Nbsp; for example: CREATETABLEIFNOTEXISTScustomers (& nbsp; firstnamevarchar (25) notnull, & nbsp; lastnamevarchar (25) how to use the joint primary key as a foreign key?
I have a table whose primary key is the Union primary key. this Union primary key is the foreign key in another table. what should I do?
For example:
Create table if not exists mers (
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 ()
)";
I want to use certificatetype and certificatenumber as the primary key of MERS and as the foreign key of cab_status. what should I do in red?
Because the names of people may be repeated, I like to use the document type and document number as the primary key.
------ Solution --------------------
Foreign key (certificatetype, certificatenumber) references customer (certificatetype, certificatenumber)