SQL Server batch index reconstruction (sorting)

Source: Internet
Author: User

When SQL Server accumulates a certain amount of data, the query efficiency is often sharply reduced, which is often intolerable. At this time, we will think of various methods to optimize the system. DBCC is a group of powerful console commands, which are often used by DBCC dbreindex. It can help us recreate the index of a specified table to improve the query speed.

This command is easy to use, for example:

DBCC dbreindex ([Customer], '', 90)

The first parameter is the name of the table to be re-indexed. The second parameter specifies the index name. If it is null, it indicates all. The third parameter is the fill factor, which indicates the data filling degree on the index page, 0 indicates that the previous value is used, and 100 indicates that each index page is filled up. In this case, the query efficiency is the highest, but other indexes are moved when the index is inserted. You can set this parameter based on the actual situation.

This command can only operate on a single table. If you want to re-index all the tables in a database, you need to writeProgram:

Use mydb; declare @ name varchar (100) declare authors_cursor cursor for select [name] From sysobjects where xtype = 'U' order by idopen authors_cursorfetch next from authors_cursor into @ namewhile @ fetch_status = 0 begin DBCC dbreindex (@ name, '', 90) Fetch next from authors_cursor into @ name enddeallocate authors_cursor
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.