SQL Server 2012 How to change the data type of a column from bit to datefield?

350 views Asked by At

I have a table Person with a column called onvacation. This column is of data type bit since it's a boolean in the code. It has values null, 0 and 1.

I would like to change the data type of this column from bit to datetime so that all values that are 1, are converted to a new date (could be current date). and 0 and null values would both be just null.

I tried following w3bschool's tutorial and did a query:

ALTER TABLE Person ALTER COLUMN onvacation datetime

But that gives an error 'DF____Person__onvac__59062A42' is dependent on column 'onvacation'.

1

There are 1 answers

0
Dhaval On BEST ANSWER

you get this error because DF____Person__onvac__59062A42 sql object Depends on onvacation column.

You can Find Dependency of Person table by Right Click-->View Dependancy

remove that dependent object and try to alter column