Contract and truncate all database logs on the sqlserver Server

Source: Internet
Author: User
Exec Sp_msforeachdb @ Command1 = N '
Print ''''
Raiserror ( '' Processing Database :? '' , 10, 1) with Nowait
Print ''''

-- Truncate logs
Backup log [?] With no_log

-- Shrink a file
Use [?]
Declare TB cursor local
For
Select n '' DBCC shrinkfile ( '' + Rtrim (fileid) + n '' ) ''
From DBO. sysfiles
Declare @ s nvarchar (4000)
Open TB
Fetch TB into @ s
While @ fetch_status = 0
Begin
Exec (@ s)
Fetch TB into @ s
End
Close TB
Deallocate TB

-- Auto shrink
If lower ( '' ? '' ) Not in ( '' Master '' , '' Tempdb '' )
Exec sp_dboption '' ? '' , '' Autoshrink '' , '' True ''

-- Set the database recovery model to simple
If lower ( '' ? '' ) <> '' Tempdb ''
Exec (n '' Alter database [?] Set recovery simple '' )
'

------ From zhujian

Mssql2005 log contraction

1. Right-click the database to which logs are cleared, such as "testdb", and click [Create query (Q)]
2. Enter the following SQL statement. "testdb" indicates the database name.

 
Dump TransactionTestdbWithNo_log

3. Execute the SQL statement. After successful execution, continue with the following operations:

4. Right-click the database node and click [task (T)]-> [Contract (S)]-> [File (F)]

5. In the displayed "shrink file" dialog box (T) ", Select" log ", and select" shrink operation "and" re-organize the page before releasing unused space (O)"

6. In "shrink files (KIn the ")" text box, enter the minimum size value, and click [OK.

Suddenly found that the original space decreases sharply because of mssql2005 errorlog, rather than the database log file. Too busy ~~~

Now we can clarify the errorlog method of mssql2005.

Sql2005 has a total of 6 errors, from errorlog, errlog.1 to errorlog.6, which seems to be 7 ..

Execute exec sp_cycle_errorlog to generate a new errorlog and delete errorlog.6. In this case, the errorlog can be refreshed six times in a first-in-first-out (similar to a queue) loop. The old one is deleted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.