Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would expect absolutely no discernible difference in runtimes between these two queries.</p> <p>However, I would still advocate <em>against</em> SELECT *, and not for performance reasons. There is a long-established myth that SELECT * is less efficient because the engine has to go look up the column names in the metadata, but the truth is that there is still a lookup to <em>validate</em> the column names you've written, and the additional cost of retrieving the names is going to be unnoticeable by humans regardless of the result set size.</p> <p>The reasons I advocate against SELECT * is that:</p> <ul> <li><p>it is unlikely you need <em>all</em> of the columns from the table (or all rows, but that's a different story). If you are pulling back more columns than you need, you are doing unnecessary I/O and perhaps forcing SQL Server to perform a table/clustered index scan when it could have performed a scan on a much skinnier index.</p></li> <li><p>even if you do need all of the columns, using SELECT * can cause hard-to-detect problems in your code later. What if someone inserts a column into the middle of the table? Drops a column? Adds a column? Renames a column? Some of these will be caught immediately but I've demonstrated cases where this can cause all kinds of hard-to-debug problems.</p></li> </ul> <p><a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/10/bad-habits-to-kick-using-select-omitting-the-column-list.aspx" rel="nofollow">http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/10/bad-habits-to-kick-using-select-omitting-the-column-list.aspx</a></p> <hr> <p>As for how CTEs work in general, that's a pretty broad question here. I'd start with these articles:</p> <p><a href="http://www.simple-talk.com/sql/t-sql-programming/sql-server-cte-basics/" rel="nofollow">http://www.simple-talk.com/sql/t-sql-programming/sql-server-cte-basics/</a></p> <p><a href="http://msdn.microsoft.com/en-us/magazine/cc163346.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/cc163346.aspx</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/ms190766%28v=sql.100%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms190766%28v=sql.100%29.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload