Friday, October 09, 2009

Shrinking a SQL Server database

The following command can be used to shrink a SQL Server logfile:

DBCC SHRINKFILE(<file name>, 1)

<file name>should be the name, without the extension, so to shrink the log file to a database called test you would use the command

DBCC SHRINKFILE(test_log, 1)

You can shrink a database with the following command:

DBCC SHRINKDATABASE(<database name>, 1)

To shrink a database called test use the command

DBCC SHRINKDATABASE(test, 1)