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

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

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

      <tfoot id='W3Rpv'></tfoot>
    1. <legend id='W3Rpv'><style id='W3Rpv'><dir id='W3Rpv'><q id='W3Rpv'></q></dir></style></legend>
      1. 无法截断表,因为它正被 FOREIGN KEY 约束引用?

        时间:2023-07-17

            <bdo id='PXwUr'></bdo><ul id='PXwUr'></ul>
            <legend id='PXwUr'><style id='PXwUr'><dir id='PXwUr'><q id='PXwUr'></q></dir></style></legend>
                  <tbody id='PXwUr'></tbody>

              1. <small id='PXwUr'></small><noframes id='PXwUr'>

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

                  本文介绍了无法截断表,因为它正被 FOREIGN KEY 约束引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用MSSQL2005,如果先截断子表(FK关系主键的表),是否可以截断带有外键约束的表?

                  Using MSSQL2005, can I truncate a table with a foreign key constraint if I first truncate the child table (the table with the primary key of the FK relationship)?

                  我知道我可以

                  • 使用不带where子句的DELETE,然后RESEED标识(或)
                  • 删除 FK,截断表,然后重新创建 FK.

                  我认为只要在父表之前截断子表,不执行上述任一选项就可以了,但是我收到此错误:

                  I thought that as long as I truncated the child table before the parent, I'd be okay without doing either of the options above, but I'm getting this error:

                  无法截断表TableName",因为它正被外键约束引用.

                  Cannot truncate table 'TableName' because it is being referenced by a FOREIGN KEY constraint.

                  推荐答案

                  正确;您不能截断具有 FK 约束的表.

                  Correct; you cannot truncate a table which has an FK constraint on it.

                  通常我的流程是:

                  1. 放弃约束
                  2. 截断桌子
                  3. 重新创建约束.

                  (当然,一切都在交易中.)

                  (All in a transaction, of course.)

                  当然,这仅适用于子项已经被截断的情况.否则我会走不同的路线,完全取决于我的数据是什么样的.(变量太多,无法进入.)

                  Of course, this only applies if the child has already been truncated. Otherwise I go a different route, dependent entirely on what my data looks like. (Too many variables to get into here.)

                  原始海报确定了为什么会这样;请参阅此答案 了解更多详情.

                  The original poster determined WHY this is the case; see this answer for more details.

                  这篇关于无法截断表,因为它正被 FOREIGN KEY 约束引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:SQL Server 中的连接组 下一篇:比较两个 SQL Server 数据库(架构和数据)的最佳工具是什么?

                  相关文章

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

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

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

                      <tfoot id='GFEUR'></tfoot>