SQL Server database compression and database log (LDF) compression method sharing _mssql

Source: Internet
Author: User
Tags mdb database mssql
Access

The operation is very simple, the specific steps are as follows: Open your MDB database, tools--> Database Utilities--> compression and Repair Database (c) ...

SQL SERVER

In general, the contraction of the SQL database does not greatly reduce the size of the database, its primary role is to shrink the log size, you should do this periodically to avoid the database log too large
1, set the database mode to Simple mode: Open SQL Enterprise Manager, in the console root in turn, click the Microsoft Sqlserver-->sqlserver group--> double hit Open your server--> double-click to open the database directory--> Select your database name (such as Forum Database Forum)--> and then right-click to select Properties--> Select option--> in the failover mode select "Simple" and then press OK to save
2, in the current database point right, look at all tasks in the shrinking database, the general inside the default settings do not need to adjust, direct point to determine
3. After the database is finished, it is recommended that you reset your database properties to standard mode, with the 1th, because the log is often an important basis for restoring the database in some unusual cases.
However, the server can use the following statement to execute in Query Analyzer
Copy Code code as follows:

DUMP TRANSACTION [Jc8] with no_log
BACKUP LOG [Jc8] with no_log
DBCC shrinkdatabase ([Jc8])

JC8 is the database name to implement the cleanup of jc8.ldf files.

SQL Server transaction log compression and deletion

Q: How should the transaction log in SQL Server be compressed and deleted?
Answer: There are 3 kinds of concrete methods.
Method One:
First step:
BACKUP LOG database_name with NO_LOG
or BACKUP LOG database_name with TRUNCATE_ONLY
--No_log and truncate_only are synonymous here, and any sentence can be executed casually.
Step Two:
1. Shrink all data and log files for a particular database and execute:
DBCC SHRINKDATABASE (Database_name,[,target_percent])
--database_name is the name of the database to shrink, and target_percent is the percentage of the remaining free space that is required in the database file after shrinking.
2. Shrink data or log files from one particular database at a time, executing
DBCC SHRINKFILE (File_id,[,target_size])
--FILE_ID is the identification (ID) number of the file to shrink, to obtain the file ID, use the FILE_ID function or search the current database for sysfiles;target_size is the desired file size in megabytes (represented by integers). If not specified, DBCC SHRINKFILE reduces the file size to the default file size. Two DBCC can be brought with parameter notruncate or truncateonly, meaning to view online help.
Method Two:
First step:
Back up the entire database before it's rainy.
Step Two:
After the backup is complete, execute the following statement in Query Analyzer:
EXEC sp_detach_db Yourdbname,true
--Remove the DB's registration information in MSSQL
Step Three:
Delete the log file in the same directory as the physical file of the log or move the log file out of the directory
Fourth Step:
In Query Analyzer, execute the following statement:
EXEC sp_attach_single_file_db Yourdbname, '
D:\mssql\data\yourDBName_data.mdf '
--Register the DB as a single file, and if successful, MSSQL will automatically generate a 500K log file for this db.
Method Three:
1. Enter Enterprise Manager, select database, such as Demo
2.-> separate database for all tasks
3. To the database file storage directory, will be muonline_log. LDF file deletion, just in case, you can cuff it.
4. Enterprise Manager-> Append database, select MuOnline, this time you will see log file This is a fork, do not matter, continue, at this time the database will prompt you whether the database has no log to create a new one, OK.
5. Remember that the user wants to reset the database after it is reattached.
If later, do not want it to become larger:
Use under SQL2000:
Right-click on the Database-> properties-> option-> failure recovery-model-select-Simple model.
or with SQL statements:
ALTER DATABASE name set recovery simple
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.