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?

25th Apr 2020, 11:49 AM
👩🏻__🇴🇲
👩🏻__🇴🇲 - avatar
4 Respostas
+ 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
25th Apr 2020, 12:05 PM
Ore
Ore - avatar
+ 1
Thank u a lot
25th Apr 2020, 4:48 PM
👩🏻__🇴🇲
👩🏻__🇴🇲 - avatar
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?
25th Apr 2020, 2:00 PM
👩🏻__🇴🇲
👩🏻__🇴🇲 - avatar
0
👩🏻__🇴🇲 You have to set the ON UPDATE constraint to CASCADE ALTER TABLE Orders ADD FOREIGN KEY (PersonID) REFERENCES Persons(PersonID) ON UPDATE CASCADE
25th Apr 2020, 4:37 PM
Ore
Ore - avatar