Two ways to clear SQL Server logs

Source: Internet
Author: User

Two methods are available when the log file is full and the SQL database cannot write to the file:
One way: Empty the log.
1. Open Query Analyzer, enter a command
DUMP TRANSACTION database name with NO_LOG
2. Open Enterprise Manager again--right click on the database you want to compress--all tasks--shrink the database--Shrink the file--Select the log file--in the contraction mode to choose to shrink to XXM, here will give an allowable contraction to the minimum number of M, directly enter this number, OK.

The other approach has some risk, because SQL Server log files are not written to the database master file immediately, such as improper processing, can cause data loss.
1: Delete Log
Detach Database Enterprise Manager-> Server-> Database-> Right-click-> Detach Database
2: Delete log file
Attach Database Enterprise Manager-> Server-> Database-> Right-click-> Attach Database
This method generates a new log with a size of more than 500 K.

Note: The first method is recommended.

If later, do not want it to become larger.
Use under SQL2000:
On the database, right-click Properties--Options--model-selection-simple model.
or with an SQL statement:
ALTER DATABASE name set recovery simple

In addition, Truncate log on checkpoint (this option is used for Sql7.0,sql 2000, i.e. the recovery model is selected as a simple model) when the checkpoint command is executed if the transaction log file exceeds 70% of its size Clear the content in the development database always set this option to true auto shrink periodically checks the database when the unused space of the database file or log file exceeds 25% of its size, the system will automatically shrink the file so that its unused space equals 25% Files that do not shrink when the file size is not larger than the initial size when it is established must also be greater than or equal to the initial size of the transaction log file to be reduced only if it is backed up or the Truncate Log on Checkpoint option is set to true.

Note: The default properties of the database that are generally established are set, but when unexpected conditions make the database properties changed, after the user empties the log, check the properties of the database to prevent the transaction log from being filled again.

Related Article

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.