Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 the logical delete

Author  Topic 

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2005-12-06 : 17:19:42
Hello

We have a large sql db, reasonably normalized. Much of our data is hooked to "point in time" type of analysis.
Where literally we need to keep data, but it needs to be deleted (logically or physically). If we do a logical delete, we can maintain data integrity, but the data design is very relational so setting up one table to handle a logical delete results in many database objects needing the additional where criteria. As anyone ever come across a grand way of handling logical deletes of data, (because old records point to these "need to be deleted" records.

Confusing as all getout. I thought I came across a long document on designing data to work in the time sensitive model. Any thoughts.



________________________________________________

Drinking German Beer... fun.
Listening to an accordian player play ACDC...priceless

SamC
White Water Yakist

3467 Posts

Posted - 2005-12-06 : 17:33:49
I have a column in my tables like this:

DELETED BIT NOT NULL DEFAULT 0; -- Set to 1 if deleted

Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2005-12-06 : 19:54:12
I do something like Sam does as well, along with a CreDate and CngDate (Creation Date and Changed Date). SO I can quickly see when a record was created, and when it was last changed.

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-12-06 : 20:00:39
How about a StillReferenced column too?

Set the whole lot to zero (on all tables, only where currently 1 will do I reckon)

Then for all records that have the DELETED bit column = 1 set the StillReferenced = 1 where any associated records can be found (that are not themselves marked as DELETED).

Then delete all the rows that are marked as DELETED and the StillReferenced column = 0

Kristen
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2005-12-06 : 20:19:14
quote:
Originally posted by MichaelP

I do something like Sam does as well, along with a CreDate and CngDate (Creation Date and Changed Date). SO I can quickly see when a record was created, and when it was last changed.
Do you maintain CngDate with a Trigger?
Go to Top of Page

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2005-12-06 : 20:59:08
quote:
Originally posted by Kristen

How about a StillReferenced column too?

Set the whole lot to zero (on all tables, only where currently 1 will do I reckon)

Then for all records that have the DELETED bit column = 1 set the StillReferenced = 1 where any associated records can be found (that are not themselves marked as DELETED).

Then delete all the rows that are marked as DELETED and the StillReferenced column = 0

Kristen



Interesting.... We usually have the createID, EditID, CreateDate, EditDate and then a status column or "deleted" bit. The application maintains those fields (used effectively for are auditing tables with triggers).

One thing that was brought up was using an incremental small int field to make each table have a PK that makes up a ID column and the smallINT. so that each "archived" version of the record, takes an increment and the most current would always be 1.



________________________________________________

Drinking German Beer... fun.
Listening to an accordian player play ACDC...priceless
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2005-12-07 : 19:07:50
Sam, we used to, but we got away from it due to performance / complexity. It's just a coding rule that we impliment in our update statements now. So, it's not 100% sneaky dba proof, but it's good enough for what we need it for in the particular database it's used in.

Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>
Go to Top of Page
   

- Advertisement -