One of my friends had a problem altering a column data type and asked me for a solution. The problem statement is given below.

He had a table test defined as below

And he needed to alter the data type of col1. He tried below query but it failed.

It’s very much clear from the error and the table schema above, that col2 depends on col1 and thus col1 can’t be changed.

So the answer here is very clear too, drop the computed column first and then change the data type of col1 and then recreate the computed column. The script for the same is give below

One thing to keep in mind is that the table won’t be accessible for DML queries when above statements are executed. So this complete activity should be planned carefully if the changes are to be done on production server.



Ahmad Osama

Like us on FaceBook Follow us on Twitter | Join the fastest growing SQL Server group on FaceBook

Follow me on TwitterFollow me on FaceBook