The sp_MSforeachdb Stored Procedure December 22, 2016 The sp_MSforeachdb stored procedure helps you to do repetitive actions against all or some of the SQL Server instance databases. For example, this query: EXEC sp_MSforeachdb ‘USE [?]; EXEC sp_spaceused’