Your SlideShare is downloading. ×
  • Like
Sql query tips or query optimization
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Sql query tips or query optimization

  • 55 views
Published

 

Published in Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
55
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
2
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 8/10/13 SQL QueryTips or QueryOptimization beginner-sql-tutorial.com/sql-tutorial-tips.htm 1/2 Beginner SQL Tutorial Tips Here is a few SQL Tips that may save you time and trouble with your SQL table work, SQL command statements ... Ideally, you want to get best results when writing SQL queries, minimizing errors and getting the best query performance when needed. Here is a small list of queries tips that may help you in your SQL queries work and that can optimized SQL for better performance. SQL Tutorial Tips: 1) SELECT only the columns needed, avoid using SELECT *. First, for each column that you do not need every SQL Server performs additional work to retrieve and return them to the client, and the second volume of data exchanged between the client and SQL Server increases unnecessary. 2) SELECT only the rows needed. The less rows retrieved, the faster the query will run. 3) Prune SELECT lists. Every column that is SELECTed consumes resources for processing. There are several areas that can be examined to determine if column selection is really necessary. Example: WHERE (COL8 = ‘X’) If a SELECT contains a predicate where a column is equal to one value, that column should not have to be retrieved for each row, the value will always be ‘X’. 4) When you create a new table always create a unique clustered index belong to it, possibly it is a numeric type. 5) Use JOIN instead of subqueries. As a programmer, subqueries are something that you can be tempted to use and abuse. Subqueries, as show below, can be very useful: SELECT a.id, (SELECT MAX(created) FROM posts WHERE author_id = a.id) AS latest_post FROM authors a
  • 2. 8/10/13 SQL QueryTips or QueryOptimization beginner-sql-tutorial.com/sql-tutorial-tips.htm 2/2 Although subqueries are useful, they often can be replaced by a join, which is definitely faster to execute. SELECT a.id, MAX(p.created) AS latest_post FROM authors a INNER JOIN posts p ON (a.id = p.author_id) GROUP BY a.id 6)