Maintenance Plan Usage4:check Integrity and Shrink database

Source: Internet
Author: User

One, Check Database Integrity Task

Check the allocation and structural integrity of the user and system tables, and indexes in the database, by running the D BCC CHECKDB Transact-SQL statement. Running DBCC ensures that any integrity problems with the database is reported, thereby allowing them to be addressed Later by a system administrator or database owner.

Include indexes

Check the integrity of the index pages as well as the table data pages.

View TSQL Code

-- include Inedexes DBCC CHECKDB (N'db_study') with    no_infomsgs--not Included indexDBCC CHECKDB (N'db_study', NOINDEX)


Two, Shrink Database Task

use the shrink Database Task dialog to create a task that attempts T o Reduce the size of the selected databases. Use the options below to determine the amount of unused space to remain in the database after the database is shrunk (the Larger the percentage, the less the database can shrink). The value is based on the percentage of the actual data in the database. For example, a 100-MB database containing MB of data and + MB of free space, with a free space percentage of Percen T, would result in (MB) of data and a of free space (because-percent of up to MB). Only excess space on the database is eliminated. Valid values is from 0 through.

Shrinking data files recovers space by moving pages of data from the end of the file to unoccupied space closer to the fro NT of the file. When enough free space was created at the end of the file, data pages at end of the the file can deallocated and returned to th E file system.

Caution:data that's moved to shrink a file can be scattered to any available location in the file. This causes index fragmentation and can slow the performance of queries, that search a range of the index. To eliminate the fragmentation, consider rebuilding the indexes on the file after shrinking.

View TSQL Code

-- Retain freed space in database files DBCC Shrinkdatabase (N'db_study', truncateonly)--Return Freed space to OSDBCC shrinkdatabase (N'db_study'), Notruncate)

Maintenance Plan Usage4:check Integrity and Shrink database

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.