Dropping Constraints

  • How i can drop my pk-fk relationship for all tables in one go.Plz suggest

  • DECLARE @sql varchar(8000)
    
    SELECT @sql = ISNULL(@sql,'') + 'DROP CONSTRAINT ' + Constraint_Schema + '.' + Constraint_Name + '
    ' FROM Information_Schema.Referential_Constraints
    EXEC(@sql)

    --Jonathan



    --Jonathan

  • to just disable your constraints (all of them) for all tables, you could use:

    execute sp_msforeachtable @command1='alter table ? nocheck constraint all'

    similarily use:

    execute sp_msforeachtable @command1='alter table ? check constraint all'

    to enable your constraints again.

    best regars,

    chris.

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

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