Solved

Creating Indexes-sql server 2012 web

Posted on 2014-12-11
6
97 Views
Last Modified: 2014-12-14
I have a site that displays nordic ski and cross-country running results and, in times of high volume, the results render slowly.  I would like to know how to optimize the query and set indexes.  We did this with my fitness events database but  now I need to do that with the cc meet database and I am not sharp enough to do it alone.  Here is a query to start with:
			sql = "SELECT r.LastName, r.FirstName, t.TeamName, r.RosterID, r.Gender, ir.RaceTime, ir.Excludes, ir.TeamPlace, ir.Bib "
            sql = sql & "FROM Roster r INNER JOIN Grades g ON r.RosterID = g.RosterID INNER JOIN IndRslts ir ON r.RosterID = ir.RosterID "
            sql = sql & "INNER JOIN Teams t ON t.TeamsID = r.TeamsID WHERE ir.RacesID = " & lRaceID & " AND ir.Place <> 0 AND ir.RaceTime <> '00:00' "
			sql = sql & "ORDER BY ir.Place"

Open in new window


What do you need to know about the tables in order to help me?  Sorry for asking a similar question but I just am having a hard time bridging the two.
0
Comment
Question by:Bob Schneider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 22

Assisted Solution

by:plusone3055
plusone3055 earned 167 total points
ID: 40494473
i do not believe in this situation its about changing the syntax of the query you listed above. It looks pretty tight.
 Its about optimizing the tables by creating indexes on the tables.


it doesn't take long at all :)
http://msdn.microsoft.com/en-us/library/ms186342.aspx




http://msdn.microsoft.com/en-us/library/ms190457.aspx

and a great video
https://www.youtube.com/watch?v=ITcOiLSfVJQ
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 40494478
Sorry use the top link first :)

i do not believe in this situation its about changing the syntax of the query you listed above. It looks pretty tight.
 Its about optimizing the tables by creating indexes on the tables.


it doesn't take long at all :)
http://msdn.microsoft.com/en-us/library/ms186342.aspx




http://msdn.microsoft.com/en-us/library/ms190457.aspx

and a great video
https://www.youtube.com/watch?v=ITcOiLSfVJQ
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 167 total points
ID: 40494561
The critical thing is to get the best clustered index on each table.  Everything else with indexes is secondary to that.

Iow, you get the clustering right, you'll get at least decent performance overall no matter what else you do.  Get the clustering wrong, you'll get poor performance overall until/unless you create lots of covering indexes.


Based on the very limited info so far, you could cluster the tables as follows:

Cluster keys for tables:
Roster  by  RosterID
Grades  by  RosterID --maybe an additional column, unknown at this time
--can't tell for sure, likely the first but maybe the second:
IndRslts  by  ( RacesID, RosterID ) OR ( RosterID, RacesID )
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 55

Assisted Solution

by:Huseyin KAHRAMAN
Huseyin KAHRAMAN earned 166 total points
ID: 40494609
check these indexes first...

Roster > RosterID
Grades > RosterID
IndRslts > RosterID, RacesID
Teams > TeamsID
0
 
LVL 50

Expert Comment

by:Vitor Montalvão
ID: 40495671
Would help if you can post the structure of the tables and respective PK, FK and Indexes. The Query Execution Plan would be useful as well.
At least you need to have indexes created on FK's and on columns used in the WHERE clause as well in the ORDER clause.

Assuming that Place and RaceTime can only have positive values I would change the '<>' to '>', like this:
			sql = "SELECT r.LastName, r.FirstName, t.TeamName, r.RosterID, r.Gender, ir.RaceTime, ir.Excludes, ir.TeamPlace, ir.Bib "
            sql = sql & "FROM Roster r INNER JOIN Grades g ON r.RosterID = g.RosterID INNER JOIN IndRslts ir ON r.RosterID = ir.RosterID "
            sql = sql & "INNER JOIN Teams t ON t.TeamsID = r.TeamsID WHERE ir.RacesID = " & lRaceID & " AND ir.Place > 0 AND ir.RaceTime > '00:00' "
			sql = sql & "ORDER BY ir.Place"

Open in new window

0
 

Author Comment

by:Bob Schneider
ID: 40498854
I guess I just need to learn how to create indexes.  I have PK-FK constraints in place and it sounds like my query is good so I will go ahead and learn this before posting back.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

696 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