{"id":6,"date":"2008-02-25T12:59:16","date_gmt":"2008-02-25T18:59:16","guid":{"rendered":"https:\/\/jackdonnell.com\/?p=6"},"modified":"2015-12-28T16:44:54","modified_gmt":"2015-12-28T22:44:54","slug":"for-each","status":"publish","type":"post","link":"https:\/\/jackdonnell.com\/?p=6","title":{"rendered":"For Each &#8230; SQL System Stored Procedures"},"content":{"rendered":"<p>Sql server has some great built-in commands procs that can help you script server or database wide commands. sp_MSForEachTable and Sp_MSForEachDb<\/p>\n<p>When first looking at a database , I sometimes like to run the following:<br \/>\nexecute sp_MSforEachTable @command1=\u2018Print \u201d?\u201d; Select Count(*) as [? &#8211; (count)] from ?;Select Top 10 * from ? \u2018<\/p>\n<p>I used the sp_MSforeachDB just the other day to set all the non-system<br \/>\ndatabases on a test server to Simple Recovery mode.Just made a quick stored procedure that I passed the ? value and filter out the system databases ( Master, Model, Tempdb and MSDB).<\/p>\n<p>For More Information Checkout :<\/p>\n<p>November 30, 2004<br \/>\nSQL Server Undocumented Stored Procedures sp_MSforeachtable and sp_MSforeachdb<br \/>\nBy Gregory A. Larsen<br \/>\n<a href=\"http:\/\/www.databasejournal.com\/features\/mssql\/article.php\/3441031\" target=\"x\">http:\/\/www.databasejournal.com\/features\/mssql\/article.php\/3441031<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sql server has some great built-in commands procs that can help you script server or database wide commands. sp_MSForEachTable and Sp_MSForEachDb When first looking at a database , I sometimes like to run the following: execute sp_MSforEachTable @command1=\u2018Print \u201d?\u201d; Select &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/jackdonnell.com\/?p=6\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[266,22,351,5],"tags":[359,277,35,358,337,295,21,291,20],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-dba","category-sql-server","category-ssms","category-t-sql","tag-count","tag-database","tag-select","tag-sp_msforeachdb","tag-sp_msforeachtable","tag-sql-server","tag-store-procedure","tag-t-sql","tag-undocumented"],"_links":{"self":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6"}],"version-history":[{"count":1,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":525,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=\/wp\/v2\/posts\/6\/revisions\/525"}],"wp:attachment":[{"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jackdonnell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}