Is it safe to add foreign key constraint on two columns, while one is not unique (MySQL)? -


I have users table and other tables like services , < Code> Orders , etc ... which I would like to change in the hair tables of the user table. So far it is simple, I just add the foreign key restriction between user (id) and command (user_id) . But if I want to add a Boolean user (disabled) field, then it will be command (disabled) and services (disabled) fields in those rows Which references the respective row in the (user_id) key via user ?

If I make any reference, will this work? In the original table, using a 2 key in the original table, a primary and a non-unique?

You may have probably answered your question if you try to do it actually , You can not create an foreign key relationship on those columns which are not part of the primary key on the table (by name) on the foreign table.

Therefore, unless the disabled column user is not part of the primary key on the table, then, no, you are not able to create a foreign key relationship Other table will contain the disabled column.

Not all have been lost

When a user becomes inactive, the trigger to disable the order and services You can use.

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -