SQL Server: How to delete log files and empty logs

Source: Internet
Author: User

    • 1. Delete Log
    • 2. Clear the Log
    • 3. Shrinking database files
    • 4. truncating the transaction log

The performance of the database is the DBA need to focus on, the increase of log files seriously affect the performance of the database, this article will introduce you to the SQL Server delete log files for your reference, I hope to help you.

In the process of using the database, the log files are increased, which degrades the performance of the database and consumes a lot of disk space. The SQL Server database has a log file, and the log file records the user's actions on the database modifications. You can clear the database log by directly deleting the log file and emptying the logs.

1. Delete LOG1.1 separate database

Before separating the database, make sure to do a full backup of the database, select the database-right--task--separate.

Tick Delete connection

The detached database will not be visible to the database list after it is detached.

1.2 Delete log file 1.3 additional database

The log file will not be found when attached.

Remove the LDF file for database information information:

After attaching the database, a new log file is generated and the new log file size is 504K.

1.4 You can also complete the above operation by command
Use master;exec sp_detach_db @dbname = ' database name '; exec sp_attach_single_file_db @dbname = ' database name ', @physname = ' D:\Program Files \microsoft SQL Server\mssql10. Sql2008\mssql\data\testdb.mdf '

sp_detach_db: Separating the database;

sp_attach_single_file_db: Attaching a single database file, attaching only the data file in the above code, without attaching the log file, meaning to delete the log file.

This command is supported in SQL Server 2005 and 2000, and SQL Server 2008 does not support this command.

2. Clear the Log
DUMP TRANSACTION database name with NO_LOG
3. Shrinking database files
DBCC shrinkfile (' Testdb_log ', 1)

"Data shrinkage" in SQL Server

4. truncating the transaction log
BACKUP LOG TestDB with no_log

The command is also not supported in SQL Server 2008, which can be used in SQL Server 2005 and 2000.

SQL Server: How to delete log files and empty logs

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.