SQL Server Mgmt Studio 弄乱了我的数据库!

发布于 2024-09-08 20:33:39 字数 361 浏览 3 评论 0原文

这实际上毁了我的一天。我有大量表,表之间有许多 FK 关系。其中一个表(我们称之为表 A)有一个计算列,该列是通过具有模式绑定的 UDF 计算的,并且也是全文索引的。

如果我编辑以任何方式(例如通过 FK)与具有全文索引计算列(表 A)的表相关的任何表(我们称之为表 B),并且保存它,则发生以下情况:

  • 保存对表(表 B)的更改
  • 我收到错误:“列 'abcd' 没有全文索引。”关于我什至没有编辑的表A,然后“用户从保存对话框中取消”
  • 与表B中所有表的所有FK关系都被删除

到底发生了什么???有人可以向我解释这是怎么发生的吗?

This has effectively ruined my day. I have a larger number of tables with many FK relationships in between. One of the tables (lets call it table A) has a computed column, which is computed via a UDF with schemabinding and is also fulltext indexed.

If I edit any table (lets call it table B) that in any way is related (e.g via FK) to the table with the fulltext indexed computed column (table A), and I save it, the following happens:

  • Changes to the table (table B) are saved
  • I get the error: "Column 'abcd' is no fulltext indexed." regarding table A which I didn't even edit, and then "User canceled out of save dialog"
  • All FK relationships to ALL TABLES from Table B are DELETED

What the hell is going on??? Can someone explain to me how this can happen?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福不弃 2024-09-15 20:33:39

我也遇到过同样的问题。正如 Will A 所说,管理工作室将执行以下步骤来更新表及其外键:

  1. 创建一个名为 temp_ 的新表
  2. 将旧表中的内容复制到新表中
  3. 删除所有约束、索引和外键
  4. 删除旧表
  5. 将新表重命名为be = 旧表
  6. 重新创建外键、索引和约束

我可能前 3 个的顺序错误,但你明白了。
就我而言,我丢失了整个表,而不仅仅是外键。就我个人而言,我不喜欢它的方式,因为必须在包含大量数据的表上重新创建索引可能非常耗时。如果是一个小更改,我通常会在 T-SQL 中自己完成。

在执行更改脚本之前检查它,确保它看起来合理。

@OMGPonies,如果表中有数据,为什么不能删除外键?当然可以。仅在包含数据的表上创建外键有限制,但前提是它打破了约束。然而,即使这种情况也可以通过在创建密钥时使用WITH NOCHECK 选项来避免。是的,我知道当您尝试更新损坏的结果集时它会损坏。

I've had the same kind of problem. As Will A said, the management studio will do the following steps to update a table and its foreign keys:

  1. Create a new table called temp_
  2. Copy contents from old table into new
  3. Drop all constraints, indexes and foreign keys
  4. Drop old table
  5. Rename new table to be = old table
  6. Recreate the foreign keys, indexes and constraints

I may have the first 3 in the wrong order but you get the idea.
In my case I've lost entire tables not just the foreign keys. Personally I don't like the way it does it as it can be VERY time consuming to have to recreate indexes on a table with lots of data in. If its a small change I usually do it myself in T-SQL.

Review the change script before it executes it, make sure it looks sensible.

@OMGPonies, why can't you drop a foreign key if there is data in the table? Of course you can. There are only restrictions on creating foreign keys on tables with data but that is only if it breaks the constraint. However even that can be avoided by using the WITH NOCHECK option when creating the key. Yes I know it'll break when you try to update a broken result set.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文