SQL Server Query Efficiency optimization

Source: Internet
Author: User
Tags sql server query

Query Efficiency analysis:

subquery to ensure that duplicate values are eliminated, nested queries must be processed for each result of the external query. In this case, you might consider replacing the join query.

If you want to use a subquery, use exists instead of in, with not exists instead of in. Because the subquery introduced by exists only tests the existence of rows that meet the criteria specified in the subquery, it is more efficient. In either case, not in is the least effective. Because it performs a full table traversal on the table in the subquery.

Establish a reasonable index, avoid scanning redundant data, avoid table scan!

Millions of data, so dozens of milliseconds to complete the query.

Machine condition

p4:2.4

Memory: 1 G

Os:windows 2003

Database: MS SQL Server 2000

Objective: To query performance test and compare the performance of two kinds of queries

SQL query efficiency step by step

--SETP 1.

--Build the table

create table t_userinfo
(
userid int identity(1,1) primary key nonclustered,
nick varchar(50) not null default '',
classid int not null default 0,
writetime datetime not null default getdate()
)

Go

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.