Tim said:
I can't remember ever having used ON CASADE
Seriously, wow.
it suggests that you are not confident of the robustness of your PKs
I don't understand your point. For me, it's the opposite case i.e. I
want to assert that my keys (all my candidate keys - who says DRI is
limited to PKs?) are robust.
By you not using CASCADE (SQL commands in uppercase, not shouting <g>)
and instead deleting referencing rows 'by hand' suggests that you are
not confident of the robustness of the engine. Actually, I can't
believe that is true: if you can't trust the engine, what can you trust
it can allow massive record deletion in silence and with no 'undo' facility
I like it when the engine does what it's told without asking me if I'm
sure <g>. Seriously, what is the problem with this? If a particular
user/group isn't trusted to with DELETE/UPDATE permissions then revoke
them.
And sure you have an undo facility: ROLLBACK TRANSACTION.
If my users want to get rid of stuff, they end up with a dialog that
says "you are about to delete 457 visits records -- are you sure?"
There's no reason why you can't do this with a CASCADE e.g. you can
query beforehand to give the user feedback on how many records would be
affected, you could even execute the command in a transaction and
present a view of the data before issuing ROLLBACK (undo) or COMMIT
(apply).
then I create the separate DELETE commands on each
table affected iff the user agrees.
So you must be doing this in a transaction so you can ROLLBACK at the
point when they bail out, yes?
Don't all these messages get annoying e.g. when deleting an employee
you'd get repeated messages ('Are you sure you want to delete this
employee's earnings history?', 'Are you sure you want to delete this
employee's pension contributions history?', etc) when it is implicit
that deleting an employee means you want to remove rows from related
tables e.g. you could show one warning message ('Deleting this employee
will also deleted their earnings history, pension contributions,... Are
you sure?') and likewise execute one delete action.
I am not for a moment criticising. My point is just that I have not
yet come across a project in my own work where there isn't a better
alternative.
Likewise, I am not criticising. I'm just finding it hard to think why
deleting rows from each table individually is 'better'. If the end
result is the same (i.e. all related rows removed/altered) then why is
it better not to let the engine do it automatically?
I don't deny there are cases when cycles could occur and other case
when the engine is not clever enough to deduce there are no cycles but
for simple cases why not trust the engine?
An analogy here is autonumber generation: sure, there are cases when a
custom order is required but when an incrementing integer is good
enough why bother rolling your own?
I suspect it's not the case that you don't trust the engine, rather
it's simply the case that you've never considered trying it.
Jamie.
--