• Thank you all for your replies and comments. While my job title is DBA, I am more of a SQL Programmer and true Database Administration is a rare task for me, as I suspect it is for most people with that job title ! There simply aren't that many occasions where it is needed when one is managing a single production database.

    Thus, please accept my apologies for any misunderstandings I have over exactly what is logged and which contstraints etc are affected by specific SQL Statements.

    The purpose of the script is to easily and quickly remove most of the data, but not all of it, from a non-Production database that has been copied from Production.

    Originally, I had used something along the lines of the following on about 30 tables;

    DELETE FROM Sales

    WHERE Customer_Person_ID NOT IN (SELECT Person_ID FROM Person WITH (nolock))

    However, since the vast majority of the records are being deleted, this is very slow and, since it is logging every single record deleted (and there are millions of records in most of the tables), it was usually running out of log space unless I ran it in smaller chunks. It took about 24 hours in total to run and needed regular monitoring.

    Using the 'Calculated Truncate' approach, it is only selecting the few records that are being kept and so it runs against thousands of tables and takes an hour to run in a single chunk.

    Thus, it is faster, more reliable and MUCH more effective in shrinking the amount of data left in the database.

    My hope is that this approach will help others with a similar problem.

    However, if certain constraints will cause issues for some systems using the script as I have written it, please suggest improvements to the script so that it can dynamically remove those constraints and reimpose them once the data has been replaced in the original tables.