Home >Backend Development >PHP Tutorial >Quick solution to full Sql server database log_PHP tutorial
First, a complex method is provided to compress log and database files as follows:
1. Clear logs
DUMP TRANSACTION library name WITH NO_LOG
2. Truncate transaction log:
BACKUP LOG database name WITH NO_LOG
3. Shrink the database file (if not compressed, the database file will not be reduced
Enterprise Manager--right-click the database you want to compress--All tasks--Shrink database--Shrink file
--Select Log file--choose to shrink to XXM in the shrink mode. There will be a minimum number of M allowed to be shrunk. Enter this number directly and confirm
--Select the data file--choose in the shrink mode. Shrink to XXM, here will give a minimum number of M that is allowed to shrink to, just enter this number and confirm
You can also use SQL statements to complete
--Shrink database
DBCC SHRINKDATABASE (Customer Information)
--Shrink the specified data file, 1 is the file number, which can be queried through this statement: select * from sysfiles
DBCC SHRINKFILE(1)
4. In order to maximize the shrinkage of the log file (if It is sql 7.0, this step can only be performed in the query analyzer)
a. Detach database:
Enterprise Manager--Server--Database--right-click--Detach database
b. In my Delete the LOG file on the computer
c. Attach database:
Enterprise Manager - Server - Database - Right click - Attach database
This method will generate a new LOG, the size is only more than 500K
Or use code:
The following example detaches pubs, and then attaches a file in pubs to the current server.
a. Detach
E File
c. Attach
E :
Enterprise Manager--Server--Right-click the database--Properties--Options--Select "Auto Shrink"
--SQL statement setting method:
E , 'TRUE'
6. If you want to prevent the log from growing too large in the future
Enterprise Manager--Server--Right-click Database--Properties--Transaction Log
--Limit the file growth to xM (x is the maximum data file size you allow)
--SQL statement setting method:
alter database database name modify file (name=logical file name, maxsize=20)
Special attention:
Please follow the steps. Please do not do the following steps without completing the previous steps
Otherwise, your database may be damaged.
It is generally not recommended to do steps 4 and 6
Step 4 is not safe , it is possible to damage the database or lose data
Step 6. If the log reaches the upper limit, subsequent database processing will fail and can only be restored after clearing the log.
In addition, a simpler method is provided. I have tried it repeatedly and it is recommended. Used by everyone.
An easier way:
1. Right-click the database properties window--Failure Recovery Model--set to Simple
2. Right create all tasks of the database--Shrink the database
3. Right-click the database properties window--Failure Recovery Model--Set to large-capacity logging