May 15, 2006 at 5:58 am
Hi
I am having some master tables referred by a transaction table. In one case the user want to permanently delete master table records. Because of referential integrity I am moving these records into a history table where the description is shown in the transaction table itself and then allow the user to delete the records.
For eg.
Master table - Student, Subject
Transaction table - Marks (foreign key student id, subject id)
If I want to remove Student or Subject permanently, can I create table called MarksHistory with no RI with the master tables( it has the description field in the MarksHistory itself) and allow user to delete student and Marks master.
Is it a right design? Some one can suggest me a alternate one.
Thanks in Advance.
May 15, 2006 at 7:19 am
Just wondering why do you want these Marks History records for that are orphon? One way you may want to keep your records intact even after deletion of Master records is to have Either Active/Inactive BIT Datatype column and when you want to delete the Master record just mark it as Inactive and while retrieving the Marks retrieves data only for Student/Subject that are active. Alternatively, you can a have column like RecDeleted with DATETIME Datatype and update the field with delete command execution time and while retrieving the child records use WHERE parenttable.RecDeleted ISNULL. This way you can audit the deleted date and time.
Prasad Bhogadi
www.inforaise.com
May 16, 2006 at 7:29 am
Hi Ananda,
In my professional opinion every table involved in a parent/child relationship should have a primary/foreign key constraint. I see a lot of databases these days, and in every one I see, there is at least one table with orphaned child rows. For that reason, I strongly suggest that you create primary and foreign key constraints on the "archive" tables, should that be the approach you want to take.
That being said, I suggest that there is a much better approach. Using your approach, you will have to:
Why make all that work for yourself only to separate active data from archive data? Of what real benefit is it? To improve the speed of select statements?
I suggest that you:
This approach saves you a lot of work, of debatable benefit. It also prepares these tables better for data mining.
That's my opinion Anada, based on 10 years of experience with SQL Server.
Richard
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply