SQL Server Overwrite Index

Source: Internet
Author: User

An overriding index is usually a composite index, which is the number of indexed fields. you should be aware of the index order when creating an index.

When SQL Server retrieves the application index, the field recognition order is left-to-right.

For example, the following index is used

Create nonclustered Index Ix_student_name_class_sex

On Tb_student (Name,class,sex)

Select * from Tb_student as S where s.name= ' ws '//Can be used

Select * from Tb_student as S where s.name= ' ws ' and S.class=1//can be used

Select * from Tb_student as S where s.name= ' ws ' and S.class=1 and s.sex=1//can be used

Select * from Tb_student as S where S.class=1 and s.sex=1//cannot use the index created

So when we create and use indexes, we need to be aware of the sort order of the fields.

When creating an index, use fields that are not updated as much as possible to avoid the non-clustered index maintenance costs that are brought when the update occurs. When you write an UPDATE statement, try to avoid updating the index fields.

You should decide if you need to update the field by adding a judgment so that you avoid the same data and update it, resulting in the cost of index maintenance for unnecessary data coverage.

If the index field must be updated frequently, then read-write separation can be used. The index is established in the query library as usual, and the update operates in the write library, avoiding the insertion of data maintenance indexes causing too many waits and deadlocks.

SQL Server Overwrite Index

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.