Description: Here I have explained how to shrink database log file using batch file in Task Scheduler
Procedure:
Procedure:
- First create TSQL script in sql as follow:
------------------------------ TestDB ---------------------------------
use TestDB
go
alter database TestDB set recovery Simple
go
dbcc shrinkfile ('TestDB_log',1)
go
alter database TestDB set recovery Full
Go
------------------------------- TestDB_new --------------------------
use TestDB_new
go
alter database TestDB_new set recovery Simple
go
dbcc shrinkfile ('TestDB_new_log',1)
go
alter database TestDB_new set recovery Full
Go
----------------------------------------------------------------------------
2. Save above file as LogCleanup.sql file in C:\Scripts folder
3. Create batch file to run TSQL script as follow and save it as logclean.bat to C:\Scripts
sqlcmd -S SQLSERVER\SQL14 -E -i "C:\scripts\LogCleanup.sql"
Note: SQLSERVER\SQL14 SQL Instance Name
4. Add schedule in task scheduler to run above batch file.
No comments:
Post a Comment