Prometheus Prometheus - 1 year ago 188
SQL Question

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

In SQL Server Management Studio, when changing an existing field in design view from

DECIMAL (16,14)
DECIMAL (18,14)
it will not allow me to save without dropping the whole table and all its data.

Is it possible to change a field type once a database is populated with records?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download