<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>MaasSql</title>
        <link>http://weblogs.sqlteam.com/jeffm/Default.aspx</link>
        <description>My momma always said share.</description>
        <language>en-US</language>
        <copyright>Jeff Maass</copyright>
        <generator>Subtext Version 2.5.1.0</generator>
        <image>
            <title>MaasSql</title>
            <url>http://weblogs.sqlteam.com/images/RSS2Image.gif</url>
            <link>http://weblogs.sqlteam.com/jeffm/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>CTE, Invalid Object, Swallowed Error - Is this a bug in MS Sql Server?  You decide.</title>
            <link>http://weblogs.sqlteam.com/jeffm/archive/2010/06/26/CTE-Invalid-Object-Swallowed-Error---Is-this-a-bug.aspx</link>
            <description>I didn't discover this, a &lt;a target="_blank" href="http://stackoverflow.com/users/376206/alban-fonrouge"&gt;person&lt;/a&gt; on StackOverflow did.  Just read the question and did some thinking.  If you are interested, then please read the &lt;a target="_blank" href="http://stackoverflow.com/questions/3119403/roles-of-parentheses-in-sql-server-select-queries"&gt;question&lt;/a&gt; and potentially comment @ StackOverflow.&lt;br /&gt;
&lt;br /&gt;
I've never submitted anything to &lt;a target="_blank" href="https://connect.microsoft.com/SQLServer"&gt;Microsoft Connect&lt;/a&gt;.  Do you think that this qualifies?  It would certainly seem if not a bug, then a severe annoyance if it ever happened in my code.&lt;img src="http://weblogs.sqlteam.com/jeffm/aggbug/61158.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Maass</dc:creator>
            <guid>http://weblogs.sqlteam.com/jeffm/archive/2010/06/26/CTE-Invalid-Object-Swallowed-Error---Is-this-a-bug.aspx</guid>
            <pubDate>Sat, 26 Jun 2010 15:42:45 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/jeffm/archive/2010/06/26/CTE-Invalid-Object-Swallowed-Error---Is-this-a-bug.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/jeffm/comments/commentRss/61158.aspx</wfw:commentRss>
        </item>
        <item>
            <title>PASS 2008 inexpensive room</title>
            <link>http://weblogs.sqlteam.com/jeffm/archive/2008/09/21/PASS-2008-inexpensive-room.aspx</link>
            <description>FYI, if you are attending 2008 Pass, and are on your own dime or saving your employer money, it may be possible to get rooms at the La Quinta right next to the convention center right at $100.&lt;br /&gt;
&lt;br /&gt;
La Quinta Inn and Suites Seattle Downtown &lt;br /&gt;
2224 8th Avenue&lt;br /&gt;
SEATTLE, WA 98121 US&lt;br /&gt;
&lt;br /&gt;
If you don't know about the PASS Community summit, you should.  Visit &lt;a href="javascript:void(0);/*1222035293465*/"&gt;http://summit2008.sqlpass.org/&lt;/a&gt; for details.&lt;img src="http://weblogs.sqlteam.com/jeffm/aggbug/60713.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Maass</dc:creator>
            <guid>http://weblogs.sqlteam.com/jeffm/archive/2008/09/21/PASS-2008-inexpensive-room.aspx</guid>
            <pubDate>Sun, 21 Sep 2008 22:17:44 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/jeffm/archive/2008/09/21/PASS-2008-inexpensive-room.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/jeffm/comments/commentRss/60713.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Milliseconds to Detail</title>
            <link>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/Milliseconds-to-Detail.aspx</link>
            <description>I use this function for testing. It takes in milliseconds and spits out the whole number value in various other rulers (seconds, minutes, etc).&lt;br /&gt;

&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;USE&lt;/span&gt; MaasSql

&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;USE&lt;/span&gt; [MaasSql]
&lt;span class="kwrd"&gt;GO&lt;/span&gt;
/****** &lt;span class="kwrd"&gt;Object&lt;/span&gt;:  UserDefinedFunction [cCode].[DateTime_GetUtcOffset]    Script &lt;span class="kwrd"&gt;Date&lt;/span&gt;: 02/25/2008 07:01:06 ******/
&lt;span class="kwrd"&gt;IF&lt;/span&gt;  &lt;span class="kwrd"&gt;EXISTS&lt;/span&gt; (&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; * &lt;span class="kwrd"&gt;FROM&lt;/span&gt; sys.objects &lt;span class="kwrd"&gt;WHERE&lt;/span&gt; object_id = OBJECT_ID(N&lt;span class="str"&gt;'[cCode].[MilliSeconds_ToDetail]'&lt;/span&gt;) &lt;span class="kwrd"&gt;AND&lt;/span&gt; type &lt;span class="kwrd"&gt;in&lt;/span&gt; (N&lt;span class="str"&gt;'FN'&lt;/span&gt;, N&lt;span class="str"&gt;'IF'&lt;/span&gt;, N&lt;span class="str"&gt;'TF'&lt;/span&gt;, N&lt;span class="str"&gt;'FS'&lt;/span&gt;, N&lt;span class="str"&gt;'FT'&lt;/span&gt;))
    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
        &lt;span class="kwrd"&gt;DROP&lt;/span&gt; &lt;span class="kwrd"&gt;FUNCTION&lt;/span&gt; cCode.MilliSeconds_ToDetail
    &lt;span class="kwrd"&gt;END&lt;/span&gt;

&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;FUNCTION&lt;/span&gt; cCode.MilliSeconds_ToDetail ( @Milliseconds BIGINT )
&lt;span class="kwrd"&gt;RETURNS&lt;/span&gt; @Results &lt;span class="kwrd"&gt;TABLE&lt;/span&gt;
    (
      ID &lt;span class="kwrd"&gt;INTEGER&lt;/span&gt; &lt;span class="kwrd"&gt;IDENTITY&lt;/span&gt;(1 , 1)
                 &lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt;
    , milliseconds BIGINT
    , Seconds &lt;span class="kwrd"&gt;REAL&lt;/span&gt;
    , Minutes &lt;span class="kwrd"&gt;REAL&lt;/span&gt;
    , Hours &lt;span class="kwrd"&gt;REAL&lt;/span&gt;
    , Days &lt;span class="kwrd"&gt;REAL&lt;/span&gt;
    , Weeks &lt;span class="kwrd"&gt;REAL&lt;/span&gt;
    )
&lt;span class="kwrd"&gt;AS&lt;/span&gt; 
&lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;

    &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @MilliSecondsREAL &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;REAL&lt;/span&gt; ;

    &lt;span class="kwrd"&gt;SET&lt;/span&gt; @MilliSecondsREAL = @Milliseconds ;

    &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @SecondsDivisor &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;REAL&lt;/span&gt; ;

    &lt;span class="kwrd"&gt;SET&lt;/span&gt; @SecondsDivisor = 1000 ;

    &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @MinutesDivisor &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;REAL&lt;/span&gt; ;

    &lt;span class="kwrd"&gt;SET&lt;/span&gt; @MinutesDivisor = @SecondsDivisor * 60 ;

    &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @HoursDivisor &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;REAL&lt;/span&gt; ;

    &lt;span class="kwrd"&gt;SET&lt;/span&gt; @HoursDivisor = @MinutesDivisor * 60 ;

    &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @DaysDivisor &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;REAL&lt;/span&gt; ;

    &lt;span class="kwrd"&gt;SET&lt;/span&gt; @DaysDivisor = @HoursDivisor * 24 ;

    &lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @WeeksDivisor &lt;span class="kwrd"&gt;AS&lt;/span&gt; &lt;span class="kwrd"&gt;REAL&lt;/span&gt; ;

    &lt;span class="kwrd"&gt;SET&lt;/span&gt; @WeeksDivisor = @DaysDivisor * 7 ;

    &lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt;
        @Results
        (
          milliseconds
        , Seconds
        , Minutes
        , Hours
        , Days
        , Weeks

        )
        &lt;span class="kwrd"&gt;SELECT&lt;/span&gt;
            @MilliSecondsREAL
        ,   @MilliSecondsREAL / @SecondsDivisor seconds
        ,   @MilliSecondsREAL / @MinutesDivisor minutes
        ,   @MilliSecondsREAL / @HoursDivisor hours
        ,   @MilliSecondsREAL / @DaysDivisor days
        ,   @MilliSecondsREAL / @WeeksDivisor weeks

    &lt;span class="kwrd"&gt;RETURN&lt;/span&gt;

&lt;span class="kwrd"&gt;END&lt;/span&gt;

GO&lt;/pre&gt;&lt;img src="http://weblogs.sqlteam.com/jeffm/aggbug/60534.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Maass</dc:creator>
            <guid>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/Milliseconds-to-Detail.aspx</guid>
            <pubDate>Mon, 25 Feb 2008 13:03:39 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/Milliseconds-to-Detail.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/jeffm/comments/commentRss/60534.aspx</wfw:commentRss>
        </item>
        <item>
            <title>DTS Script out - SQL Server 2000</title>
            <link>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/DTS-Script-out---SQL-Server-2000.aspx</link>
            <description>&lt;div class="itemtext"&gt;
&lt;div class="snap_preview"&gt;
&lt;p&gt;My preferred method of persisting a DTS package is by saving it to the server and backing up MSDB. At one of my employers, I found many filepaths and other should be variables hardcoded in. Not one week passed before someone said, what’s making this file? To find the creator of the file, I needed a way to GREP their DTS packages. I found this neat article on SQL Server Central. &lt;a target="_blank" title="http://www.sqlservercentral.com/scripts/viewscript.asp?scriptid=1613" href="http://www.sqlservercentral.com/scripts/viewscript.asp?scriptid=1613"&gt;http://www.sqlservercentral.com/scripts/viewscript.asp?scriptid=1613&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I run it as a .vbs file, and start an instance of it for every server, using a quick and easy batch file such as:&lt;br /&gt;
“\\Fileserver-4\DTS\Script Out DTS Packages-CmdArgs.vbs” /server:SQLSVR2 /backupfolder:”\\Fileserver\DTS”&lt;/p&gt;
&lt;p&gt;“\\Fileserver-4\DTS\Script Out DTS Packages-CmdArgs.vbs” /server:SQLSVR2 /backupfolder:”\\Fileserver\DTS”&lt;/p&gt;
&lt;p&gt;One possible use is for easy change control via a text file diffing.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!-- You can start editing here. --&gt; &lt;hr /&gt;
&lt;h4&gt; &lt;/h4&gt;&lt;img src="http://weblogs.sqlteam.com/jeffm/aggbug/60533.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Maass</dc:creator>
            <guid>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/DTS-Script-out---SQL-Server-2000.aspx</guid>
            <pubDate>Mon, 25 Feb 2008 12:55:56 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/DTS-Script-out---SQL-Server-2000.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/jeffm/comments/commentRss/60533.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Cleaning a Phone Number with a Function</title>
            <link>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/Cleaning-a-Phone-Number-with-a-Function.aspx</link>
            <description>&lt;div class="itemtext"&gt;
&lt;div class="snap_preview"&gt;
&lt;p&gt;Not much more to say other than, taking the resources - CPU, Memory, Time to loop through the characters in a phone number and retrieving all #’s is better than crap. Don’t blame me, blame the designer who allowed a phone number to be stored as varchar with no constraints.&lt;/p&gt;
&lt;p&gt;Oh, and maybe since we’re talking varchar, you can’t get crazy and replace | with 1 and Oo with 0 and all that other stuff we DBA’s LOVE to do.  Crap is crap.&lt;/p&gt;
&lt;p&gt;When I looked on the web, I found this post and liked the last posted script the best:  &lt;a target="_blank" title="http://sqljunkies.com/Forums/ShowPost.aspx?PostID=11222" href="http://sqljunkies.com/Forums/ShowPost.aspx?PostID=11222"&gt;http://sqljunkies.com/Forums/ShowPost.aspx?PostID=11222&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://weblogs.sqlteam.com/jeffm/aggbug/60532.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Maass</dc:creator>
            <guid>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/Cleaning-a-Phone-Number-with-a-Function.aspx</guid>
            <pubDate>Mon, 25 Feb 2008 12:54:36 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/Cleaning-a-Phone-Number-with-a-Function.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/jeffm/comments/commentRss/60532.aspx</wfw:commentRss>
        </item>
        <item>
            <title>DTS Logging - SQL Server 2000</title>
            <link>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/DTS-Logging---SQL-Server-2000.aspx</link>
            <description>&lt;div class="itemtext"&gt;
&lt;div class="snap_preview"&gt;
&lt;p&gt;It’s been a while since I used DTS.  I was trying to remember the right way to do logging in DTS.  First, I just said - hey, I’ll do a File System Object File.  Then, I said to myself, no way, that’s bogus, there has got to be an easier way……  So I found this:DTSPackageLog.  What’s funny is that the DTSPackageLog may or may not be available.  You have to test it for null or nothing prior to attempting to use it.  I soo hate that crap.  It makes no sense to me.  I used to feel bad about not understanding these sorts of ideas, until a good friend told me to take it easy on myself.  I think what he said was - “It’s not you, it just doesn’t make sense.”   Long story short, DTSPackageLog = sounds neat, but long term plan = fso writing to a reliable ( existing ) temp folder.&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" title="http://msdn2.microsoft.com/en-US/library/aa936769(SQL.80).aspx" href="http://msdn2.microsoft.com/en-US/library/aa936769%28SQL.80%29.aspx"&gt; http://msdn2.microsoft.com/en-US/library/aa936769(SQL.80).aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" title="http://www.ureader.com/message/1200664.aspx" href="http://www.ureader.com/message/1200664.aspx"&gt;http://www.ureader.com/message/1200664.aspx&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://weblogs.sqlteam.com/jeffm/aggbug/60531.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Maass</dc:creator>
            <guid>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/DTS-Logging---SQL-Server-2000.aspx</guid>
            <pubDate>Mon, 25 Feb 2008 12:54:01 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/DTS-Logging---SQL-Server-2000.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/jeffm/comments/commentRss/60531.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Sql Server Management Studio Slow</title>
            <link>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/Sql-Server-Management-Studio-Slow.aspx</link>
            <description>&lt;div class="itemtext"&gt;
&lt;div class="snap_preview"&gt;
&lt;p&gt;I really dug this explanation of the “slowness” in Management Studio. &lt;a target="_blank" title="http://blogs.msdn.com/euanga/archive/2006/07/11/662053.aspx" href="http://blogs.msdn.com/euanga/archive/2006/07/11/662053.aspx"&gt;http://blogs.msdn.com/euanga/archive/2006/07/11/662053.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is the “official” kb article:&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" title="http://support.microsoft.com/kb/555686" href="http://support.microsoft.com/kb/555686"&gt;http://support.microsoft.com/kb/555686&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;img src="http://weblogs.sqlteam.com/jeffm/aggbug/60530.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Maass</dc:creator>
            <guid>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/Sql-Server-Management-Studio-Slow.aspx</guid>
            <pubDate>Mon, 25 Feb 2008 12:53:07 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/jeffm/archive/2008/02/25/Sql-Server-Management-Studio-Slow.aspx#feedback</comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/jeffm/comments/commentRss/60530.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Easy Fix - Low Hanging Fruit - Get Em 'for they're hot.</title>
            <link>http://weblogs.sqlteam.com/jeffm/archive/2008/02/20/Easy-Fix---Low-Hanging-Fruit---Get-Em-before.aspx</link>
            <description>I am of the opinion that every table should have a clustered index.  Also, I recently saw somewhere ( maybe SqlTeam, I don't remember ) a quote from Joe Celko, "You don't have a table unless you have a key."  Which totally sounds like something he would say.  BTW, I got to meet him @ Pass one year.  Dude is wicked smart.  Wicked.&lt;br /&gt;
&lt;br /&gt;
Done with the name dropping.&lt;br /&gt;
&lt;br /&gt;
====================================&lt;br /&gt;
Basic idea: &lt;br /&gt;
You have a poorly performing database.  You can't / don't have time to re-write all of the stored procedures or many of them or whatever.  Code can't change right now.  Run this script, find the tables without Clustered indexes and primary keys and start planning.&lt;br /&gt;
&lt;br /&gt;
Clustered indexes allow SQL Server to work more efficiently.  Primary keys support the use of foreign keys.  Data integrity is sooo sexy.   Do say this to your boss.  They will love it and promote you.&lt;br /&gt;
&lt;br /&gt;
Things to keep in mind:&lt;br /&gt;
&lt;ul&gt;
    &lt;li&gt;Creating / changing a clustered index on a table means that EVERY row in the table must be moved.  Bad news: a BIG table will take a LONG time.  Good news:  a BIG table will show a HUGEr performance improvement.&lt;/li&gt;
    &lt;li&gt;read up on clustered indexes and primary keys before beginning.  While they are often set on the same column or set of columns, they are not the same thing.&lt;/li&gt;
    &lt;li&gt;Primary keys by definition are on unique columns.  Consider this:  If you aren't sure, I mean 100% positive, that the columns you have chosen for your primary key will be unique, you are probably going to break something.  If there is data in the table, then the creation of the key will not be successful.  But perhaps you are placing the key on a table which at the moment is empty.  Then the application which has been rolling along for the last 2.5 years goes cablooey trying to insert.  Be careful.  ( Yet another good example of why designing first, then coding saves lives ).&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====================================&lt;br /&gt;
Script: &lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;USE&lt;/span&gt; master&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;go&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;IF&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;EXISTS&lt;/span&gt; ( &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;span class="kwrd"&gt;TOP&lt;/span&gt; 1&lt;br /&gt;                    1&lt;br /&gt;                &lt;span class="kwrd"&gt;FROM&lt;/span&gt;&lt;br /&gt;                    sys.databases&lt;br /&gt;                &lt;span class="kwrd"&gt;WHERE&lt;/span&gt;&lt;br /&gt;                    name = &lt;span class="str"&gt;'MaasSqlTest'&lt;/span&gt; ) &lt;br /&gt;    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;DATABASE&lt;/span&gt; MaasSqlTest&lt;br /&gt;    &lt;span class="kwrd"&gt;END&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;USE&lt;/span&gt; MaasSqlTest&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;IF&lt;/span&gt; ( OBJECT_ID(&lt;span class="str"&gt;'dbo.TablesWithoutPKorCL'&lt;/span&gt;) &lt;span class="kwrd"&gt;IS&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt; ) &lt;br /&gt;    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;        --YEUP, &lt;span class="kwrd"&gt;if&lt;/span&gt; the script &lt;span class="kwrd"&gt;is&lt;/span&gt; successful, this &lt;span class="kwrd"&gt;table&lt;/span&gt; WILL show up &lt;span class="kwrd"&gt;in&lt;/span&gt; itself&lt;br /&gt;        &lt;span class="kwrd"&gt;create&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[TablesWithoutPKorCL]&lt;br /&gt;            (&lt;br /&gt;              [DBName] [nvarchar](128) &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;            , [SchemaName] [sysname] &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;            , [TableName] [sysname] &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;            , [HasUniqueCnst] [&lt;span class="kwrd"&gt;int&lt;/span&gt;] &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;            , [HasClustIndex] [&lt;span class="kwrd"&gt;int&lt;/span&gt;] &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;            , [HasPrimaryKey] [&lt;span class="kwrd"&gt;int&lt;/span&gt;] &lt;span class="kwrd"&gt;NULL&lt;/span&gt;&lt;br /&gt;            , IFixedThis &lt;span class="kwrd"&gt;BIT&lt;/span&gt; &lt;span class="kwrd"&gt;DEFAULT&lt;/span&gt;(0)&lt;br /&gt;            , ImNotAllowedToFixThis &lt;span class="kwrd"&gt;BIT&lt;/span&gt; &lt;span class="kwrd"&gt;DEFAULT&lt;/span&gt;(0)&lt;br /&gt;            , ThisCantBeFixedNow &lt;span class="kwrd"&gt;BIT&lt;/span&gt; &lt;span class="kwrd"&gt;DEFAULT&lt;/span&gt;(0)&lt;br /&gt;            , UTCDateEntered DATETIME &lt;span class="kwrd"&gt;DEFAULT&lt;/span&gt; ( GETUTCDATE() )&lt;br /&gt;            )&lt;br /&gt;        &lt;span class="kwrd"&gt;ON&lt;/span&gt;  [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;]&lt;br /&gt;&lt;br /&gt;    &lt;span class="kwrd"&gt;END&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;GO&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @&lt;span class="kwrd"&gt;SQL&lt;/span&gt; NVARCHAR(&lt;span class="kwrd"&gt;MAX&lt;/span&gt;) ;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;SET&lt;/span&gt; @&lt;span class="kwrd"&gt;SQL&lt;/span&gt; = &lt;span class="str"&gt;'&lt;br /&gt;INSERT INTO [MaasSqlTest].[dbo].[TablesWithoutPKorCL]&lt;br /&gt;           (&lt;br /&gt;            [DBName]&lt;br /&gt;           ,[SchemaName]&lt;br /&gt;           ,[TableName]&lt;br /&gt;           ,[HasUniqueCnst]&lt;br /&gt;           ,[HasClustIndex]&lt;br /&gt;           ,[HasPrimaryKey]&lt;br /&gt;            )&lt;br /&gt;select&lt;br /&gt;DB_Name() DBName&lt;br /&gt;, S.name SchemaName&lt;br /&gt;, T.name TableName&lt;br /&gt;, OBJECTPROPERTY( object_id, '&lt;/span&gt;&lt;span class="str"&gt;'TableHasUniqueCnst'&lt;/span&gt;&lt;span class="str"&gt;') HasUniqueCnst&lt;br /&gt;, OBJECTPROPERTY( object_id, '&lt;/span&gt;&lt;span class="str"&gt;'TableHasClustIndex'&lt;/span&gt;&lt;span class="str"&gt;') HasClustIndex&lt;br /&gt;, OBJECTPROPERTY( object_id, '&lt;/span&gt;&lt;span class="str"&gt;'TableHasPrimaryKey'&lt;/span&gt;&lt;span class="str"&gt;') HasPrimaryKey&lt;br /&gt;from sys.tables T&lt;br /&gt;JOIN sys.schemas S&lt;br /&gt;ON T.schema_id = S.schema_id&lt;br /&gt;WHERE OBJECTPROPERTY( object_id, '&lt;/span&gt;&lt;span class="str"&gt;'TableHasPrimaryKey'&lt;/span&gt;&lt;span class="str"&gt;') = 0&lt;br /&gt;OR OBJECTPROPERTY( object_id, '&lt;/span&gt;&lt;span class="str"&gt;'TableHasClustIndex'&lt;/span&gt;&lt;span class="str"&gt;') = 0&lt;br /&gt;&lt;br /&gt;'&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;print&lt;/span&gt; @&lt;span class="kwrd"&gt;SQL&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @ExecuteWhere NVARCHAR(&lt;span class="kwrd"&gt;MAX&lt;/span&gt;) ;&lt;br /&gt;&lt;span class="kwrd"&gt;SET&lt;/span&gt; @ExecuteWhere = &lt;span class="str"&gt;'{@DBName}.dbo.sp_executeSQL @stmt = N'&lt;/span&gt;&lt;span class="str"&gt;'{@SQL}'&lt;/span&gt;&lt;span class="str"&gt;''&lt;/span&gt; ;&lt;br /&gt;&lt;span class="kwrd"&gt;SET&lt;/span&gt; @&lt;span class="kwrd"&gt;SQL&lt;/span&gt; = REPLACE(@&lt;span class="kwrd"&gt;SQL&lt;/span&gt; , &lt;span class="str"&gt;''&lt;/span&gt;&lt;span class="str"&gt;''&lt;/span&gt; , &lt;span class="str"&gt;''&lt;/span&gt;&lt;span class="str"&gt;''&lt;/span&gt;&lt;span class="str"&gt;''&lt;/span&gt;) ;&lt;br /&gt;&lt;span class="kwrd"&gt;SET&lt;/span&gt; @ExecuteWhere = REPLACE(@ExecuteWhere , &lt;span class="str"&gt;'{@SQL}'&lt;/span&gt; , @&lt;span class="kwrd"&gt;SQL&lt;/span&gt;) ;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @dbs &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; ( DBName sysname )&lt;br /&gt;&lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt;&lt;br /&gt;    @dbs ( DBName )&lt;br /&gt;    &lt;span class="kwrd"&gt;select&lt;/span&gt;&lt;br /&gt;        name&lt;br /&gt;    &lt;span class="kwrd"&gt;from&lt;/span&gt;&lt;br /&gt;        sys.databases&lt;br /&gt;    &lt;span class="kwrd"&gt;where&lt;/span&gt;&lt;br /&gt;        name &lt;span class="kwrd"&gt;not&lt;/span&gt; &lt;span class="kwrd"&gt;like&lt;/span&gt; &lt;span class="str"&gt;'Staging%'&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @DBName sysname ;&lt;br /&gt;&lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @ExecuteWhere_DBName NVARCHAR(&lt;span class="kwrd"&gt;MAX&lt;/span&gt;) ;&lt;br /&gt;&lt;span class="kwrd"&gt;while&lt;/span&gt; &lt;span class="kwrd"&gt;exists&lt;/span&gt; ( &lt;span class="kwrd"&gt;select&lt;/span&gt; &lt;span class="kwrd"&gt;top&lt;/span&gt; 1&lt;br /&gt;                1&lt;br /&gt;               &lt;span class="kwrd"&gt;from&lt;/span&gt;&lt;br /&gt;                @dbs )&lt;br /&gt;    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;span class="kwrd"&gt;TOP&lt;/span&gt; 1&lt;br /&gt;            @DBName = DBName&lt;br /&gt;        &lt;span class="kwrd"&gt;FROM&lt;/span&gt;&lt;br /&gt;            @dbs&lt;br /&gt;        &lt;span class="kwrd"&gt;SET&lt;/span&gt; @ExecuteWhere_DBName = REPLACE(@ExecuteWhere , &lt;span class="str"&gt;'{@DBName}'&lt;/span&gt; , @DBName) ;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;PRINT&lt;/span&gt; @ExecuteWhere_DBName ;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;EXECUTE&lt;/span&gt; ( @ExecuteWhere_DBName ) ;&lt;br /&gt;&lt;br /&gt;        &lt;span class="kwrd"&gt;DELETE&lt;/span&gt;&lt;br /&gt;            @dbs&lt;br /&gt;        &lt;span class="kwrd"&gt;WHERE&lt;/span&gt;&lt;br /&gt;            DBName = @DBName&lt;br /&gt;    &lt;span class="kwrd"&gt;END&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; *&lt;br /&gt;&lt;span class="kwrd"&gt;from&lt;/span&gt; [MaasSqlTest].[dbo].[TablesWithoutPKorCL]&lt;br /&gt;&lt;/pre&gt;&lt;img src="http://weblogs.sqlteam.com/jeffm/aggbug/60520.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Maass</dc:creator>
            <guid>http://weblogs.sqlteam.com/jeffm/archive/2008/02/20/Easy-Fix---Low-Hanging-Fruit---Get-Em-before.aspx</guid>
            <pubDate>Wed, 20 Feb 2008 14:21:24 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/jeffm/archive/2008/02/20/Easy-Fix---Low-Hanging-Fruit---Get-Em-before.aspx#feedback</comments>
            <slash:comments>6</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/jeffm/comments/commentRss/60520.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Why Views are evil.</title>
            <link>http://weblogs.sqlteam.com/jeffm/archive/2008/02/12/Why-Views-are-evil.aspx</link>
            <description>&lt;p&gt;Synopsis: Views are evil, bad, buggy, temperamental, tortuous, and should be avoided.&lt;/p&gt;
&lt;p&gt;Years ago, when I started out as a wee developer graduating from Microsoft Access, I tried and did port my favorite functionality of Access to Sql Server 2000.  The idea was simple, take some complicated table joins and hide all of those complicated relationships.  In MS Access, that's called a Query.  In Sql Server, it is called a View.  &lt;/p&gt;
&lt;p&gt;In my enthusiasm, I told the report developer, "No more duplicating the same joins across all those stupid stored procedures!  Do it the right way, centralize that code up into a view.  See, how easy this is?"&lt;/p&gt;
&lt;p&gt;I was sooooooo smart, everyone admitted it, except the CIO at raise time ;).  Um, until about a year later, when that same report writer came to me saying that the reports with views weren't running so well.  The why, I still don't know.  I honestly didn't have time to find out.  Though to be honest with myself and you, I had noticed an trend with the views which was already making me queasy.    As time progressed, tables were added.  Lots of tables.  And since, surprise, surprise, the database was reasonably well de-normalized, and we were just making complicated things simple, we added LOTS of tables to those darned views.  &lt;/p&gt;
&lt;p&gt;So, here is why I say views are evil:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;I've historically been burned by them.  Is that not reason enough?&lt;/li&gt;
    &lt;li&gt;sp_refreshview  --- &lt;a target="_blank" href="http://technet.microsoft.com/en-us/library/ms187821.aspx" title="http://technet.microsoft.com/en-us/library/ms187821.aspx"&gt;http://technet.microsoft.com/en-us/library/ms187821.aspx&lt;/a&gt;, google terms: SQL2005 BOL sp_RefreshView.  Can I have an Amen to anyone who learned this the hard way?&lt;/li&gt;
    &lt;li&gt;Views hide complexity by hiding joins.  It is as simple as that.  Joins are a major cause of performance problems.  That hidden simplicity encourages poor T-SQL programming practices.  What I frequently have seen is select X_column1 from viewXY group by X_column1.  Looks fine to me, to you, to everyone.  Wrong!  The view says: Select X_column1....Y_column50 from tableX X join tableY Y on X.xID = Y.XID.  A simple select from the tableX which has a unique index on column1 would have done the trick and done the trick efficiently!&lt;/li&gt;
    &lt;li&gt;One must work especially hard to make a view updatable/insertable.  &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;What about indexed views you ask?  Well, I have an answer!&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://www.microsoft.com/technet/prodtechnol/sql/2005/impprfiv.mspx" title="http://www.microsoft.com/technet/prodtechnol/sql/2005/impprfiv.mspx"&gt;http://www.microsoft.com/technet/prodtechnol/sql/2005/impprfiv.mspx&lt;/a&gt;  .  Follow along with me under:&lt;/p&gt;
&lt;h4&gt;Benefits of Using Indexed Views&lt;/h4&gt;
&lt;p&gt;"Analyze your database workload before implementing indexed views."  &lt;/p&gt;
&lt;p&gt;Hmmmm.  A little further down.  &lt;/p&gt;
&lt;p&gt;"Applications that benefit from the implementation of indexed views include:&lt;/p&gt;
&lt;p&gt;• Decision support workloads&lt;/p&gt;
&lt;p&gt;• Data marts&lt;/p&gt;
&lt;p&gt;• Data warehouses&lt;/p&gt;
&lt;p&gt;• Online analytical processing (OLAP) stores and sources&lt;/p&gt;
&lt;p&gt;• Data mining workloads"&lt;/p&gt;
&lt;p&gt;Whew, finally!&lt;/p&gt;
&lt;p&gt;"On the contrary, online transaction processing (OLTP) systems with many writes, or database applications with frequent updates, may not be able to take advantage of indexed views because of the increased maintenance cost associated with updating both the view and underlying base tables."&lt;/p&gt;
&lt;p&gt;oh, oh, here comes my point:&lt;/p&gt;
&lt;p&gt;"Identifying an appropriate set of indexes for a database system can be complex."&lt;/p&gt;
&lt;p&gt;So, my answer(s).  A) Views and indexed views are not the same thing.  B) Indexed views may help, but ONLY if you are willing to spend quite a bit of time helping them help you.  In my experience, sadly in most development shops, time isn't given for such labor to occur. C) I work primarily on OLTP systems.&lt;/p&gt;
&lt;p&gt;=====================&lt;/p&gt;
&lt;p&gt;More reading on views:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx" title="http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx"&gt;http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx&lt;/a&gt;  Not all editions of support Indexed views the same.  &lt;/p&gt;
&lt;p&gt;&lt;a href="http://sql-server-performance.com/Community/forums/p/7447/43319.aspx" title="http://sql-server-performance.com/Community/forums/p/7447/43319.aspx"&gt;http://sql-server-performance.com/Community/forums/p/7447/43319.aspx&lt;/a&gt;  Adrian's explanation was wonderful.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.sql-server-performance.com/article_print.aspx?id=154&amp;amp;type=tip" title="http://www.sql-server-performance.com/article_print.aspx?id=154&amp;amp;type=tip"&gt;http://www.sql-server-performance.com/article_print.aspx?id=154&amp;amp;type=tip&lt;/a&gt; Tips on creating effective indexed views.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.sql-server-performance.com/tips/views_general_p1.aspx" title="http://www.sql-server-performance.com/tips/views_general_p1.aspx"&gt;http://www.sql-server-performance.com/tips/views_general_p1.aspx&lt;/a&gt; Oh look, someone already beat me to it.  There is nothing new under the sun.  I read this AFTER I wrote most of this blog.  AFTER.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://searchsqlserver.techtarget.com/tip/1,289483,sid87_gci1170220_tax301334,00.html?adg=301324&amp;amp;bucket=ETA#views" title="http://searchsqlserver.techtarget.com/tip/1,289483,sid87_gci1170220_tax301334,00.html?adg=301324&amp;amp;bucket=ETA#views"&gt;http://searchsqlserver.techtarget.com/tip/1,289483,sid87_gci1170220_tax301334,00.html?adg=301324&amp;amp;bucket=ETA#views&lt;/a&gt;  Nuff said.&lt;/p&gt;
&lt;p&gt;=====================&lt;/p&gt;
&lt;p&gt;Conclusion:&lt;/p&gt;
&lt;p&gt;Honestly, after writing this post, I'm starting to think maybe I should reevaluate just where I could use indexed views.  Since I live an ignorant life,  I had written them off without investigating them more thoroughly.  I'm thinking, investigate, recommend, implement, get noticed by the CIO, get a raise.....&lt;/p&gt;
&lt;br /&gt;
=====================&lt;br /&gt;
PS&lt;br /&gt;
2008-02-20&lt;br /&gt;
&lt;br /&gt;
=====================&lt;br /&gt;
&lt;br /&gt;
Scripts:&lt;br /&gt;
I was asked to show what was said in above post was accurate in SQL 2005.  Feel free to copy, paste, read, and then run the code below.&lt;br /&gt;
&lt;br /&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;
/**==============================================================================================================================================================================================
--#region Setup Test &lt;span class="kwrd"&gt;Schema&lt;/span&gt;**/


&lt;span class="kwrd"&gt;USE&lt;/span&gt; master

&lt;span class="kwrd"&gt;go&lt;/span&gt;

&lt;span class="kwrd"&gt;IF&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;EXISTS&lt;/span&gt; ( &lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;span class="kwrd"&gt;TOP&lt;/span&gt; 1
                    1
                &lt;span class="kwrd"&gt;FROM&lt;/span&gt;
                    sys.databases
                &lt;span class="kwrd"&gt;WHERE&lt;/span&gt;
                    name = &lt;span class="str"&gt;'MaasSqlTest'&lt;/span&gt; ) 
    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
        &lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;DATABASE&lt;/span&gt; MaasSqlTest
    &lt;span class="kwrd"&gt;END&lt;/span&gt;

&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;USE&lt;/span&gt; MaasSqlTest

&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;IF&lt;/span&gt; ( OBJECT_ID(&lt;span class="str"&gt;'dbo.ViewTest_Detail'&lt;/span&gt;) &lt;span class="kwrd"&gt;IS&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt; ) 
    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
        &lt;span class="kwrd"&gt;DROP&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; dbo.ViewTest_Detail
    &lt;span class="kwrd"&gt;END&lt;/span&gt;
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;IF&lt;/span&gt; ( OBJECT_ID(&lt;span class="str"&gt;'dbo.ViewTest_Group'&lt;/span&gt;) &lt;span class="kwrd"&gt;IS&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt; ) 
    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
        &lt;span class="kwrd"&gt;DROP&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; dbo.ViewTest_Group
    &lt;span class="kwrd"&gt;END&lt;/span&gt;
&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; dbo.ViewTest_Group
    (
      ViewTest_Group_ID &lt;span class="kwrd"&gt;INT&lt;/span&gt; &lt;span class="kwrd"&gt;IDENTITY&lt;/span&gt;(1 , 1)
                            &lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt; &lt;span class="kwrd"&gt;CLUSTERED&lt;/span&gt;
    , name NVARCHAR(50) &lt;span class="kwrd"&gt;UNIQUE&lt;/span&gt;
    )

&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; dbo.ViewTest_Detail
    (
      ID &lt;span class="kwrd"&gt;INTEGER&lt;/span&gt; &lt;span class="kwrd"&gt;IDENTITY&lt;/span&gt;(1 , 1)
                 &lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt; &lt;span class="kwrd"&gt;CLUSTERED&lt;/span&gt;
    , ViewTest_Group_ID &lt;span class="kwrd"&gt;INTEGER&lt;/span&gt;
    , DateEntered DATETIME &lt;span class="kwrd"&gt;DEFAULT&lt;/span&gt; ( GETUTCDATE() )
    , name NVARCHAR(50) 
      &lt;span class="kwrd"&gt;FOREIGN&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt; ( ViewTest_Group_ID ) &lt;span class="kwrd"&gt;REFERENCES&lt;/span&gt; dbo.ViewTest_Group ( ViewTest_Group_ID )
    )

&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;IF&lt;/span&gt; ( OBJECT_ID(&lt;span class="str"&gt;'dbo.ViewTest_GroupDetail'&lt;/span&gt;) &lt;span class="kwrd"&gt;IS&lt;/span&gt; &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt; ) 
    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
        &lt;span class="kwrd"&gt;DROP&lt;/span&gt; &lt;span class="kwrd"&gt;VIEW&lt;/span&gt; dbo.ViewTest_GroupDetail
    &lt;span class="kwrd"&gt;END&lt;/span&gt;

&lt;span class="kwrd"&gt;GO&lt;/span&gt;

&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;VIEW&lt;/span&gt; dbo.ViewTest_GroupDetail
&lt;span class="kwrd"&gt;AS&lt;/span&gt;  &lt;span class="kwrd"&gt;SELECT&lt;/span&gt;
        G.ViewTest_Group_ID
    ,   G.name GroupName
    ,   D.name DetailName
    ,   D.DateEntered DetailTime
    &lt;span class="kwrd"&gt;FROM&lt;/span&gt;
        MaasSqlTest.dbo.ViewTest_Group G
        &lt;span class="kwrd"&gt;JOIN&lt;/span&gt; MaasSqlTest.dbo.ViewTest_Detail D
            &lt;span class="kwrd"&gt;ON&lt;/span&gt; G.ViewTest_Group_ID = D.ViewTest_Group_ID

&lt;span class="kwrd"&gt;GO&lt;/span&gt;

/**
--#endregion Setup Test &lt;span class="kwrd"&gt;Schema&lt;/span&gt;
==============================================================================================================================================================================================**/

/**==============================================================================================================================================================================================
--#region Populate our &lt;span class="kwrd"&gt;new&lt;/span&gt; tables**/

&lt;span class="kwrd"&gt;GO&lt;/span&gt;
&lt;span class="kwrd"&gt;SET&lt;/span&gt; NOCOUNT &lt;span class="kwrd"&gt;ON&lt;/span&gt; ;

&lt;span class="kwrd"&gt;DECLARE&lt;/span&gt; @cntr &lt;span class="kwrd"&gt;INTEGER&lt;/span&gt; ;
&lt;span class="kwrd"&gt;SET&lt;/span&gt; @cntr = 1 ;

&lt;span class="kwrd"&gt;WHILE&lt;/span&gt; @cntr &amp;lt;= 10
    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
        &lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt;
            dbo.ViewTest_Group ( name )
        &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
            (
              &lt;span class="str"&gt;'GroupID = '&lt;/span&gt; + &lt;span class="kwrd"&gt;CAST&lt;/span&gt;(@cntr &lt;span class="kwrd"&gt;AS&lt;/span&gt; NVARCHAR(50))
        )
        &lt;span class="kwrd"&gt;SET&lt;/span&gt; @cntr = @cntr + 1 ;
    &lt;span class="kwrd"&gt;END&lt;/span&gt;

&lt;span class="kwrd"&gt;SET&lt;/span&gt; @cntr = 1 ;

&lt;span class="kwrd"&gt;WHILE&lt;/span&gt; @cntr &amp;lt;= 10
    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
        &lt;span class="kwrd"&gt;INSERT&lt;/span&gt; &lt;span class="kwrd"&gt;INTO&lt;/span&gt;
            dbo.ViewTest_Detail
            (
              ViewTest_Group_ID
            , name 
        )
            &lt;span class="kwrd"&gt;SELECT&lt;/span&gt;
                G.ViewTest_Group_ID
            ,   &lt;span class="str"&gt;'Detail='&lt;/span&gt; + G.Name
            &lt;span class="kwrd"&gt;FROM&lt;/span&gt;
                dbo.ViewTest_Group G

        &lt;span class="kwrd"&gt;SET&lt;/span&gt; @cntr = @cntr + 1 ;
    &lt;span class="kwrd"&gt;END&lt;/span&gt;

&lt;span class="kwrd"&gt;GO&lt;/span&gt;

/**
--#endregion Populate our &lt;span class="kwrd"&gt;new&lt;/span&gt; tables
==============================================================================================================================================================================================**/


/**==============================================================================================================================================================================================
--#region Test &lt;span class="kwrd"&gt;out&lt;/span&gt; various queries &lt;span class="kwrd"&gt;using&lt;/span&gt; &lt;span class="kwrd"&gt;use&lt;/span&gt; "Display Estimated Execution &lt;span class="kwrd"&gt;Path&lt;/span&gt;" button**/
&lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;

    --run query &lt;span class="kwrd"&gt;plan&lt;/span&gt; &lt;span class="kwrd"&gt;on&lt;/span&gt; this one
    &lt;span class="kwrd"&gt;SELECT&lt;/span&gt;
        *
    &lt;span class="kwrd"&gt;FROM&lt;/span&gt;
        MaasSqlTest.dbo.ViewTest_GroupDetail

    --now run query &lt;span class="kwrd"&gt;plan&lt;/span&gt; &lt;span class="kwrd"&gt;on&lt;/span&gt; this one
    &lt;span class="kwrd"&gt;SELECT&lt;/span&gt;
        ViewTest_Group_ID
    ,   GroupName
    &lt;span class="kwrd"&gt;FROM&lt;/span&gt;
        MaasSqlTest.dbo.ViewTest_GroupDetail
    &lt;span class="kwrd"&gt;GROUP&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt;
        ViewTest_Group_ID
    ,   GroupName

    --maybe the &lt;span class="kwrd"&gt;group&lt;/span&gt; &lt;span class="kwrd"&gt;by&lt;/span&gt; caused &lt;span class="kwrd"&gt;both&lt;/span&gt; tables &lt;span class="kwrd"&gt;to&lt;/span&gt; be accessed, so run query &lt;span class="kwrd"&gt;plan&lt;/span&gt; &lt;span class="kwrd"&gt;on&lt;/span&gt; this one
    &lt;span class="kwrd"&gt;SELECT&lt;/span&gt;
        ViewTest_Group_ID
    ,   GroupName
    &lt;span class="kwrd"&gt;FROM&lt;/span&gt;
        MaasSqlTest.dbo.ViewTest_GroupDetail

    --can we make it more efficient?
    &lt;span class="kwrd"&gt;SELECT&lt;/span&gt;
        ViewTest_Group_ID
    ,   GroupName
    &lt;span class="kwrd"&gt;FROM&lt;/span&gt;
        MaasSqlTest.dbo.ViewTest_GroupDetail
    &lt;span class="kwrd"&gt;WHERE&lt;/span&gt;
        ViewTest_Group_ID = 1
            
    /**==============================================================================================================================================================================================
    --#region Highlight &lt;span class="kwrd"&gt;between&lt;/span&gt; the two ==== lines**/
    &lt;span class="kwrd"&gt;BEGIN&lt;/span&gt;
        --&lt;span class="kwrd"&gt;Group&lt;/span&gt; &lt;span class="kwrd"&gt;by&lt;/span&gt; via the &lt;span class="kwrd"&gt;view&lt;/span&gt;
        &lt;span class="kwrd"&gt;SELECT&lt;/span&gt;
            ViewTest_Group_ID
        ,   GroupName
        &lt;span class="kwrd"&gt;FROM&lt;/span&gt;
            MaasSqlTest.dbo.ViewTest_GroupDetail
        &lt;span class="kwrd"&gt;GROUP&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt;
            ViewTest_Group_ID
        ,   GroupName


        --&lt;span class="kwrd"&gt;Get&lt;/span&gt; rid &lt;span class="kwrd"&gt;of&lt;/span&gt; the &lt;span class="kwrd"&gt;view&lt;/span&gt;.  Query the underlying &lt;span class="kwrd"&gt;table&lt;/span&gt; explicitly..
        &lt;span class="kwrd"&gt;SELECT&lt;/span&gt;
            ViewTest_Group_ID
        ,   Name GroupName
        &lt;span class="kwrd"&gt;FROM&lt;/span&gt;
            MaasSqlTest.dbo.ViewTest_Group
        &lt;span class="kwrd"&gt;GROUP&lt;/span&gt; &lt;span class="kwrd"&gt;BY&lt;/span&gt;
            ViewTest_Group_ID
        ,   Name
    &lt;span class="kwrd"&gt;END&lt;/span&gt;
    /**
    --#endregion Highlight &lt;span class="kwrd"&gt;between&lt;/span&gt; the two ==== lines
    ==============================================================================================================================================================================================**/

&lt;span class="kwrd"&gt;END&lt;/span&gt;
/**
--#endregion Test &lt;span class="kwrd"&gt;out&lt;/span&gt; various queries &lt;span class="kwrd"&gt;using&lt;/span&gt; &lt;span class="kwrd"&gt;use&lt;/span&gt; "Display Estimated Execution &lt;span class="kwrd"&gt;Path&lt;/span&gt;" button
==============================================================================================================================================================================================**/

&lt;/pre&gt;&lt;img src="http://weblogs.sqlteam.com/jeffm/aggbug/60505.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Maass</dc:creator>
            <guid>http://weblogs.sqlteam.com/jeffm/archive/2008/02/12/Why-Views-are-evil.aspx</guid>
            <pubDate>Tue, 12 Feb 2008 00:28:54 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/jeffm/archive/2008/02/12/Why-Views-are-evil.aspx#feedback</comments>
            <slash:comments>5</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/jeffm/comments/commentRss/60505.aspx</wfw:commentRss>
        </item>
        <item>
            <title>My momma always said share.</title>
            <link>http://weblogs.sqlteam.com/jeffm/archive/2008/02/11/Happy-to-be-here.aspx</link>
            <description>&lt;font size="2"&gt;&lt;span style="font-family: Courier New;"&gt;My momma always told me to share.  Thankfully, sharing isn't always a two way street.  &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;Thankfully, because, I've never been great at it.  I used to feel guilty every time I used the Internet to solve a problem at work.  After all, weren't they paying "me" not "them" to sweat?   &lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;Long story short, Internet Usage Guilt ( IUG ) is no longer on my medical chart.  In fact, I'm hoping to not just continue my Internet usage, but to start on that two way street of giving.  My mom would be proud.  If she knew what the Internet is.&lt;/span&gt;&lt;br style="font-family: Courier New;" /&gt;
&lt;br style="font-family: Courier New;" /&gt;
&lt;span style="font-family: Courier New;"&gt;It's been said that as you give, so you will receive.  Before even posting once on SqlTeam, I've been given some great news I longed for over many days: &lt;a href="http://www.ssmstoolspack.com"&gt;http://www.ssmstoolspack.com&lt;/a&gt;.  &lt;/span&gt;&lt;/font&gt;&lt;font size="2" face="Verdana, Arial, Helvetica" style="font-family: Courier New;"&gt;Mladen, going by the handle Spirit1 here on SqlTeam, has RedGate-ish software that I'm jumping to try.  Reading the features list makes my mouth salivate with glee!  I will of course be PayPal-ing, as soon as the next PayCheck arrives....&lt;br /&gt;
&lt;br /&gt;
So basically, I hope this blog will serve as my two way payback for all the years of sharing on SqlTeam.&lt;br /&gt;
&lt;/font&gt;&lt;img src="http://weblogs.sqlteam.com/jeffm/aggbug/60499.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeff Maass</dc:creator>
            <guid>http://weblogs.sqlteam.com/jeffm/archive/2008/02/11/Happy-to-be-here.aspx</guid>
            <pubDate>Mon, 11 Feb 2008 03:17:12 GMT</pubDate>
            <comments>http://weblogs.sqlteam.com/jeffm/archive/2008/02/11/Happy-to-be-here.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://weblogs.sqlteam.com/jeffm/comments/commentRss/60499.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>