mysql delete from table 失敗

來源:互聯網
上載者:User

標籤:資料   ann   server   upd   sed   解決   can   包括   語句   

SET @[email protected]@SQL_MODE, SQL_MODE=‘NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION‘;

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


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 - Unsuccessfully

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發現已經刪除成功!

truncate table 表名;
delete from 表名;

mysql delete from table 失敗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.