www.fromthevalley.com.au

Shrink MS SQL Log Files

Shrink the log using TSQL

 

BACK UP THE DATA BASE FIRST!!!!

 

Firstly you need to find the logfile name:

**You can find the logical name of the log file by using the following query:

        SELECT name FROM sys.master_files WHERE type_desc = 'LOG'

 

 

 

If the database is in the SIMPLE recovery model you can use the following statement to shrink the log file:

        DBCC SHRINKFILE (TA100SQLLog, 1000)
 Replace TA100SQLLog with the logical name of the log file  you need shrunk and change 1000 to the number of MB you want the log file 
shrunk to.

BUT to do this, we need the DB to be in recovery mode first.
 

If the database is in FULL recovery model you could set it to SIMPLE, run DBCC SHRINKFILE, and set back to FULL if you don’t care about losing the data in the log.

        ALTER DATABASE TA100SQL
SET RECOVERY SIMPLE
GO
DBCC SHRINKFILE (TA100SQLLog, 1000)
GO
ALTER DATABASE TA100SQL
SET RECOVERY FULL

        
HOMEAJAXAPACHEBizphoneCSSDNSGeneralGraphicsHTMLHardwareJavascriptLinuxMACMS SQLMailMicrosoftOFFICE 365PerlPostgresSEOSocial MediaVMwareWindows 10