Skip to main content

Example on how to add FOREIGN KEY in MYSQL

FOREIGN KEY :

To allow naming of a FOREIGN KEY constraint, and for defining a FOREIGN KEY constraint on multiple columns, use the following SQL syntax:

 


ALTER TABLE `customer_address`  
   ADD CONSTRAINT `fk.customer_address.customer_id` 
      FOREIGN KEY (`customer_id`) REFERENCES `user` (`ID`) 
      ON UPDATE CASCADE 
      ON DELETE CASCADE;

Tags