Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating Indexes-sql server 2012 web

Posted on 2014-12-11
6
Medium Priority
?
110 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 668 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 70

Accepted Solution

by:
Scott Pletcher earned 668 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 60

Assisted Solution

by:HainKurt
HainKurt earned 664 total points
ID: 40494609
check these indexes first...

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

604 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