bulgaria_mitko Posted December 17, 2006 Share Posted December 17, 2006 I have created a database with 2 tables one with Products->ProductID and Products->TypeID and the other with ProductsType->TypeID and i want to related them so when i delete a ProductType it will NOT delete all the Products related to that ProductType. How have to set the ON DELETE and ON UPDATE in order to do this and also how to u set them when u delete a ProductType to delete all the Products related to that ProductType? Thank you very much! ??? Quote Link to comment Share on other sites More sharing options...
btherl Posted December 18, 2006 Share Posted December 18, 2006 The default is NOT to delete related data.If you are finding that related data is deleted automatically, then it is due to something you have added to the table definitions. It could be related to foreign keys. There is no requirement to specify foreign keys. Quote Link to comment Share on other sites More sharing options...
bulgaria_mitko Posted December 18, 2006 Author Share Posted December 18, 2006 oh yeah and the most important question what is foreign key? i know already what is primery key, but foreign key? ??? Quote Link to comment Share on other sites More sharing options...
artacus Posted December 18, 2006 Share Posted December 18, 2006 A foriegn key is the primary key of a related table.So if you have a products table:product_id <- primary keycategory_id <- foreign key in this table/ primary key of the categories table Quote Link to comment Share on other sites More sharing options...
minderella Posted December 18, 2006 Share Posted December 18, 2006 There are several rules you have to abide by if you plan on using foreign keys. From what I know, InnoDB is the only engine that can implement foreign keys. I strongly suggest that you read the MySQL manual regarding the construction of InnoDB databases. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.