Generally do not recommend to do 4th, 62 steps, 4th step unsafe, it is possible to damage the database or loss of data. 6th step if the log reaches the upper limit, subsequent database processing will fail, and the log will not be restored until it is cleaned.
1. Empty log
DUMP TRANSACTION Library name with NO_LOG
2. Truncate the transaction log
BACKUP LOG database name with NO_LOG
3. Shrink Database files
(If not compressed, the database file does not reduce Enterprise Manager--right--the database you want to compress--all tasks--shrink the database--Shrink the file
Select Log file--in the shrinkage method to choose to shrink to XXM, here will give a permit to shrink to the minimum m number, directly enter this number, you can determine
Select the data file--in the shrinkage method to choose to shrink to XXM, here will give a allow to shrink to the minimum m number, directly enter this number, OK, can also use the SQL statement to complete
Shrink Database
DBCC shrinkdatabase (Customer information)
Shrink the specified data file, 1 is the file number, you can query through this statement:
SELECT * FROM Sysfiles
DBCC shrinkfile (1) 4. To minimize the log file (if it is SQL 7.0, this step can only be done in Query Analyzer)
Detach Database:
Enterprise Manager--server--database--right key--detach database
Delete log files on my Computer
Additional databases:
Enterprise Manager--server--database--right Key--additional database
This method will generate a new log with a size of more than 500 k
or in code:
The following example separates pubs and attaches a file in pubs to the current server.
Separation
EXEC sp_detach_db @dbname = ' pubs '
deleting log files
And then attach
EXEC sp_attach_single_file_db @dbname = ' pubs ',
@physname = ' c:\Program Files\Microsoft
SQL Server\mssql\data\pubs.mdf '
4. In order to be able to automatically shrink, do the following settings
Enterprise Manager--server--right key database--Properties--Options--select "Auto Shrink"
How SQL statements are set:
EXEC sp_dboption ' database name ',
' AutoShrink ', ' TRUE '
5. If you want to not let it grow too big log
Enterprise Manager--server--right key database--attribute--transaction log
Limit file growth to XM (x is the maximum data SQL Server file size you allow)
How the SQL statement is set up:
ALTER DATABASE name modify file (name= logical filename, maxsize=20)
Here is a small series of cloud-dwelling communities for everyone to share my own frequently used methods:
DUMP TRANSACTION [jb51] with no_log
BACKUP LOG [jb51] with no_log
DBCC shrinkdatabase ([jb51])
JB51 is the name of the database.
The above related content is the SQL Server compression log and database file size introduction, hope you can have some gains.