How to force a drop table into SQL?

Asked

Viewed 1,770 times

2

While trying to give a drop table in a table that has relationships, the following error occurs: #1451 - Não pode apagar uma linha pai: uma restrição de chave estrangeira falhou

Is there any way to force table deletion without having to delete relationships?

  • Do you want to drop a table where there are several relationships? What is the reason for this?

  • Correct @Marconi know it will give errors in other places, but at the moment I need to drop this table.

2 answers

6


The code below disables checking for foreign keys, with it disabled, you can delete any linked table, note that the checks must be triggered later p/ maintain the integrity of the structures.

SET foreign_key_checks = 0;
-- Drop tables
drop table ...
SET foreign_key_checks = 1;

I found this alternative here, I believe that’s what you’re looking for.

3

Do so:

SET foreign_key_checks = 0;
Drop table ...

The SET foreign_key_checks = 0 will remove the foreign key check.

Remember to return the check to the original value with SET foreign_key_checks = 1;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.