Wednesday, January 26, 2011

Shrink Log File - SQL

The log file (.log) of the SQL database will keep the track of all transactions happend to the database. As the transaction increases the log file size will get increase.
The following command will help you to shrink (reduce the log file size) your log file, ie. it will remove all the log from the log file.

To get the list of Log file

select name from sys.database_files where type = 1


To Shrink the Log file
DBCC SHRINKFILE('mastlog');


if Still the log file didnt get shinked, there could be a uncommitted transactions.

Execute the following command to get the list of acive transaction
DBCC OPENTRAN('WorkOrders');

Once all the active transactions are closed, then again execute the shrinkfile command