Spider Man
Spider Man

Reputation: 425

How to delete a constraint from sql server management studio?

I added a new column in one of my tables using the sql statement below:

ALTER TABLE DigitalResources ADD Ratings REAL DEFAULT 0.0;

This added the desired column into the table with all values set to NULL.

I then wanted to delete this column using the command below:

ALTER TABLE DigitalResources DROP COLUMN Ratings;

However, this generates the following error:

Msg 5074, Level 16, State 1, Line 11 The object 'DF__DigitalRe__Ratin__73852659' is dependent on column 'Ratings'. Msg 4922, Level 16, State 9, Line 11 ALTER TABLE DROP COLUMN Ratings failed because one or more objects access this column.

I even tried out the following commands to delete this constraint but to no avail:

DROP CONSTRAINT 'DF__DigitalRe__Rating__73852659';
ALTER TABLE DigitalResources DROP 'DF__DigitalRe__Rating__73852659';

Thanks for help.

Upvotes: 2

Views: 2163

Answers (1)

Aditya
Aditya

Reputation: 1135

The query

ALTER TABLE DigitalResources DROP DF_DigitalRe_Rating_73852659;

is correct. Remove the quotes around the constraint. It can be treated as an object rather than a value.

Upvotes: 6

Related Questions