SQL Server database record modification tracking and restoration Solution

Source: Internet
Author: User
In project development, many people may encounter such customer requirements: the user must record the user's ID, time, and modified content when operating the key records of the database, if necessary, roll back the recorded content at a certain time point. How can this problem be solved? I have summarized three solutions based on my work experience. If you have any improper or better solutions, please kindly advise :).

1. Data Table redundancy record Method
In key database tables, add fields such as "Date and Time at creation", "create user", "date and time at modification or deletion", "modify or delete user", and "record status, of course, the field name can be simplified. Here we will give a better description. "Record status" includes "currently available" and "ARCHIVE. When a user modifies a record, perform two steps: 1) update the current database record, record the modifier and time, and change "record status" to "ARCHIVE ". 2) create a new record, store the modifier and time as the creator and time, save the new record content, and set "record status" to "currently available ". If you delete a record, you only need to perform the first step.
This solution can be usedProgramAt the front-end, you can easily view the modification history and roll back to "a certain time". Here, rollback is not a real rollback, and you still need to create a new record in the table, it is the same as the modification record operation mentioned above, except that the record content is "at a certain time.
Using this method will cause excessive storage of records in the database table and affect the performance during query and statistics.

2. create a data table record operation
Create an "operation record table" for key data tables in the database ", all modifications, deletions, and even reads to key records can be recorded in the "operation record table, the specific implementation can be controlled in the Program Code , but a better way is to use the trigger control.
This solution allows you to conveniently view the modification history on the front-end and easily roll back to "a certain time ". However, the "operation record table" created for each key data table also affects the performance of SQL Server.
In addition, third parties provide the auxiliary program using this solution: omniaudit
download http://www.ttdown.com/SoftView/SoftView_27817.html

3. use SQL server logs
we know that the SQL Server database records database changes in addition to data files, as well as log files, if we can view the log file content, we know the database operation history, but Microsoft does not provide methods and interfaces such as viewing SQL logs. Fortunately, a software provides this function:
lumigent entegra for SQL Server, download page http://www.ttdown.com/SoftView/SoftView_30135.html
it can track all changes to the database and provide the rollback function, you can also export the operation history.
the advantage of this solution is that you can view the modification history without adding any burden to the database and easily roll back to "a certain time ". However, you must use third-party software instead of operating on the front-end of your program. In addition, lumigent entegra for SQL Server v2.3.1 has poor support for Chinese characters and is somewhat depressed.
looking forward to a better solution...

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.