Bit of a big question, hoping to start a discussion or just get the best answer out straight.
Trying to work out which is the best way to database history of tables and who did updates to a record.
You have a table:
MEMBERS
MemberId
Name
LName
Email
Password
Now the member updates their details and you dont want to lose their history.
I can think of 2 options:
1.
Create a history table as such.
MEMBERSHISTORY
MemberHistoryId
MemberId
Name
LName
Email
Password
So now you snapshot any changes made to members into this table.
But this seems a bit over the top if the user only updates say one field to snap shot a whole record.
2. The other way I see is:
You normalise the table further, and use a bit Active field to identify the latest details. Thus when a member changes thier details it simply inserts new ones into those tables.
MEMBERS
MemberId
MEMBERNAMES
MemberNameId
MemberId
Name
LName
Active
MEMBERLOGINS
MemberLoginId
MemberId
Email
Password
Active
Which is the better way to do this? What is the standard procedure that is used generally? Type 1 is easier to make, is type 2 a better way to database?
The second question involves capturing who made an update.
Say you have MEMBERS but also ADMINS who can update MEMBERS.
I could add to All Tables
AddedBy varchar
DateAdded
UpdatedBy varchar
DateUpdated
Now if an update is made i can put the name of the admin in there if updated by an admin, or put in the name of the member if updated by the member. And capture that date that the record was added or last updated.
What is the most effective way to do this using IDs?
So an admin updates the table then his ID must be attached to that update, or a member does the update then his ID is attached to the update.
I have an idea as such:
Say updating MEMBERS
MEMBERNAMEMEMBERUPDATES
Id
MemberNameId
MemberId
MEMBERNAMEADMINUPDATES
Id
MemberNameId
AdminId
But this means creating a table for type of user that can update a table for every table that can be updated...this can't be right.
I might be over complicating the whole thing but any pointers would be appreciated.
Thanks