Shhh! Secret Procedures!

I don’t have to tell you that the folks at Microsoft can be quite sneaky so, in case you don’t already know, there are a number of unofficially documented SQL stored procedures that can make your life not only better, but often cursor-free.

The one that is most helpful to me is entitled “sp_msforeachtable.” Using this stored procedure you can accomplish the same tasks on each table.

You can Google it for more information but a short and simple article can be found at DatabaseJournal.com:

“Beginning with version 6.5 of SQL Server, Microsoft provides a stored procedure called sp_MSreachfortable. Using the question mark as a place holder for all table names, the procedure will do the same as the above query in a single line. You can replace the above cursor with this :

sp_MSforeachtable @command1=”print ‘?’ dbcc checktable (‘?’)”

For more handy secrets, do a search on “undocument sql server stored procedures” or http://lmgtfy.com/?q=undocumented+sql+server+stored+procedures .