How do I alter the precision of a decimal column in Microsoft SQL Server?

Sql Server

Sql Server Problem Overview


Is there a way to alter the precision of an existing decimal column in Microsoft SQL Server?

Sql Server Solutions


Solution 1 - Sql Server

ALTER TABLE Testing ALTER COLUMN TestDec decimal(16,1)

Just put decimal(precision, scale), replacing the precision and scale with your desired values.

I haven't done any testing with this with data in the table, but if you alter the precision, you would be subject to losing data if the new precision is lower.

Solution 2 - Sql Server

There may be a better way, but you can always copy the column into a new column, drop it and rename the new column back to the name of the first column.

to wit:

ALTER TABLE MyTable ADD NewColumnName DECIMAL(16, 2);
GO

UPDATE	MyTable
SET		NewColumnName = OldColumnName;
GO

ALTER TABLE CONTRACTS DROP COLUMN OldColumnName;
GO


EXEC sp_rename
    @objname = 'MyTable.NewColumnName',
    @newname = 'OldColumnName',
    @objtype = 'COLUMN'
GO

This was tested on SQL Server 2008 R2, but should work on SQL Server 2000+.

Solution 3 - Sql Server

ALTER TABLE (Your_Table_Name) MODIFY (Your_Column_Name) DATA_TYPE();

For you problem:

ALTER TABLE (Your_Table_Name) MODIFY (Your_Column_Name) DECIMAL(Precision, Scale); 

Solution 4 - Sql Server

In Oracle 10G and later following statement will work.

ALTER TABLE <TABLE_NAME> MODIFY <COLUMN_NAME> <DATA_TYPE>

If the current data type is NUMBER(5,2) and you want to change it to NUMBER(10,2), following is the statement

ALTER TABLE <TABLE_NAME> MODIFY <COLUMN_NAME> NUMBER(10,2)

Solution 5 - Sql Server

ALTER TABLE `tableName` CHANGE  `columnName` DECIMAL(16,1) NOT NULL;

I uses This for the alterration

Solution 6 - Sql Server

Go to enterprise manager, design table, click on your field.

Make a decimal column

In the properties at the bottom there is a precision property

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndrew JonesView Question on Stackoverflow
Solution 1 - Sql ServerVanSkalenView Answer on Stackoverflow
Solution 2 - Sql ServerbnielandView Answer on Stackoverflow
Solution 3 - Sql ServerH ShahView Answer on Stackoverflow
Solution 4 - Sql ServerNilucshan SivaView Answer on Stackoverflow
Solution 5 - Sql Server4302836View Answer on Stackoverflow
Solution 6 - Sql ServerChris JamesView Answer on Stackoverflow