Skip to content
Advertisement

MySQL alter two column for same foreign key

I have a table called user and the primary key is user_id.

I have another table called follows. This table is for storing which user follow which user(it is something like twitter follow function).

This is my follow table.

So, how can I alter this table to set both orginal_user_id and follow_user_id as a foreign key of user_id of user table…

If a user is deleted from the user table, I want to automatically delete rows in follows table either that user id appears on an orginal_user_id column or follow_user_id column.

Advertisement

Answer

You may use cascading delete constraints in your table:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement