SQL Server Mgmt Studio 弄乱了我的数据库!
这实际上毁了我的一天。我有大量表,表之间有许多 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也遇到过同样的问题。正如 Will A 所说,管理工作室将执行以下步骤来更新表及其外键:
我可能前 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:
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.