473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

DB fundamental

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
Oct 9 '08 #1
4 1193
ck9663
2,878 Expert 2GB
This is what I would've done it.

1. Create your table.
2. Include these columns:
  • RecordStatus (Bit)
    InsertedBy (varchar())
    InsertedOn (Date)
    UpdatedBy (varchar())
    UpdatedOn
3. Insert new record for new users.
4. For updates, terminate the old record and insert the new one. Terminate means you update the RecordStatus to mean that it's a dead record and will be filtered out in WHERE clause whenever someone access this table (or you can create a view or table-function).
5. For the InsertedBy, InsertedOn, UpdatedBy, UpdatedOn, use DEFAULT values.
6. To ensure that everything is paired (new record and old record) use TRIGGER.

Happy coding.

-- CK
Oct 9 '08 #2
Hi

Thanks for the response. What you suggested is how I am also doing it currently. I just thought there may be some way to link updates to specific Primary Keys instead of just have a varchar field with say a persons name in it.
Oct 14 '08 #3
ck9663
2,878 Expert 2GB
There's also a concept that keep this columns:

PrimaryKey
NameofUpdatedColumn
OldValue
NewValue

This would mean you have to keep this table every time there's an updated. So that on that time, you can monitor the movement of the data. For ease of analysis, I still recommend what you're currently doing.

-- CK
Oct 14 '08 #4
Delerna
1,134 Expert 1GB
From the way you describe your second question, thats what users and permissions are intended for. You assign users to your database objects as well as the kind of actions that they can perform (update,delete,read,insert,execute)


In order to log who is making a change you can then use something like

Select Loginame From MASTER.DBO.sysprocesses where SPID=@@SPID

within your stored procs/views/UDF's to determine who it is that is executing it.
This means, of couse that each person must have their own login, at least for the ones you want to log, at least.

I use intranet reports and pass the login from page to page where this is important, otherwise they would need to login to every page where tracking users is important.
Oct 14 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: aurora | last post by:
Hello! Just gone though an article via Slashdot titled "The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software" http://www.gotw.ca/publications/concurrency-ddj.htm]. It argues...
51
by: Casper Bang | last post by:
My question is fundamental I beleive but it has been teasing me for a while: I have two classes in my app. The first class is instantiated as a member of my second class. Within this first class,...
2
by: DaaaDaaa | last post by:
Hi all, What are the fundamentals (fundamental functions) that most small to medium sized organizations that use MS SQL Server 7 or 2000 value most? What's your insight? OK, here's my biased...
3
by: Kyle Kolander | last post by:
I recently looked over the faq item relating to fundamental type sizes: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5 and was a bit surprised, as I had been taught more-or-less the...
8
by: Kyle Kolander | last post by:
Sorry, I sent this to comp.std.c++ and meant to send it here as well... Why are the minimum size guarantees for fundamental types intentionally omitted from section 3.9.1 Fundamental types of...
1
by: bharathreddy | last post by:
This Article gives an introduction to VSTS Team Foundation & fundamental difference between Visual Source Safe (VSS) and VSTS Team Foundation. Team Foundation is a set of tools and technologies...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.