Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 More than 3 Laksh Records in Select Query

Author  Topic 

visa123
Yak Posting Veteran

54 Posts

Posted - 2012-08-28 : 03:25:16
Hi

I need to retrieve more than 3,00,000 records in Single Select Statement.

It is very Slow and taking long time to execute it.

please guide us the above scenario to retrieve it in seconds in sql server.

Thanks,
Visa.G



Visa.G

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-08-28 : 04:25:31
Optimise the query - which may mean redesigning the tables.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visa123
Yak Posting Veteran

54 Posts

Posted - 2012-08-28 : 07:22:41
Yes... How to Optimise ?

you mean to create indexes?

Visa.G
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-28 : 07:29:41
Creating indexes might be one way. However, before you do that,

1. find out if you REALLY need to retrieve 300,000 records. If it is for reporting or display, you probably can reorganize it so one page consisting of at most a few hundred records is retrieved each time. But, of course, there are very valid reasons why you may want all 300K records in one shot - for archiving for example.

2. If you do need to retrieve the 300K records, look at the query plan to see what part of the query is taking up the time and resources and then understand why and see if you can optimize it. Creating indexes may be part of the optimization, but you won't know until you examine the query and/or query plan.

3. If you are sending the data over a network to some other site, you may also want to investigate whether it is the network traffic and delays that is causing the perceived delay.
Go to Top of Page
   

- Advertisement -