I want to discuss a problem I have with my database design becourse I
feel I cannot decide wheather I am on the right way of doing things.
First of all, I am writing a literature and magazine database with web
(PHP) and C++ Interface, serving over the web and in a very fast LAN.
So my concern is about performance (and aestaetic by doing the things
as optimal as possible.) This is my first database at all, but I have
read a lot of books about it and I am a reasonable good C++ programmer.
So here is my problem...
I have table A and B and a linking table. I want to delete the linking
tables record, this should additionally delete a record in table A.
This can't be done with foreign key constraint, since the linking
tables record has the foreign key of table A, not the primary key.
Then table A depends on table B, and here is the same problem, table A
has the foreign key of table B, not the primary key.
and so on.
Actually I have several complex cases which have to do with automatic
deletion of tables with some tables involved, for example:
When you delete a magazine, you delete a corresponding e-mail from the
publisher, but only when this e-mail is not referenced anymore by other
tables, for example books , data storage disks, cds or the like.
So what I did was the following:
Delete linking table's record, this fires a trigger that deletes a
record in table A. Deletion in table A fires a trigger which checks if
table A's record references table B and is is allowed to be deleted. If
not, I RETURN NULL, if yes, I deletion is allowed to take place.
What do you think? Would it be better to have the trigger in the
linking table to check if it can safely delete record in A by checking
table B? Would that be a real performance gain?
Or are there ways of doing things, which I havn't thought about?
Thank you for thoughts on this subject.
pgsql-general by date
|Next:||From: John Sidney-Woollett||Date: 2004-07-28 09:49:37|
|Subject: Re: Data model for Postfix v2|
|Previous:||From: Lincoln Yeoh||Date: 2004-07-28 09:23:16|
|Subject: Re: Sql injection attacks |