sp_MSforeachdb
sp_MSforeachdb is an undocumented system stored procedure that lets you iterate through all databases on an instance and execute a T-SQL statement. This can be a very handy tool for the DBA. For instance, let us create a script that lists all tables and their size on a server instance.