Use transact - SQL commands compress Databases
You can use the DBCC shrinkdatabase and DBCC shrinkfile commands to compress the database. The DBCC shrinkdatabase command compresses the database, DBCC The shrinkfile command compresses the specified files in the database.
( 1 ) DBCC Shrinkdatabase
DBCC The shrinkdatabase command syntax is as follows:
DBCC Shrinkdatabase (database_name [ , Target_percent ]
[ , {Notruncate | truncateonly} ] )
Parameters are described as follows:
· Target _ percent indicates the percentage of unused space in the database size after the database is compressed. If the specified percentage is too large and exceeds the proportion of space not used before compression, the database will not be compressed. In addition, the compressed database cannot be smaller than the initial capacity set by the database.
· Notruecate
After the database is reduced, the remaining space is retained in the database and will not be returned to the operating system.
. If this option is not selected, the remaining space is returned to the operating system.
· Truncateonly
After the database is reduced, the remaining space is returned to the operating system. When using this command, SQL Server reduces the file to the last file allocation, but does not move any data files. If this option is selected, the target_percent option is invalid.