I'm not an every day SQL Server user but I use SQL Server regularly since 7.0 version until the 2005 version (not yet tried 2008 in a serious way) and from time to time I still find some nice hidden gems.
A few days ago I needed to created a cleanup script for an application and one of the tasks was to drop all tables that match a specific name pattern.
My first thought was to use a cursor to loop or a dynamic SQL statement ...
... but this time I decided to google for some other approach, and I found the amazing undocumented sp_MSforeachtable stored procedure from the master database.
It does the same but it requires considerably less code and improves the script readability.
Below is the syntax for calling the sp_MSforeachtable SP: More...