Knowledge Walls
John Peter
Pune, Maharashtra, India
How to ignore constraints while insert,update or delete records in Mysql?
14817 Views
How to ignore below error while delete or update. 
Error Code: 1451
Cannot delete or update a parent row: a foreign key constraint fails (`schema`.`refered_table_name`, CONSTRAINT `linked_key_ibfk_1` FOREIGN KEY (`reference_col`) REFERENCES `table_name` (`linked_column`))

How to ignore foreign key checks
-- this line tells to ignore foreign key checks
SET foreign_key_checks = 0;

-- delete all records
DELETE from user_info;
TRUNCATE user_info;

-- 1 value is not allow to remove or delete without constraints
SET foreign_key_checks = 1;
Previous Topics
Previous lessons of current book.
INFORMATION_SCHEMA Db of MySQL
INFORMATION_SCHEMA Db of MySQL
INFORMATION_SCHEMA Db of MySQL
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details