Current location - Health Preservation Learning Network - Slimming men and women - How to slim down sql server2000 database?
How to slim down sql server2000 database?
/*-Pay special attention to the steps. If you don't follow the previous steps, please don't follow the following 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, future database processing will fail. You cannot recover until the log is cleared. -*/-All the library names below refer to the library names of the database you want to process, 1. Empty the log dump transaction library name with NO_LOG 2. Truncate the transaction log: use NO_LOG 3 to back up the log library 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. It can also be done by SQL statement-shrink the database DBCC SHRINKDATABASE (library name)-shrink the specified data file, and 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. separate EXEC sp_detach_db @dbname =' library name' B. delete the log file C. attach exec sp _ attach _ single _ file _ db @ dbname =' library name', @ physname =' c: \ program files \ Microsoft SQL server \ MSSQL \ data \ library name. 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: EXEC sp_dboption' library 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 library name to modify file (name= logical file name).