Can you speed up readding constraints to a table
Hi All,
I have created a number of stored procedure for archiving inactive records to another database. To do this I do the following:-
1. Remove the foreign keys and indexes from the tables I am going to archive (as the tables are large this is the fastest way)
2. Search for the inactive records, move them to the Archive database then delete from the original tables
3. Re-add the foreign keys and indexes to the tables.
My question is as follows, some of the tables are pretty large (>2 million records) and when I go to re-add the foreign keys it is pretty slow to do this. I am using the following to re-add the constraints
ALTER TABLE [FK_TBL] WITH CHECK ADD CONSTRAINT [Constraint name] FOREIGN KEY([FK_Column]) REFERENCES [PK_TBL]([PK_Col])
Is there a quicker way to readd the constraints to the table or is this the only way? I need to make sure that all the remaining Active information is not orphaned that is why I am using with check