We Recommend

SQL Cookbook SQL Cookbook
Written in O'Reilly's popular Problem/Solution/Discussion style, the SQL Cookbook is sure to please. Anthony's credo is: "When it comes down to it, we all go to work, we all have bills to pay, and we all want to go home at a reasonable time and enjoy what's still available of our days." The SQL Cookbook moves quickly from problem to solution, saving you time each step of the way.


Posted By

DaveChild on 09/11/08


Tagged

database backup shrink logs transaction


Versions (?)


SQL Shrink Transaction Log


Published in: SQL 


  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
Posted By: DaveChild on September 11, 2008

Hmm, seems the code colouring doesn't work quite right with SQL's take on escape characters.

You need to login to post a comment.