Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Powermac is offline Novice
    Windows 7 64bit Office 365
    Join Date
    Oct 2020
    Posts
    5

    Simple Table Design Basics - Extra Column or Rows ?

    Hi all,



    I have a very basic question regarding the design of a simple table (just using Access very pragmatically and no advanced Access user or database expert).

    Having different cost categories (accounts) with monthly values for different locations: Should I create an additonal column for the cost values for each account (picture A) or create a seperate row for each value with the account ID in one column and the cost value in another (picture B).

    A:
    Click image for larger version. 

Name:	V1.JPG 
Views:	59 
Size:	35.3 KB 
ID:	43145

    B:
    Click image for larger version. 

Name:	V2.JPG 
Views:	60 
Size:	61.0 KB 
ID:	43146

    Many thanks ahead!

    Best regards

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,538
    IMHO table B would be best. Table A looks like a spreadsheet design and that always leads to problems in Access. Long, narrow tables are better than wide shallow tables. The need for repeating field names that are then numbered (Account1,Accouont2 etc) are an indication that the data is not Normalized and that another table is required for the data.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Another vote for B if you were wanting other opinions. What are you going to do when they add account 5? With A you have to add a field to the table and modify every query/form/report accordingly. With B, all you do is add a record to the "accounts" table and you're done. Actually the users would probably do that via a form you give them to manage accounts. Adding a new product/account/whatever should not require design changes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    B for the same reasons as above. Suggest you read about normalisation of data
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Powermac is offline Novice
    Windows 7 64bit Office 365
    Join Date
    Oct 2020
    Posts
    5
    Hi all three,

    thanks a lot for your support! All very helpful for me! Your comments made it much clearer now.

    I read about normalisation of data but for some reason I was not sure in this case.

    Thanks!

  6. #6
    Powermac is offline Novice
    Windows 7 64bit Office 365
    Join Date
    Oct 2020
    Posts
    5
    I would like to raise one additional question that came into my mind regarding a similar cost table where I have an order ID and several (19) types of costs for each order. When applying the same logic (B) here, I get many many lines. As I have to mention the order ID and the cost element ID in each row again, the database gets much bigger compared to the spreadsheet-like scheme (A).

    Should I create the table still as on picture below?

    Click image for larger version. 

Name:	New Example.JPG 
Views:	35 
Size:	28.0 KB 
ID:	43218

    Regarding normalisation: Would a table in spreadsheet-like design A (with a column for each cost element) violate normalisation?

    Thanks again!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    In my view, yes and definitely yes. As Bob mentioned:

    Quote Originally Posted by Bob Fitz View Post
    Long, narrow tables are better than wide shallow tables.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    Would a table in spreadsheet-like design A (with a column for each cost element) violate normalisation?
    definitely

    the database gets much bigger compared to the spreadsheet-like scheme (A)
    size should not come into it. What matters is good database design. Applying excel principles (which combine storage with presentation) is not the way databases work. tables store data whilst queries, forms and reports present data. Go down the excel route and you will quickly run into trouble.

    Besides, your table B does not require a record for location 1, account 1, period 05/2020. Your picture in post #6 has 6 rows which are not required.

    Also, none of your tables have a primary key.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Another vote for B. Maybe event split to two tables. Depends how much repetition want to eliminate.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Powermac is offline Novice
    Windows 7 64bit Office 365
    Join Date
    Oct 2020
    Posts
    5
    Quote Originally Posted by pbaldy
    In my view, yes and definitely yes.
    Thanks!


    Quote Originally Posted by Ajax View Post
    definitely

    size should not come into it. What matters is good database design. Applying excel principles (which combine storage with presentation) is not the way databases work. tables store data whilst queries, forms and reports present data. Go down the excel route and you will quickly run into trouble.

    Besides, your table B does not require a record for location 1, account 1, period 05/2020. Your picture in post #6 has 6 rows which are not required.

    Also, none of your tables have a primary key.
    Thanks! Very helpful comments.
    Yes and actually lots of the orders don't have values for all of the elements, so all these could be eliminated. Understood.
    Is a primary key always required or recommended if each record is uniquely identified by the combination of foreign keys? Each combination cannot exist more than once.


    Quote Originally Posted by June7
    Another vote for B. Maybe event split to two tables. Depends how much repetition want to eliminate.
    Thanks! Do you mean the first example or the second? In the second, I cannot see how it could make sense to split into two tables. Rather in the first.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2016
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Powermac,

    I recommend you work through 1 or 2 of the tutorials from RogersAccessLibrary in which he describes a business and leads you through a procedure to identify tables and relationships. The tutorials come with a problem statement/narrative, process steps and a solution. Each tutorial will take about 45 to 60 minutes to complete. But you will learn about and experience Normalization and what you learn can be used with any database. You have to work through the tutorial(s) to gain the experience.

    Tutorials from RogersAccessLibrary

    ZYX Laboratories
    Class info system
    Catering Business
    Widgets

    Good luck.

  12. #12
    Powermac is offline Novice
    Windows 7 64bit Office 365
    Join Date
    Oct 2020
    Posts
    5
    Thanks orange for the tip with the tutorials. I'm going to follow your recommendation and work through it!

  13. #13
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    Is a primary key always required or recommended if each record is uniquely identified by the combination of foreign keys? Each combination cannot exist more than once.
    you can use a composite index as a primary key but it becomes unwieldy. Personally, I wouldn't.

    If the requirement is that each combination is unique, you can still have a composite index set to no duplicates

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Two tables could be like:

    tblEvents (or whatever in place of Event)
    EventID_PK
    LocationID
    Period
    EnterBy
    etc

    tblEventDetails
    EventID_FK
    AccountID_FK
    Amount

    Use form/subform arrangement for data entry/edit.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I am in agreement with Ajax.


    Quote Originally Posted by Powermac View Post
    ...Is a primary key always required or recommended if each record is uniquely identified by the combination of foreign keys? Each combination cannot exist more than once.
    I tried using a composite primary key in my early days of Access development... a real PITA.

    Lets say you have a customer table with a composite PK of FirstName, MI, LastName and Address1. You add two tables that should be linked to the customers table. To create the link,you have to add the composite PK fields from customers to each of the tables - that is 3 extra fields per table to create the foreign keys. Any operation where you need to use the PK requires those 4 fields.

    I have an autonumber in every table as the PK field. I know (have been told ) that it is overkill, but I have a unique identifier in every table, even if I don't use it. If I end up needing to use it, it is there.
    IMO, the design is cleaner/easier and queries are easier to create. If I need to have a unique combination of 2 or more field that cannot exist more than once, I use a compound index and set it to be Unique.

    Again, this is just my style.


    Also see:
    Microsoft Access Tables: Primary Key Tips and Techniques

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 08-23-2019, 05:16 PM
  2. Absolute basics of database design
    By thegrimmerdiscovery in forum Access
    Replies: 3
    Last Post: 04-12-2019, 05:07 AM
  3. Replies: 14
    Last Post: 09-09-2014, 01:30 PM
  4. Database Design basics 4 n00b
    By OTOTO in forum Database Design
    Replies: 7
    Last Post: 07-08-2014, 09:34 AM
  5. Replies: 3
    Last Post: 03-26-2012, 01:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums