Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4581812
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:58:55+00:00 2026-05-21T20:58:55+00:00

I have three table here…. One is menu, and second is drink, and food.

  • 0

I have three table here….
One is menu, and second is drink, and food.

One menu data can only have either one drink or one food.

So, the menu table have something like this….
[id][type][type_fk]

if the menu table type is “D”, it will find the drink table, and use the type_fk, to find the drink… …Here is a more detail example:

id:1,type:D, type_fk:1
id:2,type:F, type_fk:1

in the drink table, we have

id:1, name:coke, unit:ml

in the food table, we have

id:1, name:chicken 

The result why I want to separate two tables is because the drink table have “unit” column, but the food table don’t have this… …So, I will achieve information from user based on the type and the type_fk. So, in the first example, I can get the “coke”, and the second one, I can get the “chicken”.

Please drop your comments on this design.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:58:56+00:00Added an answer on May 21, 2026 at 8:58 pm

    I would suggest that you have a single table instead of 2 tables:

    Menu (Id, ItemId)
    Item (Id, Name, Type, Unit)

    The reason behind that is to enforce referential integrity. Menu.ItemId will be a foreign key that references Item.Id. If you have 2 tables you won’t be able to enforce referential integrity.

    I believe you shouldn’t worry about sparse columns. For example store the Unit of chicken as piece or leave it empty.

    Edit:
    If you want to avoid having a sparse table, a table with some columns not being used, then you might consider something like:

    Menu (Id, ItemId)
    Item (Id, Name)
    ItemProperties (ItemId, Name, Value)
    

    For example

    Item:
    -----
    Id    Name
    1     Chicken
    2     Coke
    
    ItemProperties:
    ---------------
    ItemId    Name    Value
    1         Price   10
    1         Type    Chinese
    2         Price   1
    2         Unit    ml
    2         Size    300
    

    This way you are keeping referential integrity and avoiding sparse tables.

    If you are using SQL Server 2008, check this SQL Server 2008 Sparse Columns

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with three fields, FirstName, LastName and Email. Here's some dummy
Ok, here's the condensed form. I have three main tables to draw data from:
i have a three dimensional bit table array as bit_table[dim1][100][200]; The second and third
Here's some background info. I have three MySQL tables (all InnoDB). The first table
Well here's my problem I have three tables; regions, countries, states. Countries can be
Well guys, I have three tables here, menu, user and access. For simplifying let's
I have these three table to store tags for photo albums. Here is the
i have three tables, i want to select all data from one of the
Rails noob here. I have a rails application with (in this example) three tables.
I have three table I need to query table 1,2 and 3 and select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.