In this case SQL 2000 produces the exact same execution plan for "SELECT 1" and "SELECT *" -
D:\>copy con: select1.sql
set showplan_text on
go
if exists (select 1 from sysobjects where xtype = 'U' and name = 'jobs
+') print 'exists' else print 'doesn''t exist'
^Z
1 file(s) copied.
D:\>copy con: selectstar.sql
set showplan_text on
go
if exists (select * from sysobjects where xtype = 'U' and name = 'jobs
+') print 'exists' else print 'doesn''t exist'
^Z
1 file(s) copied.
D:\>osql -dpubs -n -i selectstar.sql > selectstar.txt
D:\>osql -dpubs -n -i select1.sql > select1.txt
D:\>diff select1.txt selectstar.txt
3c3
< if exists (select 1 from sysobjects where xtype = 'U' and name = 'j
+obs')
---
> if exists (select * from sysobjects where xtype = 'U' and name = 'j
+obs')
And while Win's SQL does compile without error, it may be a disaster in production. For example, this code (including the code you sanction) starts an infinite loop -
use pubs
go
create table Experimental_parameters (c char (1) primary key)
insert into Experimental_parameters (c) values ('a')
go
create table another_table (c char (1) references Experimental_paramet
+ers (c))
insert into another_table (c) values ('a')
go
WHILE (exists(select 1 from INFORMATION_SCHEMA.tables where table_name
+ = 'Experimental_parameters'))
begin
drop table Experimental_parameters -- fails
end
go
print 'finished' -- never gets here
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|