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.
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.
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;