Solved

sql server 2005

Posted on 2010-09-22
6
367 Views
Last Modified: 2012-05-10
Hi,

I have got a SQL Query to improve it's performance.

Here is simple format of how it is structured:

Select x,y,z from table a
inner join table b on a.id = b.id
inner jon table c on b.id = c.id
inner join table d on a.id = d.id

left join table w.........
left join  table y.........
left jon table z.........
left join table q.........
left join table p.........

how can this change to produce a faster query...

thanks in advance
0
Comment
Question by:shmz
6 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33740354
The very first thing to check: do you have indexes on all of the columns used in joins and in your WHERE clause?If you are using a WHERE clause, what is it?
0
 

Author Comment

by:shmz
ID: 33740404
Yes there is where clauses which is used for filtering basically
0
 

Author Comment

by:shmz
ID: 33740417
for example
where a.x = @clientID
and b.y between @StartDate and @EndDate
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 11

Expert Comment

by:JoeNuvo
ID: 33740475
can you provide your real query?
(you may change table name/field list to something else to hide it real name, if u want to)
so we can see if some table can be remove or not

since now, we can't see which field need to be retrieve, which field need to be filter etc.
0
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 250 total points
ID: 33741664
1stly u can use "Database Engine Tuning Advisor" for improving performance by creating and using necessary index.
secondly, if u r calling this query very frequenctly then create view on
Select x,y,z from table a
inner join table b on a.id = b.id
inner jon table c on b.id = c.id
inner join table d on a.id = d.id

with proper indexing as Mathew Sir said.

then put left join with other table

CREATE VIEW viewData as
Select x,y,z from table a
inner join table b on a.id = b.id
inner jon table c on b.id = c.id
inner join table d on a.id = d.id


Select x,y,z from viewData
left join table w.........
left join  table y.........
left jon table z.........
left join table q.........
left join table p.........
0
 
LVL 1

Assisted Solution

by:amarsale
amarsale earned 250 total points
ID: 33745537
put a join first on the tables with least no. of rows (from less to more no. of rows)
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 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