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
|