Current location - Loan Platform Complete Network - Big data management - Teach you how to shrink MSSQL database
Teach you how to shrink MSSQL database
Shrink MSSQL database one: empty log DUMP TRANSACTION database name WITH NO_LOG shrink MSSQL database two: truncate the transaction log: BACKUP LOG database name WITH NO_LOG shrink MSSQL database three: shrink the database file (if you do not compress, the database file will not reduce the enterprise) Manager - right-click on the database you want to compress - all tasks - contraction of the database - shrink the file - select the log file - in the shrinkage mode select shrink to XXM, here will be given a minimum shrinkage to the number of M, directly enter this number, OK on it - select the data file - in the shrinkage mode select shrink to XXM, here will be given a shrinkage to the minimum number of M, directly enter this number, OK on it - select the data file - select the shrinkage mode select shrink to XXM, here will be given a shrinkage to the minimum number of M, directly enter this number of Minimum M number, directly enter this number, OK can also be completed with the SQL statement -- contraction of the database DBCC SHRINKDATABASE (customer information) -- contraction of the specified data file, 1 is the file number, can be queried through the statement: select * from sysfilesDBCC SHRINKFILE (1) shrinkage MSSQL database of four: in order to maximize the shrinkage of the log file (if sql 7.0, this step can only be carried out in the query analyzer) a. Separate the database: Enterprise Manager - server - database - right click - separate 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 that is just over 500K in size or with code: the following example detaches pubs and then attaches a file from pubs to the current server. a. Detach E X E C sp_detach_db @dbname = 'pubs' b. Delete the log file c. Attach again E X E C sp_attach_single_ file_db @dbname = 'pubs',@physname = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf' Shrink the MSSQL database of the fifth: In order to be able to automatically shrink in the future, do the following setup: Enterprise Manager - Server - Right-click the database - Properties - Options - select "autoshrink" - SQL statement settings: E X E C sp_dboption 'database name', 'autoshrink', 'TRUE' 6. If you want to prevent it from logging the growth of the enterprise manager - server - right-click the database - Properties - Transaction logging - the growth of the file will be limited to xM(x is the maximum data file size you allow) -- SQL statement set way: alter database database name modify file(name=logical file name, maxsize=20) shrink MSSQL database of special attention: please follow the steps, not carried out in the previous steps, please do not do the latter steps or may damage your database. Generally not recommended to do step 4,6 step 4 is not safe, may damage the database or loss of data step 6 if the log reaches the upper limit, the subsequent database processing will fail, after cleaning up the logs can be restored. In addition to provide a simpler method, I have tried repeatedly, it is recommended that you use. Shrink the MSSQL database of a simpler method: 1. right build database properties window - failure to restore the model - set to simple 2. right build database all tasks - contraction of the database 3. right build database properties window - failure to restore the model - set to large-capacity logging Above is a simple introduction to how to make the contraction of the MSSQL database. The long spear is not a good idea.