On 1 May 2010 11:00, Karl DeSaulniers <k...@designdrumm.com> 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> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php