MySQL InnoDB Foreign Keys Across Databases
In MySQL InnoDB, you can create foreign keys between tables in different databases. This allows you to enforce referential integrity even when the tables reside in separate databases. To achieve this:
CREATE TABLE example_table ( id INT PRIMARY KEY, other_id INT, FOREIGN KEY (other_id) REFERENCES otherdb.othertable(id) );
In the example above, the example_table in your current database has a foreign key that references the other_id column in the othertable in the otherdb database. The otherdb.othertable must exist and its id column must be a primary key or unique index.
This allows you to maintain referential integrity even if you move the tables to different databases. The MySQL documentation does not specify any limitations on foreign key references across databases. Therefore, you can confidently use the otherdb.othertable syntax to establish cross-database foreign key relationships.
Das obige ist der detaillierte Inhalt vonKönnen MySQL InnoDB-Fremdschlüssel datenbankübergreifend sein?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!