papa
2 years ago
19
4
Tips

How to delete a records which its ID not exists in another tables ?

Posted 2 years ago by papa

Hi,

I have a table of users

Users
id, first_name, last_name
1, Tom, Baar

and also I have 10 tables where all of them have a column which is the foreign_key of user_id

e.x.

Contracts
id, name, contract_manager(foreign key of users table)
1, Servers, 1

Logs
id, data, user_id(foreign key of users table)
1, data, 1

My question is how can I check if the user_id who I want to delete exists in one of the 10 tables it is associated so that I prevent the deleteion of the user ?

Please sign in or create an account to participate in this conversation.