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.