<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3865227304909182823</id><updated>2011-04-21T12:41:37.661-06:00</updated><title type='text'>The Cranky DBA</title><subtitle type='html'>Regular updates on MS SQL 2000 &amp; 2005, with large spoonfuls of sarcasm and crankiness. You've been warned!

-- Because knowing how to write a SELECT doesn't make you a DBA.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://crankydba.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3865227304909182823/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://crankydba.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Marcio</name><uri>http://www.blogger.com/profile/08647102462738962863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://4.bp.blogspot.com/_6ieM8k8jVPk/SYHP9_A5gJI/AAAAAAAADdg/ewymX0FTtsE/S220/marvel2.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3865227304909182823.post-7693556419875231979</id><published>2008-05-09T16:23:00.001-06:00</published><updated>2008-05-09T16:23:48.658-06:00</updated><title type='text'>How to track dependencies on column and table level</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This is a little something I wrote today.... I used to spend a lot of time tracking down dependencies between tables, and it's always difficult and tedious work. So after some time writing the code below, I found out that sql already provides a function that's almost as good as the one I have&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;exec sp_depends @objectname&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Almost as good, you say? That's because mine has the option of passing a column name to the search, so if all you're looking for is which procs refer to a specific column (because you're renaming the column), then you can narrow the search down to just the procs that specifically refer to the column. If all you want is a complete list of dependencies, however, then just leave the parameter empty&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Usage:&lt;/p&gt;  &lt;p&gt;exec sp_find_deps @tablename, @columnname&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Example:&lt;/p&gt;  &lt;p&gt;exec sp_find_deps @address, '' --Leave the parameter blank for a full list&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Code:&lt;/p&gt;  &lt;p&gt;create proc sp_find_deps &lt;/p&gt;  &lt;p&gt;@tablename varchar(100),   &lt;br /&gt;@columnName varchar(100) &lt;/p&gt;  &lt;p&gt;as &lt;/p&gt;  &lt;p&gt;declare @sql varchar(1000),   &lt;br /&gt;@databasename varchar(100) &lt;/p&gt;  &lt;p&gt;select @databasename =&amp;#160; db_name() &lt;/p&gt;  &lt;p&gt;set @sql = '   &lt;br /&gt;select distinct o.name parent_name, /*o.type, d.referenced_major_id, d.referenced_minor_id, c.name column_name,*/ d.is_selected, d.is_updated, d.is_select_all    &lt;br /&gt;from '+@databasename+'.sys.objects o    &lt;br /&gt;inner join '+@databasename+'.sys.sql_dependencies d on o.object_id = d.object_id    &lt;br /&gt;inner join '+@databasename+'.sys.columns c on c.column_id = d.referenced_minor_id --and c.object_id = o.object_id    &lt;br /&gt;where d.class in (0,1) and     &lt;br /&gt;d.referenced_major_id = (select object_id from prepassam.sys.objects where name = '''+@tablename+''' )    &lt;br /&gt;and c.name like ''%'+@columnName+'%''    &lt;br /&gt;order by o.name--, c.name    &lt;br /&gt;'    &lt;br /&gt;--print @sql    &lt;br /&gt;exec (@sql)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3865227304909182823-7693556419875231979?l=crankydba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crankydba.blogspot.com/feeds/7693556419875231979/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3865227304909182823&amp;postID=7693556419875231979' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3865227304909182823/posts/default/7693556419875231979'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3865227304909182823/posts/default/7693556419875231979'/><link rel='alternate' type='text/html' href='http://crankydba.blogspot.com/2008/05/how-to-track-dependencies-on-column-and.html' title='How to track dependencies on column and table level'/><author><name>Marcio</name><uri>http://www.blogger.com/profile/08647102462738962863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://4.bp.blogspot.com/_6ieM8k8jVPk/SYHP9_A5gJI/AAAAAAAADdg/ewymX0FTtsE/S220/marvel2.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3865227304909182823.post-7866576080552401405</id><published>2008-05-07T15:29:00.001-06:00</published><updated>2008-05-07T15:30:42.313-06:00</updated><title type='text'>Alternatives to an OR on a join</title><content type='html'>&lt;p&gt;Really liked a solution I saw recently for an alternative to using an OR clause in a join, as in&lt;/p&gt;  &lt;p&gt;select t1.blah, t2.blah from t1&lt;/p&gt;  &lt;p&gt;inner join t2 on t1.id = t2.id&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;or t1.id = t2.id2&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;instead, try it like this&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;select t1.blah, t2.blah from t1&lt;/p&gt;  &lt;p&gt;inner join t2 on t1.id = t2.id&lt;/p&gt;  &lt;p&gt;union&lt;/p&gt;  &lt;p&gt;select t1.blah, t2.blah from t1&lt;/p&gt;  &lt;p&gt;inner join t2 on t1.id = t2.id2&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Nice and elegant, I think. I'll have to explain it better later :-)&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3865227304909182823-7866576080552401405?l=crankydba.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://crankydba.blogspot.com/feeds/7866576080552401405/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3865227304909182823&amp;postID=7866576080552401405' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3865227304909182823/posts/default/7866576080552401405'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3865227304909182823/posts/default/7866576080552401405'/><link rel='alternate' type='text/html' href='http://crankydba.blogspot.com/2008/05/alternatives-to-or-on-join.html' title='Alternatives to an OR on a join'/><author><name>Marcio</name><uri>http://www.blogger.com/profile/08647102462738962863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='28' height='32' src='http://4.bp.blogspot.com/_6ieM8k8jVPk/SYHP9_A5gJI/AAAAAAAADdg/ewymX0FTtsE/S220/marvel2.jpg'/></author><thr:total>0</thr:total></entry></feed>
