且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server Management Studio - 如何在不删除表的情况下更改字段类型

更新时间:2023-02-03 08:55:42

只需使用 T-SQL 脚本而不是可视化设计器即可实现您的目标:

Just use T-SQL script instead of the visual designer to achieve your goal:

ALTER TABLE dbo.YourTableNameHere
ALTER COLUMN YourColumnNameHere DECIMAL(18, 14) 

你应该没事.

视觉设计师采取了格外小心的方法,即使用新结构创建表格,然后复制所有数据 - 可行,但很乏味.通常,只要您不截断列(使其更短),您绝对可以使用 T-SQL 语句就地"更改列的数据类型.

The visual designer takes the extra careful route of creating the table with the new structure and then copying over all the data - it works, but it's tedious. Normally, as long as you don't truncate a column (make it shorter), you can definitely change the column's datatype "in place" using a T-SQL statement.

此外:默认情况下,SSMS 设计器会格外小心,不允许任何需要删除和重新创建表周期的更改.您可以在 Tools > 中禁用这种额外的小心操作.选项然后在这个对话框中:

Also: by default the SSMS designer is extra careful and won't allow any changes that require a drop-and-recreate table cycle. You can disable this extra carefullness in Tools > Options and then in this dialog box:

如果取消选中该选项,您将能够在视觉设计器中进行破坏性"更改

If you uncheck that option, you will be able to do "destructive" changes in your visual designer