SQL Server Management Studio - how to change a field type without dropping table

前端 未结 2 1508
执笔经年
执笔经年 2020-12-05 14:21

In SQL Server Management Studio, when changing an existing field in design view from DECIMAL (16,14) to DECIMAL (18,14) it will not allow me to sav

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 14:50

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

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

    and you should be fine.

    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.

    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:

    enter image description here

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

提交回复
热议问题