Executing a command against all databases

Leave a comment (0) Go to comments

If you want to run the same command against all databases in an instance there is another undocumented stored procedure called ‘sp_MSforeachdeb’.  This can be used to check the space used by all databases in an instance.  This is especially helpful if you have a server with a ton of databases.  Here’s the syntax to check the space used for all db’s:

exec sp_MSforeachdb ‘exec ?..sp_spaceused’

EOF - Executing a command against all databases, SQL Server 2012 , 2008 R2 , 2008 , 2005 , 2000

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.