(go) Resolution of an LDF file in SQL Server is too large

Source: Internet
Author: User

Original address: http://blog.itpub.net/35489/viewspace-616459/

In SQL Server, where the transaction log is often large, in addition to setting the database to auto shrink, you can use the following SQL command to quickly clear the transaction log in the database as follows:
-First step: Empty the Log

DUMP TRANSACTION
DatabaseName
With
No_log

--Step Two: Truncate the transaction log

BACKUP LOG
DatabaseName
With
No_log

--Step three: Shrinking the database

DBCC Shrinkdatabase (databasename)


Some points need to be explained:
1. The above SQL commands need to be executed in sequence;
2. Executing the above commands is usually much faster than using the "shrink" command directly in the right-click menu

Resources:
SQL SERVER Database log is full, how to shrink the database log
Http://blog.csdn.net/faintbear/archive/2005/02/06/283316.aspx
How to shrink a database log
Http://www.cndiy8.com/data/web5701/20050228/20050228__3794589.html

---------------------------------------------------------------------------------------

Another easy way to do this is to detach the data and then delete the. ldf file and reattach the database MDF file. You will be prompted to find the. ldf file. You can delete it directly, such as

after deleting, click OK and the database is attached. The newly generated LDF file is only 504 KB

1. After detaching the database into the directory after deleting the. ldf file to the SQL Server attached to the database (will be prompted to find the LDF file, without the control, directly delete it) after the attachment succeeds, the LDF file 504K is confirmed to be feasible, and the content of the website has no influence .... Hehe 2. Shrink the transaction log file with SQL statements but I haven't done it yet. Steps: 1. Back up the transaction log files so that most active virtual log files are inactive. Therefore, you can remove the inactive virtual log files in a later step. To do this, run a Transact-SQL statement similar to the following Transact-SQL statement. Backup LOG <DatabaseName> to DISK = ' <BackupFile> ' NOTE: In this statement,<databasename> is a placeholder for the name of the database to be backed up. In this statement,,<backupfile> is a placeholder for the full path of the backup file. For example, run the following Transact-SQL statement. BACKUP LOG TestDB to disk= ' C:\TestDB1.bak ' 2. Shrink the transaction log file. To do this, run a Transact-SQL statement similar to the following Transact-SQL statement. DBCC Shrinkfile (<filename>, <TargetSize>

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.