I would like to know if it's possible in InnoDB in MySQL
to have a table
with foreign key that references another table in a different database
?
And if so, how this can be done ?
Since you want to keep all the business rules in the database your first thought is to use a Foreign Key constraint between the two databases, but when you try to create a foreign key between the two tables on the different databases you quickly learn that it is not possible.
InnoDB does not currently support foreign keys for tables with user-defined partitioning. This includes both parent and child tables.
No problem at all.
A table can have multiple foreign keys based on the requirement.
I do not see any limitation on https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html.
So just use otherdb.othertable and you will be good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With