I have a database A and database B. In database A i set company_id as Primary key. In database B i have to set same company_id as a reference. Is it possible to set B.company_id as foreign key? If yes means how to set this B.company_id as foreign key?
Any relationship between/among tables are confined within a schema. You cannot define foreign key constrain between two unrelated tables in two different schema. If you have a real need o do it then you need to re-think about your database design.
Please refer to this nearly duplicate item. It is possible to have foreign keys between different schemas (sometimes called "databases") on the same MySQL database server. MySQL InnoDB foreign key between different databases
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