MYSQL How to delete a row from a table with dependencies?

0

Is it possible to delete a row from a table with dependencies? I tried the command

ALTER TABLE MinhaTabela NOCHECK CONSTRAINT ALL

But the error appears

  

Error Code: 1064. You have an error in your SQL syntax; check the   manual that corresponds to your MySQL server version for the right   syntax to use near 'NOCHECK CONSTRAINT ALL

What's wrong?

    
asked by anonymous 13.06.2017 / 17:26

1 answer

3

The correct syntax for disabling and enabling FKs in MySQL is

To disable:

SET FOREIGN_KEY_CHECKS=0;

To enable:

SET FOREIGN_KEY_CHECKS=1;

The ideal is not to use this to delete the records, because your database will be inconsistent, but look for the records that are related to the record you want to delete and remove this link, after that you can delete your record without problems.

    
13.06.2017 / 17:48