<small id='guW5l'></small><noframes id='guW5l'>

    <legend id='guW5l'><style id='guW5l'><dir id='guW5l'><q id='guW5l'></q></dir></style></legend>

      <bdo id='guW5l'></bdo><ul id='guW5l'></ul>
      <tfoot id='guW5l'></tfoot>

      <i id='guW5l'><tr id='guW5l'><dt id='guW5l'><q id='guW5l'><span id='guW5l'><b id='guW5l'><form id='guW5l'><ins id='guW5l'></ins><ul id='guW5l'></ul><sub id='guW5l'></sub></form><legend id='guW5l'></legend><bdo id='guW5l'><pre id='guW5l'><center id='guW5l'></center></pre></bdo></b><th id='guW5l'></th></span></q></dt></tr></i><div id='guW5l'><tfoot id='guW5l'></tfoot><dl id='guW5l'><fieldset id='guW5l'></fieldset></dl></div>

      如何截断外键约束表?

      时间:2023-05-24

      <small id='iKu1Y'></small><noframes id='iKu1Y'>

      • <bdo id='iKu1Y'></bdo><ul id='iKu1Y'></ul>

            <tbody id='iKu1Y'></tbody>
          <tfoot id='iKu1Y'></tfoot>
            <i id='iKu1Y'><tr id='iKu1Y'><dt id='iKu1Y'><q id='iKu1Y'><span id='iKu1Y'><b id='iKu1Y'><form id='iKu1Y'><ins id='iKu1Y'></ins><ul id='iKu1Y'></ul><sub id='iKu1Y'></sub></form><legend id='iKu1Y'></legend><bdo id='iKu1Y'><pre id='iKu1Y'><center id='iKu1Y'></center></pre></bdo></b><th id='iKu1Y'></th></span></q></dt></tr></i><div id='iKu1Y'><tfoot id='iKu1Y'></tfoot><dl id='iKu1Y'><fieldset id='iKu1Y'></fieldset></dl></div>
              <legend id='iKu1Y'><style id='iKu1Y'><dir id='iKu1Y'><q id='iKu1Y'></q></dir></style></legend>

                本文介绍了如何截断外键约束表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                为什么 mygroup 上的 TRUNCATE 不起作用?即使我有 ON DELETE CASCADE SET 我得到:

                Why doesn't a TRUNCATE on mygroup work? Even though I have ON DELETE CASCADE SET I get:

                ERROR 1701 (42000): 无法截断外键约束中引用的表 (mytest.instance, CONSTRAINT instance_ibfk_1 FOREIGN KEY (GroupID) 参考 mytest.mygroup (ID))

                ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (mytest.instance, CONSTRAINT instance_ibfk_1 FOREIGN KEY (GroupID) REFERENCES mytest.mygroup (ID))

                drop database mytest;
                create database mytest;
                use mytest;
                
                CREATE TABLE mygroup (
                   ID    INT NOT NULL AUTO_INCREMENT PRIMARY KEY
                ) ENGINE=InnoDB;
                
                CREATE TABLE instance (
                   ID           INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
                   GroupID      INT NOT NULL,
                   DateTime     DATETIME DEFAULT NULL,
                
                   FOREIGN KEY  (GroupID) REFERENCES mygroup(ID) ON DELETE CASCADE,
                   UNIQUE(GroupID)
                ) ENGINE=InnoDB;
                

                推荐答案

                你不能TRUNCATE一个应用了 FK 约束的表(TRUNCATE删除).

                You cannot TRUNCATE a table that has FK constraints applied on it (TRUNCATE is not the same as DELETE).

                要解决此问题,请使用以下任一解决方案.两者都存在破坏数据完整性的风险.

                To work around this, use either of these solutions. Both present risks of damaging the data integrity.

                选项 1:

                1. 去除约束
                2. 执行TRUNCATE
                3. 手动删除现在引用无处
                4. 的行
                5. 创建约束

                选项 2:user447951 在他们的回答中提出

                SET FOREIGN_KEY_CHECKS = 0; 
                TRUNCATE table $table_name; 
                SET FOREIGN_KEY_CHECKS = 1;
                

                这篇关于如何截断外键约束表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Nodejs 表达并承诺不会做我期望的事情 下一篇:一次导出和导入所有 MySQL 数据库

                相关文章

                    <bdo id='VNDKa'></bdo><ul id='VNDKa'></ul>

                    <small id='VNDKa'></small><noframes id='VNDKa'>

                  1. <i id='VNDKa'><tr id='VNDKa'><dt id='VNDKa'><q id='VNDKa'><span id='VNDKa'><b id='VNDKa'><form id='VNDKa'><ins id='VNDKa'></ins><ul id='VNDKa'></ul><sub id='VNDKa'></sub></form><legend id='VNDKa'></legend><bdo id='VNDKa'><pre id='VNDKa'><center id='VNDKa'></center></pre></bdo></b><th id='VNDKa'></th></span></q></dt></tr></i><div id='VNDKa'><tfoot id='VNDKa'></tfoot><dl id='VNDKa'><fieldset id='VNDKa'></fieldset></dl></div>
                    <legend id='VNDKa'><style id='VNDKa'><dir id='VNDKa'><q id='VNDKa'></q></dir></style></legend><tfoot id='VNDKa'></tfoot>