[thelist] Nested Queries
rudy
r937 at interlog.com
Wed Aug 21 13:11:01 CDT 2002
> Or am I missing something?
possibly
a parent-child or one-to-many relationship has the foreign key in the child
create table treetable
( id integer primary key
, name varchar(20) not null
, parent_id integer null
references (treetable)
)
this structure not only allows the database to enforce relation integrity,
it makes for simpler queries
if you store child keys in the parent record, you essentially need one
parent-to-child row for each instance of the relationship, and then you
must either set the parent name to null or make it redundant -- an
ungainly, inlikeable structure either way
while database enforced relational integrity is possible(*) with the parent
record containing the child key, you still have twice as many rows in the
table as you really need, and twice as much traffic for inserts and deletes
(*) cascading deletes would work -- just backwards from what you'd expect!!
rudy
More information about the thelist
mailing list