Lifehack – Delete rows from table with foreign keys

First deactivate foreign key check. Next execute the delete statement. Don’t forget to activate foreign key check again.

Example:

SET FOREIGN_KEY_CHECKS=0;

DELETE FROM user
WHERE id IN (55,62);

SET FOREIGN_KEY_CHECKS=1;

Leave a Reply

Your email address will not be published. Required fields are marked *