Create Some SQL Query Optimization Technique

View: 342    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: MySQL   Fields: Other

9 point/3 review File has been tested

It is very important to avoid unnecessary data selection of the query. We should select data field that we need but not all fields of the table.

Introduction

1. Selection of required field only.

It is very important to avoid unnecessary data selection of the query. We should select data field that we need but not all fields of the table.

 SELECT login_id, pawwsord FROM tbluser

2. Index

Properly created Indexes are help to optimize search result. You need to better understanding of the databases before selection of better performing index. Selection of highly utilized filed as index is very important.

 CREATE clustered INDEX ind_login_id ON tbluser(login_id)

3. Primary key

Primary key is the most important index of the table. Most important thing of the primary key is selection of short and unique field. This will leads to easy access to data records.

CREATE TABLE tbluser(id INT,
     name VARCHAR(150),
     email VARCHAR(100),
     login_id VARCHAR(100),
     password VARCHAR(10),
    primary_key(id)
     )

4. Index unique column

Indexing of unique column will improve searching and increase efficiency of the database. You must have better understanding of the data field and their utilization before indexing unique column. Indexing lower utilized column is not helping any improvement of the efficiency of the database.

CREATE INDEX ind_email ON tbluser(email)

5. Select limited records

None of the user interfaces can visualize thousand of record at ones. Hence no means of having selected all the record at once, so always limit the selection when you have large number of record set. Select required data only.

SELECT id, name, email, login_id,password FROM tbluser WHERE 1 limite 10

6. Selection of correct data type and length

Use most appropriate data type and correct length of the data. Bad selection data type will produce bulky databases and poor performance. This will improve resource utilization of the database server.

CREATE TABLE tbluser(id INT,
     name VARCHAR(150),
     email VARCHAR(100),
     login_id VARCHAR(100),
     password VARCHAR(10)
     )

 

7. Avoid in sub query

Always avoid use of IN sub query your application. In sub query will evaluate all the record of table A with table B (product of records) before selecting re

SELECT login_id,name, email FROM tbluser WHERE login_id IN ( SELECT login_id FROM tbllogin_details)

one of correct way is used inner join

SELECT login_id,name, email FROM tbluser INNER JOIN tbllogin_details ONtbluser.login_id = tbllogin_details.login_id

8. Avoid NOT operator

Please avoid the usage of NOT operator situation that numbers of qualifying records are lower than unqualified records. Always used positive operator such as LIKE, EXIST than NOT LIKE, NOT EXIST.

 SELECT * FROM tbluser WHERE email NOT LIKE '%gmail%'

The other way is

 SELECT * FROM tbluser WHERE email LIKE '%yahoo%'

Create Some SQL Query Optimization Technique

Create Some SQL Query Optimization Technique Posted on 07-01-2016  It is very important to avoid unnecessary data selection of the query. We should select data field that we need but not all fields of the table. 3/10 342

Comment:

To comment you must be logged in members.

Files with category

 

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd