0
How can I do the composite key in the database?
I want to creat table that include just two culmon and both are foreign key.. which that two will be primary key.. how can I do that in mysql?
4 Respuestas
+ 1
Just set both of them as primary key. It automatically become a composite key. So if you have folkowing values
column1 | column2
1 | 6
1 | 3
There will be no error
+ 1
Thank u a lot
0
So if I use this query
ALTER TABLE Orders
ADD FOREIGN KEY (PersonID) REFERENCES Persons(PersonID);
For both column it will be correct yes?
0
👩🏻__🇴🇲 You have to set the ON UPDATE constraint to CASCADE
ALTER TABLE Orders
ADD FOREIGN KEY (PersonID) REFERENCES Persons(PersonID)
ON UPDATE CASCADE