Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Dynamically add the primary key to related tables in Access

Posted on 2014-03-21
Medium Priority
Last Modified: 2014-03-24
Hui Experts,

I have about 6-8 tables in an Access 2010 database that relate to the same primary key.  Let's just say that all the tables relate to suppliers and SupplierID is the primary key in all the tables.

When I add a new record to the master table (ie add a new supplier to the Supplier List) I also want the ID to be added in all the other related tables and queries.

How do I do this and what's it called?  Does this have anything to do with "cascade updating".  Also, if I want to add a new table based on the list of all existing SupplierID numbers, do I have to export and re-import as a new table?

I know this is a rookie question.  Thanks for your help.

Question by:thutchinson
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 39

Expert Comment

ID: 39945794
The short answer is that's not how relational databases work.

It is the "foreign key" (primary key of tblA stored in tblB as a pointer back to tblA) that links all the data.  There is no way to know what rows of tblB should contain a new value added to tblA.

I think you are experiencing a problem with queries that is caused by using the wrong type of join.  The default join type is INNER.  That means you are requesting all rows of tblA that have matching rows in tblB.  So, what happens for example if you join Customers to Orders and a Customer has not yet placed an Order?  The recordset will not contain any rows for the new Customer.  If you wanted to see all customers whether or not they had placed an order, you would use a LEFT join.  The left join says - give me all rows in tblA and also any matching rows in tblB.  So, the columns from tblB would exist but be null for any tblA rows without a tblB record.  The third join type is RIGHT and is the same as LEFT but from the other direction.  When you create a query using the QBE and draw the join line, Access pops up a dialog with three options.  Read them carefully and choose the option that will produce the results you are looking for.

If you have defined relationships in the BE by using the Relationships window, Access will automatically draw join lines when you create new queries using QBE but it will use the default join type of INNER so you will have to double click on the join line to change the join type or switch to SQL View and change it by typing.  If you think that the majority of your joins would be LEFT or RIGHT rather than INNER, you can specify a default join type in the Relationship window and when Access automatically creates new joins for you, it will use this default to specify the join type.

Author Comment

ID: 39946380
Yes, I understand how the joins and the relationships work.  I did not express my question well.  I'm so sorry.   Thanks for the thoughtful response.

I need to think about what I'm trying to accomplish here and restate the question.  I will close this an award the points by Monday if I decide to abandon this question.
LVL 39

Expert Comment

ID: 39946501
I forgot to answer the last question.
Also, if I want to add a new table based on the list of all existing SupplierID numbers, do I have to export and re-import as a new table?
Again, this is not how relational databases work.  Select queries and tables are interchangeable for most purposes.  Use queries with selection criteria to isolate subsets of data.  Do not create new tables.  When you create new tables, you will also have to create new forms and queries.

It sounds like you have several 1-1 relationships.  Although there is nothing wrong with that per se, it is unusual so make sure you have created them for the right reasons.  Most people resort to 1-1 relationships because they have too many columns to fit into a single table.  This is a symptom of having one or more repeating groups and the schema should be normalized to remove them.

Have a great weekend.

Author Comment

ID: 39950402
Yes, I have 4 tables with the same primary key (SupplierID) in one-to-one relationships.  Whenever I found that I needed to collect a new type of data, I started a new table.

You are saying that I should have one mega table with many columns.  It makes sense as long as I can remember what I'm storing in all those columns.
LVL 39

Accepted Solution

PatHartman earned 2000 total points
ID: 39950759
One table is easier to work with so unless you need to split off the columns for some particular reason, leave them all together.  Here are some reasons to split.
1. Security - some data is more sensitive than other
2. Sparseness - some data occurs only rarely and so to avoid lots of empty rows, you can put those columns in a separate table.  Since null columns take up only enough room to hold the record lengh field, there is really no technical advantage to this.
3. Some large data fields are used rarely so you want to keep them out of normal processing.

If you have "lots" of columns and keep adding more, be very certain that you are not adding repeating groups.  Those need to go into "many-side" tables.

The Left Join I suggested earlier will solve the problem of working with sparse 1-1 relationships.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

596 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question