[thesite] last 5 query

Dean Mah dsmah at home.com
Sun Nov 26 21:52:10 CST 2000

jeff writes:

> try to think of triggers as event handlers.  you're doing the same
> thing when using constraints and foreign keys.  you're initiating an
> action (be it an update, delete, etc) whenever another action
> occurs.

I would disagree.  Using a trigger means implementing more than
trivial business logic.  Primary and foreign keys, and to a lesser
extent, check constraints implement trivial data robustness checking.
That said, I would never rely on database constraints.  I'll always
try to catch data inconsistencies within the application.

> the unfortunate side effect of keeping the separation you're talking
> about is an increase of code in the business logic side adding to an
> increase in potential coding errors as well as more convoluted
> logic.

I don't necessarily agree.  In my current environment, we've hired a
programmer a week to help with quite a complex system for the last
couple of months.  Containing some of the business logic in the
database usually makes it more difficult for them to find bugs and
figure out the system.  For example, it is usually more difficult for
them to track down how a table is being changed when it is triggered
by an update to another table.  All of the industry (information
technology in general) people that I've talked to, they've never had
good things to say about the maintainability of triggers in a complex

Whether the additional code sits in the application layer or the
database layer there is still the same potential for coding errors.
And I wouldn't agree that the application code would have more
convoluted logic than the database code.  If anything, you need to
know a couple of languages which makes the maintenance effort greater
and requires a higher knowlegde level on the part of the developers.

> i agree.  however, i think there's an even better approach to this
> issue.  rather than having a "last 5" table, why not just have a
> "last 5" file that's altered whenever there's an insert into the
> database.

I'd still like to see this implemented at the application level.


More information about the thesite mailing list