Drop and Recreate constraints

  • Hi,

    I have an ssis package that does truncate insert of all the tables in a database. Before i do this, i execute alter scripts to drop all the constraints and recreate them later.

    Is there any option other than Alter table drop constraint and Alter table add constraint scripts for each and every constraint?

  • There are some tables that you can’t truncate. One of the conditions is that the table is not referenced in a foreign key constraint. Unfortunately even if you disable the constraint, you still can’t truncate the table. The only option is to drop the foreign key constraint and recreate it after the truncate operation. Notice that you should only do it with foreign keys constraints and not with all constraints as you wrote in your message. Also if the tables are not big tables, you can run delete statement instead of truncate.

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

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

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