SQL Server Performance Forum – Threads Archive
Select statment where clause 1=2Select Col1,Col2 from table1 where 1=2 is this query is optimized query to get just the table skeletal.
if not how would i get the table structure. will the above query scan all the row in table ? Thanks !
No it doesn’t appear to table scan (checked it on a 40million row table ). Tom Pullen
DBA, Oxfam GB
Thanks Thomas, but the below link say its not good practice to do..
http://www.sql-server-performance.com/transact_sql.asp any clue why is it so…? With regards,
Quote from Brad’s tip "Don’t include code that doesn’t do anything. This may sound obvious, but I have seen this in some off-the-shelf SQL Server-based applications. For example, you may see code like this: SELECT column_name FROM table_name
WHERE 1 = 0 When this query is run, no rows will be returned. Obviously, this is a simple example (and most of the cases where I have seen this done have been very long queries), a query like this (or part of a larger query) like this doesn’t perform anything useful, and shouldn’t be run. It is just wasting SQL Server resources. In addition, I have seen more than one case where such dead code actually causes SQL Server to through errors, preventing the code from even running. [6.5, 7.0, 2000] Added 5-30-2003" Well that’s true – but if you only run it as a one-off for a certain purpose, it won’t harm anything. I think Brad meant in terms of putting it in an application.
I use this kind of code frequently for generating column lists.
DBA, Oxfam GB
Tom is correct. I was writing this tip from a purists point of view. —————————–
Brad M. McGehee, MVP