sp_msforeachdb

SQLServerCentral Article

sp_msforeachdb: Improving on an Undocumented Stored Procedure

  • Article

Have you ever wanted to run a query across every database on a server with the convenience of a stored procedure? If so, Microsoft provided a stored procedure to do so. It’s unreliable, outdated, and somewhat obfuscated, though. Let’s improve on it!

4.72 (43)

You rated this post out of 5. Change rating

2016-04-15 (first published: )

16,870 reads

Blogs

How to: Regain SysAdmin Access to a SQL Server Instance Without the SA Password

By

Hello, reader! Today, I’m going to walk you through a scenario that many DBAs...

Secure Your SQL Estate: Best Practices for Azure SQL Security

By

The Castle and the Keys Imagine your Azure SQL environment as a sprawling digital...

The Book of Redgate: Meetings

By

I think we might have forgotten this a bit, but on one of the...

Read the latest Blogs

Forums

Has Data-Driven Marketing Really Improved Loan Ads ROI?

By vikram1915

I’ve been wondering about this for a while so thought I’d put it out...

Trouble with SSIS Package Failing on Schedule but Running Manually

By jakestopher

Hi everyone, I’m fairly new to working with SSIS in SQL Server 2005, and...

Handling Engagement Rings & Wedding Band

By iBling Jewels

I’m working on a jewelry e-commerce project and need advice on designing an efficient...

Visit the forum

Question of the Day

The Duplicate Cursor

Can I run this code:

DECLARE ANewTable CURSOR FOR 
SELECT * FROM ANewTable

See possible answers