Add Foreign Key to Existing Table in MySQL


To add a foreign key constraint to an existing table in MySQL use the following query:

ALTER TABLE `myTable` ADD CONSTRAINT fk_myTable_otherTableID FOREIGN KEY (`otherTableID`) REFERENCES `otherTable`(`ID`);



Published:
Last modification:





This websites uses cookies and cookies of third parties for analytical purposes and advertisement. By using our website you agree to that. More information. You can change your choice any time.