473,396 Members | 2,011 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,396 software developers and data experts.

Question about history

I would like to create an history module to my application..

I need some advice to use a duplicate database with who, when and where fields added to that new duplicate table, or create a table with a character field saying which fields have been affected and others fields with who, when and where.

What is the best way to keep an historical table of other table?

Any example or article that I can read.

Sincerely,
Rafael
I'm new using C#.NET. I have C# 2003 with MS SQL Server 2000.
Sep 19 '06 #1
3 2620
Hi Rafael,

If this is a question especific to SQL I think you will get a better answer in a SQL Server NG. I have never had the need of this but I think that using a trigger will be the key, not sure if you will be able to get the who/when part though.

You can set a trigger FOR INSERT/UPDATE and compare the new fields to the original ones and act accordingly.

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Rafael Tejera" <ra**********@hotmail.comwrote in message news:%2***************@TK2MSFTNGP02.phx.gbl...
I would like to create an history module to my application..

I need some advice to use a duplicate database with who, when and where fields added to that new duplicate table, or create a table with a character field saying which fields have been affected and others fields with who, when and where.

What is the best way to keep an historical table of other table?

Any example or article that I can read.

Sincerely,
Rafael
I'm new using C#.NET. I have C# 2003 with MS SQL Server 2000.
Sep 19 '06 #2
If the historical information will be referred to on a daily basis, it is
probably best to set up your history tables within the same database. It is
also unlikely that you will need ALL of the fields from your main tables in
your history tables. Here is a simplification of how I do it: In one of my
tables, I have all of the details of a particular item and another table
contains the current cost information (why cost is separate is topic for
another discussion and not relevant to this one). In my history table, I
save the foreign key of the item table, but instead of an FK from the cost
table, I save the cost info at the time the entry was made along with an
entry date and an edit date.
"Rafael Tejera" <ra**********@hotmail.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
I would like to create an history module to my application..

I need some advice to use a duplicate database with who, when and where
fields added to that new duplicate table, or create a table with a character
field saying which fields have been affected and others fields with who,
when and where.

What is the best way to keep an historical table of other table?

Any example or article that I can read.

Sincerely,
Rafael
I'm new using C#.NET. I have C# 2003 with MS SQL Server 2000.
Sep 19 '06 #3
I built some classes to do this, and it wasn't easy. But now I can have an
application that performs database operations that can be undone and redone.
Let me see if I can sketch it out for you:

I created 2 tables in a database: ChangeLog and ChageRows:

ChangeLog
ChangeID (identity)
UserName (nvarchar)
ChangeTime (DateTime)
TableName (nvarchar)
ChangeType (int)
RolledBack (bool)

ChangeRows
RowID (identity)
ChangeID (int - foreign key to changeLog)
RowIndex (int)
RowValues (nvarchar)

The ChangeType stores an enumerated value from an enumeration I created:

DataChangedEventType
Uninitialized = -1,
RowUpdated = 0,
RowAdded = 1,
RowDeleted = 2,
RowsUpdated = 3,
RowsAdded = 4,
RowsDeleted = 5,
OperationCancelled = 6

Next, I created several interfaces and generic classes:

IHistoryEntry - Interface for HistoryList member classes.
IHistoryList - Interface used by History Client
to access HistoryList members
IHistoryAction : IList - Provides non-Generic access
to HistoryActionList as IList

HistoryList<T : IEnumerable<T>, IEnumerable,
ICollection<T>, ICollection, IList<T>, IList, IHistoryList
where T: IHistoryEntry - Represents a History List of any data type.
HistoryActionList<T: List<T>, IHistoryAction
where T : IHistoryEntry - Undo or Redo List in a HistoryList.

Now, this is a bit more complex than you perhaps need, because I designed it
to be able to work with strongly-typed instances of any type of data. I also
created a ToolStrip Control with Undo and Redo buttons on it.

Basically, this is how it works. You create your custom HistoryEntry class,
using the IHistoryList interface, and then you wire up event handlers to
actions in your interface. Each database action is of one of the types in
the enumeration. When, for example, a row in a DataTable (this is what I
used this for initially) changes, I use the ItemArray of the row to get an
array of all the row values, which I store as a pipe-delimited string in the
RowValues column of the ChangeRows table. This records the current state of
the row. I then make the change, and record the change in the database. The
RowIndex is the current index of the changed row in the database. When
undoing, each action is undone in reverse order, ensuring the state
reverting back in its original form. Deleting a row works the same way. And
so on. Redoing works the same way. The state of the row is stored in the
History list prior to re-doing the last action, and then the action is
re-done. And of course, if you undo to a certain point, and then make a
change, the ReDo list is cleared.

The hardest part (all of it is hard, of course) is building the UI to work
with it. There are 2 History Lists, the Undo and the Redo History List, and
when you undo, the Undone item is moved from the Undo to the Redo History
List, and so on.

That's it in a nutshell. Any more and you'd have to pay me! ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
Digital Carpenter

A man, a plan, a canal,
a palindrome that has gone to s**t.

"Rafael Tejera" <ra**********@hotmail.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
I would like to create an history module to my application..

I need some advice to use a duplicate database with who, when and where
fields added to that new duplicate table, or create a table with a character
field saying which fields have been affected and others fields with who,
when and where.

What is the best way to keep an historical table of other table?

Any example or article that I can read.

Sincerely,
Rafael
I'm new using C#.NET. I have C# 2003 with MS SQL Server 2000.
Sep 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Dunlop | last post by:
leegold2 wrote: > I know php is server side scripting, but say a page is rendered by php > were A = 1. Now, I want when the user clicks the back button on the > browser and sees the page...
4
by: WertmanTheMad | last post by:
Ok here goes, another odd SQL Question ....as always.. How do I get ... The value of a paramater passed to say a Trigger OR The SQL Itself Like this , say I have a Trigger set on delete, ...
4
by: craig | last post by:
I have a question about database design that I think some of the more experienced developers might be able to answer... Early on in the development of the DB for a project we are working on, the...
3
by: Phil Sherman | last post by:
UDB LUW (Windows) 8.1 FP9a I issued a PRUNE HISTORY 20050819 AND DELETE and was surprised to see that the archived log files were not physically deleted. The history record of the 20050818...
3
by: John Baker | last post by:
Hi: I have a table with many months of data on it. I am attempting to create a delete transaction, based on matching a date in the table with a date in another table. The match works perfectly...
6
by: David | last post by:
A user logs into a web site. He is then redirected to a web page of his choosing - based on menu options - for example: "WeeklyReport.aspx" is a page the user is currently viewing If the user...
9
by: Jeff | last post by:
Hello- Ive never used a vector or vectors in C++ so I have a question for you all. I know I can dynamically create the size I need upfront, but is it possible to create them on the fly...
12
by: nyathancha | last post by:
Hi, I have a question regarding best practices in database design. In a relational database, is it wise/necessary to sometimes create tables that are not related to other tables through a...
0
by: Nyh | last post by:
I tried to explain the best I can but it is very difficult to do. Here it goes. I have three history tables. Teacher, student and school. School and teacher, and school and student are linked...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.