Jump to content

Recommended Posts

Im just curious as what the best approach to take in designing a database is with foreign keys. If i have a menu table and a submenu table and a submenu belongs to a menu then i presume submenu would reference the menu table. But what happens when i want to delete an item in the submenu table? i would have to delete from the menu table first? is it best to not decalre a relationship at all? or to just not allow deletion? also when is it best to use foreign keys when there will be trouble deleting records?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/194118-databse-froeign-keys-design-help/
Share on other sites

Im just curious as what the best approach to take in designing a database is with foreign keys. If i have a menu table and a submenu table and a submenu belongs to a menu then i presume submenu would reference the menu table. But what happens when i want to delete an item in the submenu table? i would have to delete from the menu table first? is it best to not decalre a relationship at all? or to just not allow deletion? also when is it best to use foreign keys when there will be trouble deleting records?

 

thanks

 

Why would an item in the submenu table even be in the main menu table?

  • 2 weeks later...

what is the difference between a menu and a submenu, in terms of the data required to be saved?

 

Generally speaking you should just have one table menu, and account for relationships in the that one table.

So you could have 'parent_id', and if the menu is a 'submenu' it's parent_id would be the 'id' of the menu item that it relates to.

 

If you delete a child you don't need to delete the parent, the children are independently saved and removed from their parents.

 

For menus, I find using a tree structure to be the most effective in my processes and the life cycle of the applications.

 

Good luck.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.