April 18, 2008 at 8:59 am
I am using the EXISTS Clause as
1. IF Exists(Select Specialty from Doctors)
Select 'Yes'
Can anybody tell me that is the following query is better or faster than the st query?
IF Exists(select * from Doctors)
select 'YES'
Whether to user Exist (select * from tablename ......) or Exist (select FieldName from tablename.......)
Thanx for the help!!!! 🙂
Thanks.
Gunjan.
April 18, 2008 at 9:22 am
Performance will not make a difference, but they can return different results.
If the field you reference when not using * returns all NULL values, even if there are rows in the table, the EXISTS will be false.
April 18, 2008 at 9:28 am
Thanks.
But it will be good if my next statements will be based upon that field.
Then it will improve the perfomance...
right??
Thanks.
Gunjan.
April 18, 2008 at 9:31 am
I checked..
Even if the field is NULL it returns the "True" in EXISTS statement...
Thanks.
Gunjan.
April 18, 2008 at 9:33 am
I am not sure what you meant by this:
[font="Courier New"]But it will be good if my next statements will be based upon that field.
Then it will improve the perfomance...
right?? [/font]
but the EXISTS performance will be the same either way.
You can, of course, just look at the execution plans - this is pretty easy to test.
April 18, 2008 at 9:36 am
If you know that you are looking for single field from the table...the definately you should go for if Exists(Select Specialty from Doctors)
April 18, 2008 at 9:42 am
Khelan I think you didn't got the question....
Its about performace.......
which is better one??
Thanks.
Gunjan.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply