Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
teamjai
Yak Posting Veteran
52 Posts |
Posted - 2015-05-07 : 05:06:46
|
Hi,I am trying to change a column from a decimal(18,2) to a decimal(18,3). What is the SQL command to alter this table?SQL Command:alter table TableName alter column ColumnName decimal(18,3) [null]the above command is right ? |
|
Kristen
Test
22859 Posts |
Posted - 2015-05-07 : 05:33:17
|
I do this in SSMS (using the GUI) and then instead of "Save" I use the toolbar button that generates a Script.Some types of data type alteration require that a new table is created, data copied over, constraints / foreign keys / indexes all recreated and the original table dropped ... other data type conversions, and addition of new columns, can be done with a simple ALTER of that column |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2015-05-07 : 05:35:13
|
Yes. But you do not need a square brace around NULLMadhivananFailing to plan is Planning to fail |
|
|
teamjai
Yak Posting Veteran
52 Posts |
Posted - 2015-05-07 : 08:04:29
|
Hi,i got an below error messageSQL: alter table Houralter column Absolute decimal(18,3) nullMsg 5074, Level 16, State 1, Line 1The index 'Idx_Deleted_Absolutes' is dependent on column 'Absolute'.Msg 4922, Level 16, State 9, Line 1ALTER TABLE ALTER COLUMN Absolute failed because one or more objects access this column. |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2015-05-07 : 09:09:22
|
You'll have to disable the index first, then change the column, then rebuild the indexGerald Britton, MCSAToronto PASS Chapter |
|
|
Kristen
Test
22859 Posts |
Posted - 2015-05-07 : 14:30:57
|
That's why I do it in SSMS and let that build the appropriate Script for me |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
|
|
|
|
|
|