Method 1: my usual methods
The code is as follows: |
Copy code |
1. Clear logs Dump transaction database name WITH NO_LOG 2. Truncate transaction logs: Backup log Library name WITH NO_LOG
|
3. Compress database files (if not compressed, the database files will not be reduced
Enterprise Manager -- right-click the database you want to compress -- all tasks -- contract database -- contract file
-- Select Log File -- select to shrink to XXM in the contraction mode. Here, a minimum number of MB allowed to be shrunk is displayed. Enter this number directly and click OK.
-- Select data file -- select to shrink to XXM in the contraction mode. Here, a minimum number of MB allowed to be shrunk is displayed. Enter this number directly and click OK.
You can also use SQL statements to complete
The code is as follows: |
Copy code |
-- Shrink database Dbcc shrinkdatabase (database name) -- Contract the specified data file. 1 is the file number. You can use this statement to query: select * from sysfiles Dbcc shrinkfile (1) |
Method 2: Use code
The code is as follows: |
Copy code |
USE [master] GO Alter database DNName set recovery simple with NO_WAIT GO Alter database DNName set recovery simple -- SIMPLE mode GO USE DNName GO Dbcc shrinkfile (n'dnname _ log', 11, TRUNCATEONLY) GO USE [master] GO Alter database DNName set recovery full with NO_WAIT GO Alter database DNName set recovery full -- restore to FULL mode GO |
Method 2: Use mssql enterprise manager directly
1. Set Database mode to simple mode: Open the SQL Enterprise Manager, in the root directory of the console, open Microsoft SQL Server --> SQL Server Group --> double-click your Server --> double-click to open the Database Directory --> select your database name (such as the forum database) forum) --> then right-click and select Properties --> select options --> Select "simple" in the fault recovery mode, and then click OK to save
2. Right-click the current database to view the shrinking database in all tasks. Generally, the default settings in the database do not need to be adjusted. Click OK directly.
3. After shrinking the database, we recommend that you set your database attributes to the standard mode. The operation method is the same as the first one, because logs are often an important basis for restoring the database in case of exceptions.