Monday, January 12, 2009

[SQL] Running code on most databases on a server

Everybody should already be using sp_MSforeachDB to do things in all databases.

This is a really cheap way of only doing it to some databases; just add the list in two single-quotes (since you're running it within sp_MSforeachDB)

sp_MSforeachdb 'if ''?'' NOT IN (''tempdb'')
use ?
exec sp_updatestats

No comments: