Foreings Keys in MySQL with other Database

0

Is it possible to perform FK between fields in different databases?

I'm using the IDE MySQL Workbench and apparently the IDE does not allow it, but I would like to get out of doubt.

    
asked by Jonathan Ramírez 21.11.2016 в 16:48
source

1 answer

0

Yes, you can. You can do it by code directly ..

ALTER TABLE Tabla1 
ADD foreign key FK_tabla1(NombreColumnaTabla1)
REFERENCES db2.FromTabla2(NombreColumnaTabla2)

Where db2 is the other database.

Note: It is also possible to add that delete or update in cascade, putting the code:

on delete cascade
on update cascade;

It would stay like this:

ALTER TABLE Tabla1 
ADD foreign key FK_tabla1(NombreColumnaTabla1)
REFERENCES db2.FromTabla2(NombreColumnaTabla2)
on delete cascade
on update cascade;
    
answered by 21.11.2016 в 17:20