Two kinds of ways to build the table on how to record the data changes


title: Record Dual built table on how to change the way data is recorded
DATE: 2018-08-08 22:07:44
Tags: database
---

A project to do at the time to include a rights management capabilities, assign permissions that the owner of the system. And the demand for rights management can access right is infinite issued (I feel reality is not infinite issued (. · ∀ ·) Techno), these do not speak. Because there are rights management to relate to changes in user groups, and permissions, etc., but these operations are to be recorded. So with two options.

1. recorded by a single event record table event:

id uid eventid etime
  • id is incremented
  • uid refers to the user's id, is the object of the event
  • eventid event id, there is another table listing all possible events, eventid its id
  • Time of the event: etime
advantage:
  1. This method is more intuitive, easier you can think of.
  2. Operation is not very troublesome
Disadvantages:
  1. To operate multiple tables at the same time (for example, you want a person of the right to delete, then you want to delete the corresponding records in the permissions table, this event should be recorded in the record table).
  2. All operations may need to train (which seems not what disadvantages (. ^ ▽ ^)).

2. By increasing the time field to record the event

For example, there is a user - grouping table:

id uid guide
  • increment primary key id
  • uid user id
  • gid permission group id

If it is in accordance with the first method, when a person is divided into a set of permissions, then add the appropriate records to this table, but also to add a record to the record sheet. However, if more than two fields, starttime (start time), endtime (end time), it is not the same.

id starttime endtime uid guide

When a user is assigned to a packet, this time on the recording starttime, when a user is kicked packet is recorded in the kick-out time into endtime. In this case, as long as the value can be determined whether there is a user in a state detection endtime, this action not only on the table which records the grouping, but also retains a record.

advantage:
  1. Less need to build the table.
  2. When operations do not need to delete a record, simply record time, less the operating table.
Disadvantages:
  1. If a tables have frequent operations is likely to result in data redundancy.

Guess you like

Origin www.cnblogs.com/flytree/p/11622652.html