在 SQL Server Management Studio 中编辑表后保存更改

发布于 2024-08-15 17:22:38 字数 298 浏览 8 评论 0原文

如果我想保存之前保存在 SQL Server Management Studio 中的表中的任何更改(表中不存在数据),我会收到一条错误消息:

不允许保存更改。您所做的更改需要 以下表格将被删除并重新创建。你要么做了 对表的更改无法重新创建或启用该选项 防止保存需要重新创建表的更改。

什么可以防止表格被轻易编辑?或者,SQL Server Management Studio 是否需要重新创建表进行编辑?它是什么 - 这个“选项阻止保存更改”

If I want to save any changes in a table, previously saved in SQL Server Management Studio (no data in table present) I get an error message:

Saving changes is not permitted. The changes you have made require the
following tables to be dropped and re-created. You have either made
changes to a table that can't be re-created or enabled the option
Prevent saving changes that require the table to be re-created.

What can prevent the table to be easily edited? Or, is it the usual way for SQL Server Management Studio to require re-creating table for editing? What is it - this "option Prevent saving changes"?

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

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

发布评论

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

评论(7

ζ澈沫 2024-08-22 17:22:39

您应该停止以这种方式编辑数据,而不是取消选中该框(一个糟糕的解决方案)。如果必须更改数据,请使用脚本进行更改,以便您可以轻松地将其移植到生产环境中,并使其处于源代码控制之下。这也使得在生产被推送到开发人员之后更容易刷新测试更改,使开发人员能够处理更新的数据。

Rather than unchecking the box (a poor solution), you should STOP editing data that way. If data must be changed, then do it with a script, so that you can easily port it to production and so that it is under source control. This also makes it easier to refresh testing changes after production has been pushed down to dev to enable developers to be working against fresher data.

梦回梦里 2024-08-22 17:22:39

您可以在 SQL Server Management Studio 的表编辑器中非常轻松、直观地进行许多更改,但实际上需要 SSMS 在后台删除表并从头开始重新创建。即使像对列重新排序这样简单的事情也无法用标准 SQL DDL 语句来表达 - SSMS 所能做的就是删除并重新创建表。

此操作可能 a) 在大型表上非常耗时,或者 b) 甚至可能因各种原因(例如 FK 约束等)而失败。因此,SQL Server 2008 中的 SSMS 引入了其他答案已经确定的新选项。

乍一看,阻止此类更改似乎违反直觉 - 而且这对开发服务器来说肯定是一个麻烦。但在生产服务器上,此选项及其防止此类更改的默认值成为潜在的救星!

Many changes you can make very easily and visually in the table editor in SQL Server Management Studio actually require SSMS to drop the table in the background and re-create it from scratch. Even simple things like reordering the columns cannot be expressed in standard SQL DDL statement - all SSMS can do is drop and recreate the table.

This operation can be a) very time consuming on a large table, or b) might even fail for various reasons (like FK constraints and stuff). Therefore, SSMS in SQL Server 2008 introduced that new option the other answers have already identified.

It might seem counter-intuitive at first to prevent such changes - and it's certainly a nuisance on a dev server. But on a production server, this option and its default value of preventing such changes becomes a potential life-saver!

猫腻 2024-08-22 17:22:39

重现问题的步骤

  1. 在 SQL Server Management Studio 中,在表设计器工具中创建一个包含主键的表。
  2. 右键单击包含此表的数据库,然后单击属性
  3. 数据库属性对话框中,单击更改跟踪
  4. 更改跟踪项的值设置为True,然后单击确定
  5. 右键单击该表,然后单击属性
  6. 表属性对话框中,单击更改跟踪
  7. 更改跟踪项的值设置为True,然后单击确定
  8. 工具菜单上,单击选项
  9. 选项对话框中,单击设计器
  10. 单击以选中防止保存需要重新创建表的更改复选框,然后单击“确定”。
  11. 在表设计器工具中,更改现有列的允许空值设置。
  12. 尝试将更改保存到表中。

Steps to reproduce the problem

  1. In SQL Server Management Studio, create a table that contains a primary key in the Table Designer tool.
  2. Right-click the database that contains this table, and then click Properties.
  3. In the Database Properties dialog box, click Change Tracking.
  4. Set the value of the Change Tracking item to True, and then click OK.
  5. Right-click the table, and then click Properties.
  6. In the Table Properties dialog box, click Change Tracking.
  7. Set the value of the Change Tracking item to True, and then click OK.
  8. On the Tools menu, click Options.
  9. In the Options dialog box, click Designers.
  10. Click to select the Prevent saving changes that require table re-creation check box, and then click OK.
  11. In the Table Designer tool, change the Allow Nulls setting on an existing column.
  12. Try to save the change to the table.
挽手叙旧 2024-08-22 17:22:38

进入工具->选项->设计师->取消选中“防止保存需要重新创建表的更改”。瞧。

发生这种情况是因为有时需要删除并重新创建表才能更改某些内容。这可能需要一段时间,因为必须将所有数据复制到临时表,然后重新插入到新表中。由于 SQL Server 默认情况下不信任您,因此您需要说“好吧,我知道我在做什么,现在让我做我的工作。”

Go into Tools -> Options -> Designers-> Uncheck "Prevent saving changes that require table re-creation". Voila.

That happens because sometimes it is necessary to drop and recreate a table in order to change something. This can take a while, since all data must be copied to a temp table and then re-inserted in the new table. Since SQL Server by default doesn't trust you, you need to say "OK, I know what I'm doing, now let me do my work."

月下伊人醉 2024-08-22 17:22:38

工具|选项|设计师|表和数据库设计器

取消选中“防止保存需要重新创建表的更改”选项。

Tools | Options | Designers | Table and Database Designers

Uncheck the option "Prevent saving changes that require table re-creation".

冷弦 2024-08-22 17:22:38

要解决此问题,请使用 SQL 语句更改表的元数据结构。

当启用“防止保存需要重新创建表的更改”选项时,会出现此问题。

来源:尝试在 SQL Server 2008 中保存表时出现错误消息:“不允许保存更改”

To work around this problem, use SQL statements to make the changes to the metadata structure of a table.

This problem occurs when "Prevent saving changes that require table re-creation" option is enabled.

Source: Error message when you try to save a table in SQL Server 2008: "Saving changes is not permitted"

長街聽風 2024-08-22 17:22:38

转到 SSMS 并尝试此

菜单>>工具>>选项>>设计师>>取消选中“防止保存需要重新创建表的更改”。

对此有一个很好的解释:
http:// blog.sqlauthority.com/2009/05/18/sql-server-fix-management-studio-error- saving-changes-in-not-permission-the-changes-you-have-made-require-the-following-要删除并重新创建的表,您对选项卡进行了更改/

GO to SSMS and try this

Menu >> Tools >> Options >> Designers >> Uncheck “Prevent Saving changes that require table re-creation”.

Here is a very good explanation on this:
http://blog.sqlauthority.com/2009/05/18/sql-server-fix-management-studio-error-saving-changes-in-not-permitted-the-changes-you-have-made-require-the-following-tables-to-be-dropped-and-re-created-you-have-either-made-changes-to-a-tab/

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