Thursday, December 22, 2011

sp_MSforeachdb – Undocumented Stored Procedure

The undocumented stored procedure “sp_MSforeachdb” is found in the “master” database. This is similar to sp_MSforeachtable. This stored procedure Sp_MSforeachdb gives a DBA the ability to cycle through every database in your catalog. This stored procedure will loop every database in your catalog for performing a command.

You can run a DBCC CHECKDB on all databases as below
   
EXEC sp_Msforeachdb "DBCC checkdb ('?')"

Similarly you can run other command also.

No comments:

Post a Comment