Question

in orther to get a column similar to the mysql ENUM type, I wrote a sql query as follows

ALTER TABLE [DbName].[dbo].[MediaContent]
ADD MediaType nvarchar(50) 
check(MediaType in ('audio','video','song','other')) 

this worked as wished(for test): But now I want to delete this column without success. It seems like there no way to directly delete a column which has a constraint up on it. How can I solve this issue? I want to delete this column and create another one.

here is the error message I get while the deletion

 The object 'CK__MediaCont__Media__14270015' is dependent on column 'MediaType'.
  ALTER TABLE DROP COLUMN MediaType failed 
because one or more objects access this         
column. (Microsoft SQL Server, Error: 5074)

No correct solution

OTHER TIPS

The object referenced in the error message is the name of the constraint. You should be able to use the follow:

ALTER TABLE [DbName].[dbo].[MediaContent]
  DROP CONSTRAINT CK__MediaCont__Media__14270015

You need to first drop the check constraint mentioned in the error message since that's stopping you from dropping the column. Following that you may drop the column.

Drop the constrain first then drop the column ,it will work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top