SQL Shrink Transaction Log


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  1. CREATE PROCEDURE Shrink_Transaction_Log AS
  2.  
  3. -- Build log file name
  4. DECLARE @strLogFile AS VARCHAR(100)
  5. SET @strLogFile = 'C:\Backups\SQL\Transaction Logs\'
  6. set @strLogFile = @strLogFile + cast(year(getdate()) as varchar(4)) + ' - ' + right('00' + cast(month(getdate()) as varchar(2)), 2) + ' - ' + right('00' + cast(day(getdate()) as varchar(2)) , 2)
  7. set @strLogFile = @strLogFile + '.bak'
  8.  
  9. BACKUP LOG LiveDatabase TO DISK = @strLogFile
  10.  
  11. -- Reduce log file to acceptable size
  12. DBCC SHRINKFILE(LiveDatabase_Log, 100)
  13.  
  14. GO

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.