Operation logs of data records

Source: Internet
Author: User

There are many requirements for a project recently, one of which is to record operation logs on data records, and the logs must be analyzed.

As a result, I began to analyze this requirement:

1. Most of the other projects I previously worked on only need to be refined to who changed and when. it's almost done. however, what the guys asked for this time can be used to analyze the ins and outs of the data, that is, to record who, when, and content of the data. Who else has the time to change the content. Who deleted the record at what time.

 

2. I figured out three things to do from above: 1. Write logs at creation; 2. Write logs at every modification; 3. Write logs at deletion.

 

3. Therefore, we need to consider the relationship between the log table and the real table. Each entity table corresponds to a log table.

Three fields in the log table: xgr -- modifier xgsj -- modification time xglx -- modify the type (which can be "insert, update, delete "), in addition, BH cannot be identified (the BH in the object table must be identified ).

 

4. Implement the SQL statements for these three tasks. The structure of the data table is as follows:

 

 

 

SQL statement for data source Configuration:

Select:

Select * From scd_sgryyfb

 

Update:

Insert into scd_sgryyfb_xgjl ([Zah], [RQ], [RS], [BH], [BS], ryfl, xgr, xgsj, xglx)
Values (@ Zah, @ RQ, @ Rs, @ BH, @ BS, @ ryfl, @ xgr, getdate (), 'update ')
Update [scd_sgryyfb] Set [Zah] = @ Zah, RQ = @ RQ, RS = @ Rs, BS = @ BS, ryfl = @ ryfl where bH = @ BH

 

Insert:

Insert into scd_sgryyfb ([Zah], [RQ], [RS], [BS], ryfl)
Values (@ Zah, @ RQ, @ Rs, 1, @ ryfl)
Declare @ varbh int
Select @ varbh = @ identity
Insert into scd_sgryyfb_xgjl ([Zah], [RQ], [RS], [BH], [BS], ryfl, xgr, xgsj, xglx)
Values (@ Zah, @ RQ, @ Rs, @ varbh, 1, @ ryfl, @ xgr, getdate (), 'insert ')

 

Delete:

Insert into scd_sgryyfb_xgjl ([Zah], [RQ], [RS], [BH], [BS], ryfl, xgr, xgsj, xglx)
Values (@ Zah, @ RQ, @ Rs, @ BH, @ BS, ryfl, @ xgr, getdate (), 'delete ')
Delete from scd_sgryyfb where bH = @ BH

 

@ Xgr assignment:

Protected void sqldatasource1_inserting (Object sender, sqldatasourcecommandeventargs E)
{

E. Command. Parameters ["@ xgr"]. value = user. Identity. Name; // This statement must be customized by yourself. the ID of the login user of the current system must be used.

}

Protected void sqldatasource1_deleting (Object sender, sqldatasourcecommandeventargs E)
{

E. Command. Parameters ["@ xgr"]. value = user. Identity. Name; // This statement must be customized by yourself. the ID of the login user of the current system must be used.

}

Protected void sqldatasource1_updating (Object sender, sqldatasourcecommandeventargs E)
{

E. Command. Parameters ["@ xgr"]. value = user. Identity. Name; // This statement must be customized by yourself. the ID of the login user of the current system must be used.

}

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.