Solved

Sql queries faster?

Posted on 2012-04-10
11
370 Views
Last Modified: 2012-04-13
We are using Sql Server 2k and a VB 6 application.

I find some of the SQL queries take about a minute to retrieve a single record. But then if I try to retrieve the same record a second time it loads pretty quickly in 5 seconds.

What are some of the ways to optimize SQL performance? Would upgrading to newer SQL versions significantly improve performance?
0
Comment
Question by:Ricky66
  • 2
  • 2
  • 2
  • +5
11 Comments
 
LVL 6

Assisted Solution

by:yawkey13
yawkey13 earned 100 total points
ID: 37830514
You need to create indexes on the table(s) being queried.  If you supply one of the queries and the table definition, I can walk you through setting them up.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 100 total points
ID: 37830561
You need to create indexes on the table(s) being queried.
I think that should really say:  You need to create appropriate indexes on your tables. Indexes incur overhead, and too many indexes can actually cause slow down of your DB as well as not having them can. I'm sure yawkey13's intent revolved around this, but I just wanted to make sure it was stated that you have to be smart about how you create your indexes  = )

P.S.

As an FYI, the reason we create indexes on tables is because without them our queries will cause a "full table scan", and for a high-traffic site this will surely lead to customer flocking to a speedier competitor. Searching every row of the DB every time a query hits your DB is certain to cause performance degradation.
0
 
LVL 6

Expert Comment

by:yawkey13
ID: 37830583
That is why I asked for this query and table structure.  My intent is to tell him what index(es) to create and why we are created them.
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 100 total points
ID: 37830667
I find some of the SQL queries take about a minute to retrieve a single record. But then if I try to retrieve the same record a second time it loads pretty quickly in 5 seconds.
That is called caching.  SQL Server will keep the information in memory for a period of time after you query the information.  That is the reason it is so quick the second time.
0
 
LVL 38

Expert Comment

by:Aaron Tomosky
ID: 37831156
What's the size of the db and how much memory does the server have? Keeping the db in memory can sipped things up significantly if possible. If you can rdp into the server you can see if the query is CPU or io bound...
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 18

Expert Comment

by:deighton
ID: 37831412
Indexes are the think to look at first here, I'd definitely go down that route before spending money - you might well be able to get 60 and 5 seconds down to zero seconds.
0
 
LVL 4

Expert Comment

by:agusacil
ID: 37832091
Hi,

Agree with all experts above. It is most likely about missing index on that particular query.

For a complete check list to optimize your SQL Server application performance, see here
http://msdn.microsoft.com/en-us/library/ff647681.aspx
0
 
LVL 4

Assisted Solution

by:agusacil
agusacil earned 100 total points
ID: 37832181
In addition, for your case upgrading to newer version of SQL Server will not improve performance if the necessary index for the query is not created.

New version of SQL Server always come with performance improvement over the older version, but it depends on whether or not the application make use of the new feature (e.g. small scale application may not get much improvement by upgrade). It is better to focus on the 'basic' things first before considering upgrade.
0
 

Assisted Solution

by:nitin_s_shah
nitin_s_shah earned 100 total points
ID: 37837746
Create Index for all Order by fields and check the difference.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 37840576
I suspect the author no longer cares or has left the building...
0
 

Author Closing Comment

by:Ricky66
ID: 37845649
Thanks all! The issue was with the Sql query.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Exceptions 3 35
TSQL previous 5 22
Add '#' to end of file 2 29
converting visio 2010 to powerpoint 2010  - formatting issues 5 3
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now