Re: [PHP-DB] grabbing from multiple tables

[email protected] (Karl DeSaulniers)
Newsgroups php.db
Message-ID <[email protected]>
GOLD!
Thank you.

Karl


On May 1, 2010, at 4:12 AM, Peter Lind wrote:

> On 1 May 2010 11:00, Karl DeSaulniers <[email protected]> wrote:
>> Thank you Peter... again.. :)
>> Which would be the source field and which the target field?
>
> You place the constraint on the table that has the foreign key. Using
> your example:
>
> Table 1 = products
> * id = primary key
>
> Table 2 = productoptions
> * product_id = foreign key
>
> On table 2 you would place a constraint like this (in SQL):
> CONSTRAINT FOREIGN KEY (product_id) REFERENCES products (id) ON  
> DELETE CASCADE
>
> This will delete any rows in table 2 if a matching row in table 1 is
> deleted (i.e. if you delete a product, all rows in table 2 matching
> options to products will be deleted as well, if they reference the
> deleted product).
>
> If instead you want to make sure that no product can be deleted while
> it still has options attached, use this:
>
> CONSTRAINT FOREIGN KEY (product_id) REFERENCES products (id) ON  
> DELETE NO ACTION
>
> I don't really know how this translates into your "source" and
> "target" but I would guess source means the primary key on table 1 and
> target means the foreign key on table 2 ... though, thinking about it,
> it would make at least as much sense the other way round. Best see if
> you can find some documentation to translate those terms into
> something SQL-centric
>
> Regards
> Peter
>
> -- 
> <hype>
> WWW: http://plphp.dk / http://plind.dk
> LinkedIn: http://www.linkedin.com/in/plind
> Flickr: http://www.flickr.com/photos/fake51
> BeWelcome: Fake51
> Couchsurfing: Fake51
> </hype>

Karl DeSaulniers
Design Drumm
http://designdrumm.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.