The object 'DF.....' is dependent on column 'COL1' . But How?

  • Hi,

    I was playing with alter table. When i come across this suituation. I tried to figure it out but 🙁 . Well let me tell you what had i done.

    First i added a new column as :

    Alter Table Demo ADD col1 Int NOT NULL DEFAULT 1

    Then i added a constraint on this column as

    Alter Table Demo Add Constraint PK_demo PrimaryKey(col1,col2)

    Then i played with the data and decided to drop this constraint and bring the table to its original structure. So i proceeded with. I first thought of drooping the constraint which i had created which i did sucessfully as

    Alter Table Demo Drop Constraint PK_Demo

    After that i though of dropping the added column as

    Alter table Demo drop column col1

    but :doze: i got the error which is mention in the subject line.

  • the part of your script here:

    DEFAULT 1

    Alter Table Demo ADD col1 Int NOT NULL DEFAULT 1

    creates a default constraint ont eh column...so you can't drop teh column until you drop teh constraint on that column.

    sp-help demo will show you all the constraints, and then you can do an explicit drop like this:

    ALTER TABLE demo DROP CONSTRAINT DF__DEMO__2F126280

    to make it easier on yourself, you can add the default constraint with a specific name :

    Alter Table Demo ADD col1 Int NOT NULL

    ALTER TABLE Demo ADD CONSTRIANT DF_Demo_col1_default_value DEFAULT(1) FOR col1

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks Lowell........

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply