• Thanks for the article. I've used a number of these stored procedures before but a couple were new to me.

    One interesting point that you may or may not know about sp_MSforeachtable is that you can specify a where condition for it to limit the number of tables you operate against.

    For instance, if all of your audit tables ended with the word AUDIT you could truncate only that group by using the following command.

    --truncate all AUDIT tables

    exec sp_MSforeachtable @command1 = "truncate table ? ", @whereand = "and o.name like '%AUDIT' "

    It is important to specify the 'o' in 'o.name' as that is the underlying alias for the sys.objects table in the stored procedure.