How to force a drop table in SQL?

2

When 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 deletion of the table without having to delete the   relationships?

    
asked by anonymous 18.05.2017 / 13:58

2 answers

5

The code below disables foreign key checking, with it disabled, you can delete any table with relationship, note that the checks should be triggered later to 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 think it's what you're looking for.

    
18.05.2017 / 14:09
3

Do this:

SET foreign_key_checks = 0;
Drop table ...

SET foreign_key_checks = 0 will remove foreign key verification.

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

    
18.05.2017 / 14:09