To Delete A Database Record Or Mark As Deleted? - A Discussion

Yesterday I received an often asked question from a close friend of mine and someone who I very much respect. In his words:

My new company has an existing system that I am rewriting. The system
has a database that follows the philosophy of never really deleting a
record - just set a flag marking it deleted. What do you think of this?

In general, I think it is a bad idea. I think it just creates work
for you in other areas. But I could be naive.

I'm using "ruby on rails", which has this guideline of DRY (Don't
Repeat Yourself). Rails puts things that are traditionally in the
database into the object-relational mapping layer, such as rules on
referential integrity. I guess referential integrity is normally in 2
places: application code (business logic) and database meta data.
Anyway, database constraints are rarely used in rails.

The system is a community site, with discussion boards and lots of
other shared content that is contributed by members. Members may
leave and can be deleted or disabled.

I'm tempted to delete members if they should be deleted. I'm tempted
to delete content if it should be deleted. I'm tempted to leave
content from former members unless the content itself is
inappropriate, though I guess content that is missing an associated
member record would be sort of an orphan. (I'm just thinking out loud
here).

Do you have any general recommendations?

I would hate to add to every single sql statement "when (deleted is
null or deleted=0)". And I think there could be other issues, like
unique key collisions with records that are marked 'deleted'.

On a project I created a schema that had sort of a "weak"
relationship in it. This was the goal planning system. The goal table
had a username column. This username column could be used to find the
user in the user table. But if the user was deleted, the goals still
displayed just fine. I guess if a user joined later, reusing a
previously used username they would inherit some existing goals.
Actually this feature was motivation for the schema — I started with
a set of goals from a big spread sheet and I wanted them to exist and
I wanted to be able to add users and them take ownership of goals
already in the system.

Finally, if I delete records, do you recommend saving the deleted
record in another table? Is that a common practice?

Full article (972 words) »

Update On Super Simple Java ORM Replacement in 80 Lines

I have been inundated with emails after my article Java Database Framework (ORM Replacement) in 80 Lines of Code, asking for the source code of the framework or if I could release it as open source. I haven't been yet able to individually reply to all of them, sorry. I have decided to release it as open source framework targeted for SQL happy Java developers. I plan to release it next week as this week we are all busy releasing version 3.1 of Translator Plugin Pro for WordPress blogs.

Super Simple Java ORM Framework For SQL Happy Developers

I previously mentioned that I intended not to use any Java ORM frameworks. ORM frameworks I have seen so far have a steep learning curve and tend to shoe horn your architecture into their model. So I started fresh without any ORM frameworks like Hibernate or Spring (which I have heard is better).

I am happy coding my queries in SQL and don't need to use any ORM specific language like Hibernate OQL. SQL is best for what it does. Why re-invent the wheel? Also I like the fine-grained control over my database as I am processing very large amount of data. My experience will be primarily relevant to sql happy java developers.
Full article (405 words) »

To Hibernate or not? - A commentary on ORM’s and few recommendations

I came across the post from Jesus Rodriguez where he tries to find good reasons to convince management to use Hibernate.

Full article (536 words) »

Protected by Comment Guard Pro