Maintenance Plan Usage4:Check Integrity and Shrink database

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Maintenance Plan Usage4:Check Integrity and Shrink database相关的知识,希望对你有一定的参考价值。

一,Check Database Integrity Task

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

Include indexes

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

View TSQL Code

--include inedexes
DBCC CHECKDB(NDB_Study)  WITH NO_INFOMSGS

--Not included index
DBCC CHECKDB(NDB_Study, NOINDEX)


二,Shrink Database Task

Use the Shrink Database Task dialog to create a task that attempts to 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 60 MB of data and 40 MB of free space, with a free space percentage of 50 percent, would result in 60 MB of data and 30 MB of free space (because 50 percent of 60 MB is 30 MB). Only excess space in the database is eliminated. Valid values are from 0 through 100.

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

Caution: Data that is 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(NDB_Study, 10, TRUNCATEONLY)

--Return freed space to OS
DBCC SHRINKDATABASE(NDB_Study, 10, NOTRUNCATE)

 

以上是关于Maintenance Plan Usage4:Check Integrity and Shrink database的主要内容,如果未能解决你的问题,请参考以下文章

Maintenance Plan Usage3:Task Usage (Maintain Index)

CF949 C Data Center Maintenance——边双连通分量

CF949C Data Center Maintenance(建图+强联通分量)

CF 949C Data Center Maintenance——思路+SCC

PLAN

Plan9操作系统基本概念