February 6, 2006 at 11:05 pm
Folks,
I'm trying to query a table using SELECT statement and WHERE key refering to a unique ID [which has millions of records]...
for eg : select XYZ from dbo.abc where key ='232'
I'm sure this would take hell of time...
Is there a simplest/smartest way to fetch the records in quick time?
Let me know the syntax as well...
Thanks
A
February 7, 2006 at 1:33 am
If your unique ID is your primary key or a unique index then SELECT XYZ FROM dbo.abc WHERE key='232' is going to be fast no matter how many records you have.
If your primary key or unique index is clustered then SELECT XYZ FROM dbo.abc WHERE key BETWEEN '111' AND '999' will also be very fast.
If your key isn't indexed then expect it to take a while.
February 7, 2006 at 3:08 am
If the key column is indexed then create a procedure and pass the parameter
check the statistics for that table to check to wether index are defragmented. This happens if you would havedeleted and added records to that.If that is the case update the stats and rebuild the table, create the procedure. and then check for the execution time.
February 7, 2006 at 3:10 am
"index are defragmented." --> Fragmented
"rebuild the table, " sorry .. defragment the index.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply