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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1969096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:52:13  来源:igfitidea点击:

Saving changes after table edit in SQL Server Management Studio

sqlsql-serverssmsdatabase-table

提问by rem

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:

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

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"?

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

回答by Pedro

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."

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

回答by Prasanna

Tools>Options

工具>选项

enter image description here

在此处输入图片说明

Uncheck above option

取消选中上面的选项

回答by Daniel Vassallo

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

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

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"

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

回答by Rolwin Crasta

GO to SSMS and try this

转到 SSMS 并尝试此操作

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/

这里有一个很好的解释: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-drop-and-re-created-you-have-either-made-changes-to-a-tab/

回答by HLGEM

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.

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

回答by marc_s

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.

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

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.

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

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!

乍一看,阻止此类更改似乎有悖常理——这对开发服务器来说肯定是件麻烦事。但是在生产服务器上,此选项及其防止此类更改的默认值成为潜在的救星!

回答by Chris

This is a risk to turning off this option. You can lose changes if you have change tracking turned on (your tables).

这是关闭此选项的风险。如果您打开了更改跟踪(您的表格),您可能会丢失更改。

Chris

克里斯

http://chrisbarba.wordpress.com/2009/04/15/sql-server-2008-cant-save-changes-to-tables/

http://chrisbarba.wordpress.com/2009/04/15/sql-server-2008-cant-save-changes-to-tables/