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

前端 未结 2 1502
执笔经年
执笔经年 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:41

    Designer will still drop the table even if the option is unchecked in SSMS. It will just not prompt you next time it does it. To prove, launch the SQL profiler and alter a column using the SSMS designer and you will see a drop table command issued before the Alter table command is executed.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题