Disabling constraints

  • as an example if i want to drop the Publishers table in Pubs database it won't let me because of a Foreign Key constraint.

    I then run

    sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT ALL"

    attempting to disable all constraints so that I can go ahead and drop the table but it still won't let me.

    How can I programmatically disable these foreign key constraints to allow me to drop this table?

    Brian Lockwood

    President

    LockwoodTech Software

    Brian Lockwood
    President
    ApexSQL - SQL Developer Essentials

    http://www.apexsql.com/blog

    Stand up for an Independent SQL Community - be Informed

  • Cant disable, have to remove the foreign key relationship.

    Andy

    http://www.sqlservercentral.com/columnists/awarren/

  • Actually you can disable it for INSERT and UPDATE which is all. To be able to drop a table, even if disabled you have to drop the FK constraint first, then drop the table. If not then you would retain garbage in your database which would degrade it.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • quote:


    Actually you can disable it for INSERT and UPDATE which is all. To be able to drop a table, even if disabled you have to drop the FK constraint first, then drop the table. If not then you would retain garbage in your database which would degrade it.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)


    OK - thanks for the quick answers guys.

    Brian Lockwood

    President

    LockwoodTech Software

    Brian Lockwood
    President
    ApexSQL - SQL Developer Essentials

    http://www.apexsql.com/blog

    Stand up for an Independent SQL Community - be Informed

Viewing 4 posts - 1 through 4 (of 4 total)

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