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>