How to truncate sql database

Hi all,

Today I want to share with you guys a simple database trick which might helps you when the sql database server disk becomes full.

Before doing this, please take the backup for your database

1. Now go to your sql database server and select your database and right click and go to properties and then select options on your right hand side and set recovery model to simple.

2. Select the database and now go to sql query and run the below command

SELECT file_id, name FROM sys.database_files;

3. Run this below command in sql query

DBCC SHRINKFILE (2, TRUNCATEONLY);

where 2 is the id of the transaction log you get in the step 3

4. set recovery model to full again.

Thats it, you have reduced your sql database size by removing log transactions.

 

1 thought on “How to truncate sql database

Leave a reply to AX Cancel reply