Sunday, 10 December 2017

Clearing the MSSQL Database log file using GUI and Scripts

Dear Friend’s
Many times we are going to face the problem while takin a backup or restore in AX 2012 and other version. Here is the solution to come out from that problem we can make the space by clearing the Database logfile.
There are two ways that we can clear the logfile of the MSSQL Database.

  1. By GUI
  2. By SQL Script.
We can clear the log file using MSSQL server by following below steps.
1) Click on Start SSMS ->Run as Admin
2) Once the SQL server open select the data base which you want to clear the log file details.
3) Go to properties of the database and check in the Options that recovery model is set to Simple or not if it’s not set to simple select the Simple and Click on OK.
4) Select the database and Tasks > Shrink > Database.


5) Then click on OK.

6) Now it’s time to revert the Database changes that we had did for clearing the Log file,
Right click on the database select Properties click on Options change the recovery model to Full click OK.

Now you can check the Drive space is got more memory compare to before. 

The above steps will clear the log file of One database, And if we want to clear the log files off all the databases then please execute the below script in in the MSSQL.

1) ALTER DATABASE testdb SET RECOVERY SIMPLE;
2) USE yourdb;
        GO
        CHECKPOINT;
        GO
        CHECKPOINT; -- run twice to ensure file wrap-around
        GO
        DBCC SHRINKFILE(yourdb_log, 200); -- unit is set in MBs
        GO

Thanks in Advance…
Keep DAXing