• Andrew Watson-478275 (12/14/2010)


    If you don't mind using undocumented procedures, you can simplify it slightly by replacing all the loop stuff with:

    exec sp_msforeachtable @command1='insert #TempTable exec sp_spaceused ''?'''

    I also convert the "KB" values from sp_spaceused into numbers to allow for easier manipulation.

    Though sp_msforeachtable procedure is undocumented, but it is really useful if we want to apply the changes to all the tables in the database - by using this we can avoid Loop or cursors. We are using this to enable/disable all the constraints at one go.

    Thanks