:::: MENU ::::

To perform a T-SQL task for all databases in SQL Server

  • Nov 11 / 2008
  • 0
DBCC Commands, dbDigger, System Stored Procedures

To perform a T-SQL task for all databases in SQL Server

Sometimes we need to perform a specific task on all databases. Like to run a specific SP on all database. In that case if you have a number of databases (likely in most of cases) then an automated method is required rather than to perform the task on each database one by one. In SQL Server T-SQL we have a system stored procedure (sp) sp_msforeachdb for this purpose. For example if you want to check database integrity of all databases, then you may run the following command.

 
EXEC sp_msforeachdb 'DBCC CHECKDB()'  
 GO  

The command DBCC CHECKDB() will be executed for all databases one by one.

Consult us to explore the Databases. Contact us