Shrink Database Files
SQL Allow you to shrink data and log file. You can shrink
a file to a size that is less than the size specified when it was created. This
resets the minimum file size to the new value.
We will discussed here some ways to shrink database files.
Before we move to shrink file using queries, first we need to get
names of files which are attached to the database.
Below is the query which is used to retrieve logical name of mdf
and ldf files.
Get Name of mdf and lfd file
Syntax:
USE Database_Name
GO
EXEC sp_helpfile
GO
Shrink database file using queries
By using this query you will be find name of files. No we will
move to use this file name into the query to shrink those files.
Syntax:
Use Database_Name
DBCC
SHRINKFILE (FileNameToShrink' , 1)
SHRINKFILE requires two parameter.
First is the name of file to shrink and other is size for the file in
megabytes, expressed as an integer. If not specified, DBCC SHRINKFILE reduces
the size to the default file size. The default size is the size specified when
the file was created.
Shrink database files through management studio
- Log in to the Microsoft SQL
2000 Server as an administrator.
- Open SQL Enterprise
Manager.
- Right-click the database that
VirtualCenter is using.
- Click Properties.
- Click the Options Tab.
- Set the Recovery Model to Simple as
follows:
- Click OK.
- Right-click on the database again.
- Click All Tasks ->Shrink Database.
- On the Shrink Database window, click Files.
- Select the transaction
log from the database file list. This appears in the list as databasename_Log as follows:
The
space used versus the space allocated displays. In general after you set the
recovery model to Simple you see the majority of the space in the
transaction log released.
- Ensure that the Compress
pages and then truncate free space from end of file radio button is
selected.
- Click OK to shrink
the log.
- Click OK, to perform a
shrink the database, and close the wizard.
Space
is now freed on the server. If there is more than one transaction log for
the database, perform the above steps for each of the logs.
Comments
Post a Comment