简体   繁体   中英

How to delete with no check foreign key constraints

I have a table with some bad data in SQL. this table has a lot of relationship with other tables and other tables have a lot of data so when I want to delete bad data it's very slowly and take lots of time to do. I think the cause of this problem is foreign key constraints. the main problem is how can disable all of the foreign key constraints from one table.

You have to disable check constraint:

SET FOREIGN_KEY_CHECKS=0;

Make sure to turn it back after your commands:

SET FOREIGN_KEY_CHECKS=1;

Disable constraint for one table:

alter table
   table_name
DISABLE constraint
   constraint_name;

Here is an example:

select 'alter table '||table_name||' disable constraint '||constraint_name||';' from user_constraints;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM