Provide a sophisticated method of compressing the log and database files as follows:
1. Emptying log dump TRANSACTION library name with NO_LOG 2. Truncate transaction log: BACKUP log database name with NO_LOG3. Shrink the database file (if not compressed, The database file does not reduce the Enterprise Manager--right-click the database you want to compress--all tasks--shrink the database--Shrink the file--Select the log file--select shrink to XXM in the shrink mode, here will give a minimum allowable contraction to the number of M, directly enter this number, OK--Select the data file--choose Shrink to XXM in the contraction mode, here will give a allowable contraction to the minimum m number, directly enter this number, OK can also use SQL statement to complete--shrink the database DBCC SHRINKDATABASE (customer data)-- Shrinks the specified data file, 1 is the file number, which can be queried by this statement: SELECT * from SYSFILESDBCC shrinkfile (1) 4. To maximize the size of the log file (in SQL 7.0, this step can only be performed in Query Analyzer) a. Detach the database: Enterprise Manager--server--database--right--detach database B. Delete the log file on my Computer c. Attaching a database: Enterprise Manager--server--database--right--attach database This method generates a new log with a size of more than 500 K or code: The following example separates Pubs, and then attaches a file in pubs to the current server. A. Separating E x e c sp_detach_db @dbname = ' pubs ' B. Deleting a log file C. Appending e x e c sp_attach_single_file_db @dbname = ' pubs ', @physname = ' c:\Pr Ogram Files\Microsoft SQL Server\mssql\data\pubs.mdf ' 5. In order to automatically shrink in the future, do the following settings: Enterprise Manager--server--right-click Database--Properties--Options--select "Auto Shrink"-- SQL statement settings: E X e C sp_dboption ' database name ', ' autoshrink ', ' TRUE ' 6. If you want to keep it from growing too large in the future. Enterprise Manager-Server-right-click Database-Properties-transaction log-limits file growth to XM ( X is the maximum data file size you allow)--SQL statement: ALTER DATABASE name modify file (name= logical file name, maxsize=20) Special Note: Follow the steps, do not enterLine the previous steps, do not do the following steps otherwise it may damage your database. It is generally not recommended to do the 4th, 62 step 4th step Unsafe, it is possible to damage the database or lost data 6th step if the log reaches the upper limit, subsequent database processing will fail after the log cleanup . In addition to provide a more simple method, I have tried, recommend everyone to use. A simpler approach: 1. Right-built Database Properties window--Fault restore model--set to Simple 2. Right-building database All Tasks-shrinking database 3. Right-built Database Properties window--Failure restore model--set to bulk-logged
A quick workaround for MSSQL database log full