mysql delete from table 失敗

SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';mysql

TRUNCATE TABLE name
truncate語句,是清空表中的內容,包括自增主鍵的信息。truncate表後,表的主鍵就會從新從1開始。sql


check the manual that corresponds to your Mysql server version for the right syntax to yse near '-' at line 1命令行

[Msg] [Imp] Import table [bridge02]
[Err] [Imp] 1452 - Cannot add or update a child row: a foreign key constraint fails (`mydb`.`bridge02`, CONSTRAINT `TRSD_id2` FOREIGN KEY (`TRSD_id`) REFERENCES `trsd_adr_vli` (`TRSD_id`) ON DELETE NO ACTION ON UPDATE NO ACTION)
[Err] [Imp] INSERT INTO `bridge02` (`TRSD_pos`,`TRSD_id`,`TRCD_id`,`TRED_id`) VALUES ('20','11',NULL,'3'),('30','11',NULL,'21'),('40','11',NULL,'155'),('0','0',NULL,NULL)
[Msg] [Imp] Processed:5, Added:1, Updated:0, Deleted:0, Errors:4
[Msg] [Imp] Finished - Unsuccessfullyserver

mysql> delete from users_table where id =1;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails。。。問題解決
在MySQL在InnoDB中設置了foreign key關聯,形成沒法更新或刪除數據。能夠經過設置FOREIGN_KEY_CHECKS變量來避免這種狀況。
在命令行中輸入:
SET FOREIGN_KEY_CHECKS = 0;
刪除完成後設置
SET FOREIGN_KEY_CHECKS = 1;
這樣再select發現已經刪除成功!io

truncate table 表名;
delete from 表名;table

相關文章
相關標籤/搜索