syntax check to execute DBCC UPDATEUSAGE for all user DBs

  • please confirm the following t-sql for correctness:

    EXEC sp_MSforeachdb 'USE ? IF "?" NOT IN ("master", "model", "msdb", "tempdb")
    DBCC UPDATEUSAGE(?) '
  • this is the type of sql you should confirm yourself in a dev box - if it is wrong you will see the errors.

    as for executing it blindly as you have above - as per the documentation https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-updateusage-transact-sql?view=sql-server-ver16

     

    We recommend the following:

    • Don't run DBCC UPDATEUSAGE routinely, as SQL Server maintains the metadata under most circumstances. DBCC UPDATEUSAGE should be run on an as-needed basis, for example, when you suspect incorrect values are being returned by sp_spaceused. DBCC UPDATEUSAGE can take some time to run on large tables or databases.
    • Consider running DBCC UPDATEUSAGE routinely (for example, weekly) only if the database undergoes frequent Data Definition Language (DDL) modifications, such as CREATE, ALTER, or DROP statements.

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

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