SQL Server 2008 Shrink Log

Source: Internet
Author: User

In SQL SERVER 2008, BACKUP Log with TRUNCATE_ONLY is no longer supported, and to shrink the database log, you first need to truncate the file by setting the database recovery mode to simple.

The statements are as follows:

Use DATABASENAME;

GO
--Truncate The log by changing the database recovery model to simple.

ALTER DATABASE DATABASENAME SET RECOVERY simple;

GO
--Shrink The truncated log file to 1 MB.

DBCC Shrinkfile (Databasename_log, 1);

GO
--Reset the database recovery model.

ALTER DATABASE DATABASENAME SET RECOVERY full;

GO
It can also be done through a graphical interface.

By backing up the log first, and then shrinking the log file, the following:

Back database mydb to disk= ' Mydb_bak ';

DBCC SHINKFILE (mydb_log,10);--Shrink to 10m

Error:
[Cause:com.microsoft.sqlserver.jdbc.SQLServerException: The transaction log for database ' RISKDB ' is full. To find out why the space in the log cannot be reused,
See the Log_reuse_wait_desc column in sys.databases. ]

Select Name,log_reuse_wait_desc from sys.databases
----found that the LOG_REUSE_WAIT_DESC for this database in the results is replication to indicate that the log file cannot be compressed because replication
ALTER DATABASE RISKDB set recovery simple
Use RISKDB
DBCC SHRINKFILE (' Riskdb_log ', 10)
ALTER DATABASE RISKDB set recovery full
----

SQL Server 2008 Shrink Log

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.