[thelist] SQL query statement help

Belinda Johnson belinda at prodsol.net
Mon Dec 9 19:03:06 CST 2002

OMG reading that made my brain hurt... :)

Just when I think I'm getting smart - y'all make me feel so dumb!!!



Subject: Re: [thelist] SQL query statement help

nice design, chris, very nice examples

one wee point (and i admit it's more style than substance)

in the item table, you have

> -> item_type_id (foreign key from item_types)

instead of from, i prefer to say to

it's a foreign key to the item_types table

what you intended was, and i'm guessing, is that the values in this column
in the item table are values that originated in the primary key in the
item_type table, and that would be correct

in practice, this is borne out by the need to create the primary key in the
item_type table first, after which it can be used in foreign keys

to me, the key question for each item is "which item type is this item?"

the answer is "that one over there"

in other words, the foreign key points to the primary key

this is reinforced by the syntax FOREIGN KEY foo REFERENCES bar

this in turn reminds you (well, it does me, anyway) that you can have
multiple foreign keys pointing to the same primary key

multiple iteme can reference the same item_type

the foreign key is in the child, and points to the parent


More information about the thelist mailing list