I have two databases: accounts and *company_x*.
In both db I have a table users.
accounts.users
user_id - pimary key, auto increment
first_name
last_name
time_zone
etc.
company_x.users
user_id - primary keu, auto increment
global_user_id
first_name
last_name
I want the following: when in accounts.users first_name or last_name changes to update company_x.users.
I know this way data is redundant (I store first_name and last_name in two places, but I decided not to make queries across databases).
How to set up a foreign key in this situation to automatically update the company_x.users table.
I can’t simply create a foreign key from company_x.users_first_name to accounts.users_last_name because last_names aren’t unique.
Thanks!
You can have a composite foreign key constraint:
Although, as @Furqan comments, there are probably better ways to achieve what you want.