Different ways to Shrink file
1]
USE Database Name
GO
DBCC SHRINKFILE(logfile name, 1)
BACKUP LOG databasename WITH TRUNCATE_ONLY
DBCC SHRINKFILE(logfile_name, 1)
2]
sp_dboption [AdventureWorks], 'trunc. log on chkpt.', 'true'
dbcc shrinkfile ([AdventureWorks_Log])
3] Eliminate the log file completely
Sometimes we just do not need the big log file. For example, I have 40GB log file. I am sure I do not need this log file and want to get rid of it completely to free up the hard drive space. The logic is
a. Detach the database
b. Rename the log file
c. Attach the database without the log file
d. Delete the log file
Let’s say, the database name is testDev. In the SQL Server Management Studio,
Highlight the database-> Tasks->Detach..-> Click OK Go to log file folder -> rename the testDev_log.ldf to be like testDev_log-aa.ldf, Highlight Databases->Attach…-> Click Add -> add the database testDev, highlight the log file and click the ‘Remove’ button. This means you only attach testDev.mdf After this is done, you can verify the contents of the attached database and then delete the log file.
No comments:
Post a Comment