Use script to narrow the database log

zhaozj2021-02-16  45

Because the database used by the customer often causes the hard disk space to be insufficient because the log is too large, or the backup file cannot be transmitted via mail.

Leisure, refer to SQLServer's help file, write the following script, can truncate logs to achieve the purpose of narrowing the file. Have a space, you can test the effect on your own SQL Server. . . :) Perhaps the logs caused by some cases have no great effect, which can be exchanged with each other.

- Execute the following script (using Query Analyzer) declare @dbname varchar (50) in the MASTER database declare temp_cur cursor scroll for select name from sysdatabasesopen temp_curfetch first from temp_cur into @dbnamewhile @@ fetch_status = 0 begin exec ( 'backup log' @ dbname 'with no_log') exec ( 'dbcc shrinkdatabase (' @ dbname ')') exec ( 'dbcc checkcatalog (' @ dbname ')') exec ( 'dump transaction' @ dbname 'with no_log') Fetch next from temp_cur @dbnamendclose temp_curdeallocate temp_cur

转载请注明原文地址:https://www.9cbs.com/read-25685.html

New Post(0)