Let's say I have a column of varchar(40) with data already and i change the datatype of that column to integer. does the data change at all in the columns (ie, does the data 'corrupt') or does it not matter and a table of (1,2,3) will still be (1,2,3) regardless of the datatype?
views:
68answers:
3
+2
A:
It will be the same, subject to
- datatype conversion error (eg "foo" to int)
- truncation (eg "foobar" in char(4))
gbn
2010-01-25 20:27:39
+1
A:
If you attempt to change a column's datatype and the new type is incompatible with the old type, it will fail and nothing will change. You'll get an error like:
"Disallowed implicit conversion from data type <type> to data type <type2>".
womp
2010-01-25 20:29:36
A:
Your first problem when you do something like this is that not all the data may meet the criteria to make the change. Those records need to be found and fixed before changing a data type.
The safest way to do something like this is to:
Make a backup Find and fix any data that will not meet the criteria for the new datatype Create an additional column in the correct datatype Migrate the data Drop the orginal column Rename the new column to the old name
HLGEM
2010-01-25 21:23:05