A union of curiosity and data science

Knowledgebase and brain dump of a database engineer


Shrink Transaction Logs

 
Running the following code truncates the transaction log. A full database backup should be run after this script to insure point of time recovery in any production environment. 

USE <DB>
GO
DBCC SHRINKFILE(<TLOGNAME>, 1)
BACKUP LOG <DB> WITH TRUNCATE_ONLY
DBCC SHRINKFILE(<TLOGNAME>, 1)
GO

 
 
-- New way
use <DB>
ALTER DATABASE <DB> SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(<DB_LOG>, 1)
ALTER DATABASE <DB> SET RECOVERY FULL WITH NO_WAIT