CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2011
    Posts
    59

    many to many tables

    Hi,

    i need some help creating my tables.
    I´m writing a cookbook.
    for now i have 4 tables.

    First table: Recipetable

    Columns:
    RecipeID, int, primary key
    Name
    Price
    Time
    Description

    second table: Ingredients table

    Columns:
    ID, int, primary key,
    REF_RecipeID (FK on Recipe ID in Recipetable)
    IngredientName
    Amount
    type of amount

    third table: Categorys table

    Columns:
    ID, int, primary key,
    REF_Recipe_ID (FK on Recipe ID on Recipetable)
    CategoryName

    fourth table: Images table

    Columns:
    ID, int, primary key,
    REF_Recipe_ID (FK on Recipe ID on Recipetable)
    ImagePath
    ImageData

    One Recipe can have one Image, Name, Price, Time and description.
    One recipe has many ingredients(with their amount and type of amount).
    One Recipe has 1-4 categorys.

    How do i build my tables correctly?
    Or is it correct?
    i can display ONE recipe with everything that belongs to it (image, ingredients, categorys) by selecting an ID from the Name table and in the statement selecting everything from the other tables where the ID is the same.

    but i have one form on which i want to display ALL recipes i have with their ingredients, categorys and pictures in a datagridview.
    how do i have to write my select statement?
    i´m totally lost here When i select it right now with my tables the way they are, i get the recipe with every combination of ingredients and categorys possible..

    attached my tables so far and my output so far.. you´ll see my problem..
    i´m grateful for any help.
    regards,

    Lisa
    Attached Images Attached Images   

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: many to many tables

    is it correct?
    The definition looks correct to me for your tables of recipes, images and ingredients.
    I have a doubt about the definition of your table of categories because I don't know very well what you mean by "categories". In my mind, I though that a reciped belonged to some categories instead of a recipe having some categories, therefore I was exepecting a Ref_KategorieID in the RezeptTabelle and no REF_RezeptID in Kategorien. But, maybe you are right.

  3. #3
    Join Date
    Jan 2011
    Posts
    59

    Re: many to many tables

    a recipe can have many categories.
    e.g.
    mexican, vegetarian, supper
    or
    french, with meat, snack

    like that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured