{"id":7578,"date":"2014-11-20T17:19:10","date_gmt":"2014-11-20T17:19:10","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/please-sp_help-my-system-stored-procedure\/"},"modified":"2017-08-10T12:49:26","modified_gmt":"2017-08-10T12:49:26","slug":"please-sp_help-my-system-stored-procedure","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/please-sp_help-my-system-stored-procedure\/","title":{"rendered":"Please sp_help My System Stored Procedure"},"content":{"rendered":"<p>SQL Server provides a large number of built-in stored procedures that can tell us all sorts of useful information about what&#8217;s going on in our SQL Server databases. For example, the <code>sp_help*<\/code> set of system stored procedures allow us to return information regarding the structure of our databases, or any of the objects within that are listed in <code>sys.syobjects<\/code>, including the system stored procedures themselves. This means that if you&#8217;re intrigued to know the current state of the code in any of SQL Server&#8217;s system stored procedures, there is an easy way to find out.<\/p>\n<p>A recent, popular article by <a href=\"https:\/\/www.simple-talk.com\/sql\/database-administration\/exploring-your-sql-server-databases-with-t-sql\/?utm_source=simpletalk&amp;utm_medium=weblink&amp;utm_content=tonyeditorial-20141124&amp;utm_campaign=editorial\">Scott Swanberg<\/a> shows a range of T-SQL scripts for exploring your SQL Server Databases, including investigating database object dependencies using the <code>sp_msdependencies<\/code> system stored procedure. If you&#8217;ve a few idle moments and need a laugh, use <code>sp_helptext<\/code> to take a look at its definition. The code comments are littered with casual, chatty asides, such as &#8220;&#8230;<i>do not raiserror as we may be calling this blindly and this is not a real error<\/i>&#8220;, and &#8220;<i>Just in case, remove self-refs from #t1<\/i>&#8221; or my personal favorite, &#8220;<i>Note that triggers are weird<\/i>&#8220;.<\/p>\n<p>It&#8217;s as if the developer expected his code to be peer reviewed and &#8216;fixed&#8217; but the team decided simply to chuck it out there, and then never touched it again. The code was clearly written on SQL Server 2000 or earlier, since it happily references system tables such as <code>sysobjects<\/code> (owned by <code>dbo<\/code>), instead of the catalog views, as well as various old Sybase throwbacks such as <code>sysreferences<\/code>.<\/p>\n<p>Now, admittedly, I&#8217;ve picked on an unsupported system stored procedure here and not many others will be in such a state of disrepair, but there&#8217;s no doubt that many more of them are long overdue a makeover.<\/p>\n<p>Since we have <code>sp_helptext<\/code> to allow us to poke around in the source code anyway, and since Microsoft clearly struggles to keep up with improving and updating all of them, why not open source their development? Microsoft could invite members of the community to improve the existing procedures, then vet the most promising, verify their output and incorporate them. That way we might end up with Adam Machanic&#8217;s <code>sp_whoisactive<\/code> as part of the engine instead of the rather less refined <code>sp_who2<\/code>, or Kimberley Tripp&#8217;s vastly superior version of <code>sp_helpindex<\/code>!<\/p>\n<p>What do you think? Feel free to nominate the system stored procedure that you think most needs fixing, and why.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL Server provides a large number of built-in stored procedures that can tell us all sorts of useful information about what&#8217;s going on in our SQL Server databases. For example, the sp_help* set of system stored procedures allow us to return information regarding the structure of our databases, or any of the objects within that&#8230;&hellip;<\/p>\n","protected":false},"author":200703,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,47125],"tags":[],"coauthors":[],"class_list":["post-7578","post","type-post","status-publish","format-standard","hentry","category-blogs","category-editorials"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/7578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/200703"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=7578"}],"version-history":[{"count":3,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/7578\/revisions"}],"predecessor-version":[{"id":42442,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/7578\/revisions\/42442"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=7578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=7578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=7578"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=7578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}