SET FOREIGN_KEY_CHECKS = 0; TRUNCATE table1; SET FOREIGN_KEY_CHECKS = 1;
Here is what the above code is Doing:
1. First, we’re turning off foreign key checks. This is necessary because we’re going to truncate the table, which will delete all the rows. If we don’t turn off foreign key checks, we’ll get an error because the foreign key constraints will be violated.
2. Next, we’re truncating the table. This will delete all the rows in the table.
3. Finally, we’re turning foreign key checks back on.