Showing posts with label empty table mysql with foreign key. Show all posts
Showing posts with label empty table mysql with foreign key. Show all posts

Wednesday, 19 August 2015

Truncate table mysql with foreign key


Truncate table mysql with foreign key

You cannot truncate/empty the table which has foreign key constraints applied on it

Use the below query to empty the table with foreign key but at your own risk.

Note : Please take backup of database first.

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE tablename1;
TRUNCATE tablename2;
SET FOREIGN_KEY_CHECKS = 1;