Wednesday, March 7, 2012

Cheapest way to see if a value is in a table

Hi,
Can anyone tell me what the most performance friendly way to see if an
id exists in a table is?
I'm currently doing a count on the ID, but I dont really need the server
to count them all - I just need a bool telling me whether its in there!
:-)
Thanks all
SimonSimon,
I can't guarantee it, but I believe one of these is the the most efficient
way:
if exists (select MyID from MyTable where MyID = <something> )
if exists (select * from MyTable where MyID = <something> )
Turn on statistics I/O and statistics time in QA and compare the resources
used: logical reads, cpu, etc. More than likely, they will be very close.
-- Bill
"Simon Harvey" <nothanks@.hotmail.com> wrote in message
news:O0z4ZRKQHHA.4156@.TK2MSFTNGP03.phx.gbl...
> Hi,
> Can anyone tell me what the most performance friendly way to see if an id
> exists in a table is?
> I'm currently doing a count on the ID, but I dont really need the server
> to count them all - I just need a bool telling me whether its in there!
> :-)
> Thanks all
> Simon|||Looks good to me - I'll give it a shot
:-)

No comments:

Post a Comment