MySQL InnoDB Foreign Key Constraints Across Databases
Can InnoDB within MySQL maintain a foreign key relationship between tables in separate databases?
Answer:
Yes, MySQL allows foreign key constraints to reference tables in different databases.
Implementation:
To establish a cross-database foreign key constraint:
For example, to create a foreign key constraint in the mytable table in the mydb database that references the othertable table in the otherdb database, use the following syntax:
ALTER TABLE mydb.mytable ADD FOREIGN KEY (col1) REFERENCES otherdb.othertable (col2);
The above is the detailed content of Can MySQL InnoDB Create Foreign Keys Between Tables in Different Databases?. For more information, please follow other related articles on the PHP Chinese website!