Current location - Health Preservation Learning Network - Healthy weight loss - What is the shrink command of sql database?
What is the shrink command of sql database?
1. use NO_LOG 2 to empty the log dump transaction library name. Truncate the transaction log: use NO_LOG3 to back up the log database name. Shrink the database file (if it is not compressed, the file in the database will not decrease in size) Enterprise Manager-Right-click the database to be compressed-All tasks-Shrink the database-Shrink the file-Select the log file-In shrink mode, select shrink to XXM, and the minimum number of m allowed to shrink will be given here. Just enter this number directly and confirm-Select the data file-Select shrink to XXM in shrink mode. The minimum number of m allowed to shrink is given here. Enter this number directly and confirm. You can also shrink the specified data file by SQL statement-shrink database DBCC shrink database-, 1 is the file number. You can query by this statement: select * from sysfiles DBCC shrinkfile (1) 4. In order to minimize the log file (if it is sql 7.0, this step can only be completed in the query analyzer). A. Detach the database: enterprise manager-server-database-right-click-detach the database. B. Delete the log file in my computer. C. Attach the database: enterprise manager-server-database-right-click-attach the database. This method will generate a new log, the size is only more than 500 K or use the code: below. A. Detach execsp _ Detach _ db @ dbname =' pubs' B. Delete the log file C. Attach execsp _ Attach _ single _ file _ db @ dbname =' pubs', @ phys name =' c:\ Program files \ Microsoft SQL Server \ MSSQL \ data \ pubs.mdf' 5. In order to shrink automatically in the future, make the following settings: Enterprise Manager-Server-Right-click Database-Properties-Options-Select Auto Shrink-SQL statement setting method: E X E C sp_dboption' database name',' Auto Shrink', TRUE'6. If you want to prevent its log from growing too much in the future, enterprise manager-server-right-click database-properties-transaction log-limit file growth to xM(x is the maximum data file size you allow)-SQL statement setting method: alter database database name to modify file (name= logical file name, Maxsize=20) Special note: Please follow the steps. Please don't follow the previous steps, or your database may be damaged. Steps 4 and 6 are generally not recommended. Step 4 is unsafe, which may damage the database or lose data. Step 6, if the log reaches the upper limit, the database processing will fail in the future, and it can only be restored after cleaning the log. In addition, I provide a simpler method. I have tried it and recommend it to everyone. A simpler method: 1. Right-click the database properties window-recovery model-and set it to Simple 2. Right-Build Database All Tasks-Shrink Database 3. Right-click the database properties window-recovery model-and set it as bulk logging.