Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Table Database Advice

Table Database Advice

Scheduled Pinned Locked Moved Database
databasequestion
8 Posts 5 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JackMisani
    wrote on last edited by
    #1

    Hello everybody, i'm writing to ask an advice. In my Access db, I've many tables but the most important table is named "Products". The Primary Key for this table is the "Product Code". For every product I've to save different fields. Some fields are descriptives fields that rarely change while other fields are prices fields that change different times per day. Which is the best way to represent a product? I have these 3 ideas: 1) TABLE1 where I insert only descriptives fields and has the product code as primary key. TABLE2, where i save only prices, that has a relation one to one with the first table and share the primary key with it. 2) TABLE1 where I insert descriptives fields and an integer field at the end which is in relation with TABLE2 where I save prices. In this case the primary key of table2 will be an identity field. Also in this case it will be a one to one relation. I'm sceptic for this solution because I always add and remove products from table1 so, after 1 year it will be possible that I will have 10.000 product in my database but the primary key of TABLE2 will be a very big number like 50.000. 3) Only TABLE1 where I save every fields both desctiptives and prices fields. Which is the best solution in your opinion? In this moment i've adopted the first solution... Thank Giacomo

    Richard DeemingR L J 3 Replies Last reply
    0
    • J JackMisani

      Hello everybody, i'm writing to ask an advice. In my Access db, I've many tables but the most important table is named "Products". The Primary Key for this table is the "Product Code". For every product I've to save different fields. Some fields are descriptives fields that rarely change while other fields are prices fields that change different times per day. Which is the best way to represent a product? I have these 3 ideas: 1) TABLE1 where I insert only descriptives fields and has the product code as primary key. TABLE2, where i save only prices, that has a relation one to one with the first table and share the primary key with it. 2) TABLE1 where I insert descriptives fields and an integer field at the end which is in relation with TABLE2 where I save prices. In this case the primary key of table2 will be an identity field. Also in this case it will be a one to one relation. I'm sceptic for this solution because I always add and remove products from table1 so, after 1 year it will be possible that I will have 10.000 product in my database but the primary key of TABLE2 will be a very big number like 50.000. 3) Only TABLE1 where I save every fields both desctiptives and prices fields. Which is the best solution in your opinion? In this moment i've adopted the first solution... Thank Giacomo

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      It depends. If a product can only ever have a single price, with no price-breaks, no customer-specific prices, etc., then store that price in the products table. If you need a more complicated pricing structure, then store the prices in a separate table, with a one-to-many relationship between products and prices. For example:

      Prices:
      ID (PK, Identity)
      ProductCode (FK to products)
      FromDate (optional)
      ToDate (optional)
      MinimumQuantity (optional)
      MaximumQuantity (optional)
      CustomerPriceGroup (optional)
      Price


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      J 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        It depends. If a product can only ever have a single price, with no price-breaks, no customer-specific prices, etc., then store that price in the products table. If you need a more complicated pricing structure, then store the prices in a separate table, with a one-to-many relationship between products and prices. For example:

        Prices:
        ID (PK, Identity)
        ProductCode (FK to products)
        FromDate (optional)
        ToDate (optional)
        MinimumQuantity (optional)
        MaximumQuantity (optional)
        CustomerPriceGroup (optional)
        Price


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        J Offline
        J Offline
        JackMisani
        wrote on last edited by
        #3

        Thank you very much Richard....I think i will use your solution that is similar to my idea number 2 because, i forgot to explain, I will have to store different prices for every products....

        M 1 Reply Last reply
        0
        • J JackMisani

          Hello everybody, i'm writing to ask an advice. In my Access db, I've many tables but the most important table is named "Products". The Primary Key for this table is the "Product Code". For every product I've to save different fields. Some fields are descriptives fields that rarely change while other fields are prices fields that change different times per day. Which is the best way to represent a product? I have these 3 ideas: 1) TABLE1 where I insert only descriptives fields and has the product code as primary key. TABLE2, where i save only prices, that has a relation one to one with the first table and share the primary key with it. 2) TABLE1 where I insert descriptives fields and an integer field at the end which is in relation with TABLE2 where I save prices. In this case the primary key of table2 will be an identity field. Also in this case it will be a one to one relation. I'm sceptic for this solution because I always add and remove products from table1 so, after 1 year it will be possible that I will have 10.000 product in my database but the primary key of TABLE2 will be a very big number like 50.000. 3) Only TABLE1 where I save every fields both desctiptives and prices fields. Which is the best solution in your opinion? In this moment i've adopted the first solution... Thank Giacomo

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          JackMisani wrote:

          Which is the best solution in your opinion?

          A normalized model. Rules for normalization can be found on the wiki :thumbsup:

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          • J JackMisani

            Thank you very much Richard....I think i will use your solution that is similar to my idea number 2 because, i forgot to explain, I will have to store different prices for every products....

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            If the ProduceCode is user editable then it should never be used as a foreign or primary key, use the ProductID an identity field.

            Never underestimate the power of human stupidity RAH

            J 1 Reply Last reply
            0
            • J JackMisani

              Hello everybody, i'm writing to ask an advice. In my Access db, I've many tables but the most important table is named "Products". The Primary Key for this table is the "Product Code". For every product I've to save different fields. Some fields are descriptives fields that rarely change while other fields are prices fields that change different times per day. Which is the best way to represent a product? I have these 3 ideas: 1) TABLE1 where I insert only descriptives fields and has the product code as primary key. TABLE2, where i save only prices, that has a relation one to one with the first table and share the primary key with it. 2) TABLE1 where I insert descriptives fields and an integer field at the end which is in relation with TABLE2 where I save prices. In this case the primary key of table2 will be an identity field. Also in this case it will be a one to one relation. I'm sceptic for this solution because I always add and remove products from table1 so, after 1 year it will be possible that I will have 10.000 product in my database but the primary key of TABLE2 will be a very big number like 50.000. 3) Only TABLE1 where I save every fields both desctiptives and prices fields. Which is the best solution in your opinion? In this moment i've adopted the first solution... Thank Giacomo

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #6

              JackMisani wrote:

              that rarely change while other fields are prices fields that change different times per day.

              What happens if someone wants to return something that they bought yesterday? If they order it online two weeks ago and it ships today what price are they charged?

              J 1 Reply Last reply
              0
              • M Mycroft Holmes

                If the ProduceCode is user editable then it should never be used as a foreign or primary key, use the ProductID an identity field.

                Never underestimate the power of human stupidity RAH

                J Offline
                J Offline
                JackMisani
                wrote on last edited by
                #7

                When I'll insert a product I'll also insert the ProductCode but then I never won't be able to modify it. I'll only be able to remove the product

                1 Reply Last reply
                0
                • J jschell

                  JackMisani wrote:

                  that rarely change while other fields are prices fields that change different times per day.

                  What happens if someone wants to return something that they bought yesterday? If they order it online two weeks ago and it ships today what price are they charged?

                  J Offline
                  J Offline
                  JackMisani
                  wrote on last edited by
                  #8

                  My products will be only stocks. Every stocks has always a trading code that i'll use as PK. For every stocks i need to store 2 kinds of fields: 1) Descriptive fields that changes rarely like: description, isin code, country, expiration 2) Prices fields like: last price, minimun, maximum When I launch my app i will load my db data in my memory and i'll start to download prices from servers. I'll do calculation between the prices i've in memory and the price I receive from server and only when i'll click "Save" button i'll write data in my db....-

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups