Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL InnoDB foreign key between different databases

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 ?

like image 344
Alaa Avatar asked Oct 11 '10 09:10

Alaa


People also ask

Can you have a foreign key to a different database?

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.

Does InnoDB support foreign keys?

InnoDB does not currently support foreign keys for tables with user-defined partitioning. This includes both parent and child tables.

Can a foreign key reference multiple tables MySQL?

No problem at all.

Can a table contain multiple foreign key's?

A table can have multiple foreign keys based on the requirement.


1 Answers

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.

like image 71
BarsMonster Avatar answered Oct 04 '22 04:10

BarsMonster