Access 2002 - Many to Many Relationships

  • Thread starter Thread starter Lynn
  • Start date Start date
L

Lynn

I am new to Access and I have done a considerable amount
of reading and research. I need assistance to understand
and confirm that I am setting up a database correctly
that has many to many relationships. The database that I
am creating has a number of tables connecting at the end
to develop information to be used in four (4) different
forms.

The main tables are Customers, Quotes and Jobs. There
can be many Customers with many Quotes and many Jobs. I
have inserted combination tables for Customers and Quotes
and a second one for Customer Jobs. The Quotes table is
linked to the Quotes details and the Jobs table is linked
to the Job details table.

I understand the importance of ensuring your table
structure is correct before designing forms and reports.

I would really appreciate any assistance people could
provide to assist me in ensuring I have the tables set up
correctly to go onto the next steop.

Thank you in advance.
 
The main tables are Customers, Quotes and Jobs. There
can be many Customers with many Quotes and many Jobs.

Actually, to talk about relationships, the above is not correct.

You have "A" customer, and that customer can have many quotes.

So, this is One customer can have many quotes.

You can say that many customers have many quotes..but then who do the quotes
belong to?

So, the correct term is One customer can have many quotes.

The next question is can a customer have a Jobs, or do Jobs belong to
Quotes?

You see again, how working from table you are talking about is very
important.

Do you want to attach a Job to a quote, or to a customer?

Either we have:

One customer can have many Jobs. This means we don't care about he quotes
table here.

Or, do you have

Customer can have many Quotes. And, each SINGLE quote can have MANY jobs?

Hence, we have

Customer->Quotes
->Jobs

or

Customer->Quotes->Jobs

Your design is going to depend if you need jobs attached to a Quote (if you
do, then of course you use the 2nd example).


So far, in your explain of what you want, we are talking about standard one
to many relationships. Hence, always think of "ONE" record in a table, and
that generally allows you figure things out. I should also note that you
can't actually build a many to many relationships. The database ONLY allows
one to many relations. However, if you think about this, many customers can
have many jobs, but as you see, in database design, we always use one to
one, or one to many relationships (the end results is certainly a customer
can have many jobs).
 
Thank you aLbert for your feedback. You are correct
about their only being one customer but my problem is
that the customer may receive a quote or many quotes but
not necessarily go into a job or there may be a job
without the quote. I have tried to set up the tables to
be able to draw from the information to use in the forms
we currently use. I need a quote form, an invoice, job
assignment, extra work form with details, packing slip.
I want to be sure that the Customer information is
available for all Quotes and all Jobs with specific
information in the details area.

I hope this helps. Can you please explain to me exactly
how the
linking tables work with the combined primary codes.
Should they have a special name. I think I have them
linked together correctly as one primary key:

The information that shows under the Indexes is:

Line1(Index Name) Customer ID (Field Name) Customer ID
Line2(Index Name) Primary Key (Field Name) Quote ID
Line3 (Index Name) Blank Space (Field Name) Customer ID
Line4 (Index Name) Customer ID (Field Name) Quote ID

Just one more thing for clarification at this time. How
does the linking table affect forms that I will be making
up with Quotes and Jobs. What do I use as the Primary
Key from the linking table? Should this Combined Prinary
Key have a special name? I am not sure about what will
happen to this link for the next step.

I apologize for being ignorant about the workings of
Access but I think the best way to learn is having
something to apply it too.

Thank you so much for your assistance.

Lynn
 
Thank you aLbert for your feedback. You are correct
about their only being one customer but my problem is
that the customer may receive a quote or many quotes but
not necessarily go into a job or there may be a job
without the quote.

The above tells me that a customer can have a quote. Do you need, or want to
attach jobs to a quote?

If 99% of jobs have to be attached to a quote, then obvsilty for those RARE
exctips, you would create a quote, and not fill much of it out,and then
simply attach the job to the not very usefaull quote part. But, who cares
for these rare exctipns. (and, only you know the answer to this qutstion). A
big part of data modeling is to attempt to come up with a desing that
models the problem at hand. And, since we don't have un-limnited programmer
resouces here, then often a compromose needs to be made. So, while some jobs
don't need a quote..do most? If you say 50/50, then lots of quotes will be
made, and lots of jobs can be made, and thus the desing should reflect this
relaidty.

Lets assume that the answer is 50/50 (jobs often belong to a quote, but
often they don't). that means we would choose:


Customer ->Quotes
->jobs

Thus, we need 3 tables, but quotes and jobs relatte back to customer. We
also would of couse put in the jobs reocrd what Quote the job belongs to IF
a quote is needed.
I hope this helps. Can you please explain to me exactly
how the
linking tables work with the combined primary codes.
Should they have a special name. I think I have them
linked together correctly as one primary key:

I have always used the defalut for primary key id's. In this case, your
customer table likey has a ID field called ID.
Line1(Index Name) Customer ID (Field Name) Customer ID

Ah, ok..you used Customer ID. I find spaces in field namesx shold be
advoied..they are a souce of pain, and problems.
up with Quotes and Jobs. What do I use as the Primary
Key from the linking table?

Each child table (the many side) simply need to have a field added that
tells us what Customer Reocrd id it belongs to. So, in each chidl table you
use a REGULAR long integer field. (it is likey important to note that
relatosions in child tables are simply reuglar field, and are not autonumber
filds, nor are then primary key field, nor are they speical fields. The
fields used to build relatonations in these child ables are simply regular
long integer fields. We often call these regular plain jane fields Forigher
keys.
Should this Combined Prinary
Key have a special name?

Huh? When did we start talking about combined primary keys. What do we need
them for?

You got a table called jobs. If you need to relate this table back to
Customer, then we simply add a reagular field to the jobs table. A good
field name would be Customer_Id. Note that our jobs table does not actaully
need a primary key. (you can certanly create a primary key field in the jobs
table, but we don't need it..do we?). Also, since we cna have a LOT of
tables, then you might as well standarzie your naming,a nd make all primary
key fields have the simple name of ID. For those simply plain fields that
are used in relatons, then you can use

tableName_ID

Anyway, you already made some tables...so don't worry about what you used
for your primary key fields (but, these fields are going to autonumber
fields).

You also statned that you would like sometimes to relate the jobs to a quote
(but not always). Ok, then simply add another field to the jobs table, and
that field is going to be a regular long integer field that relatts to the
quotes table. We can call tha tfiedl

Quotes_id

I am not sure about what will
happen to this link for the next step.

it turns out, that linking MUST be done by you! In other words, after
setting up all this way cool relatonship stuff, YOU STILL have to entry the
valeus into the fields used for linking to a parent table (note how I said
linking to a parent table, as you do not link the other way! (but you can,
and do think conceptilay that the link is from the parent to the child
table....yes, this is true..but the actual field used in the link is in the
child table (our so called forightn key)).

So, you can open up a form, and add anew customer. While adding the
customer, you can make note, and write down the CustomerID. You can then
open up the Quotes table, and enter in the quotes information, and to link
this quote to a particular customer, YOU HAVE to enter the customerID into a
field. Of course, as you become a better developer, then you would make the
application set the customerID, but I do want to stress that it is YOU who
has to enter this number into the table to make it relate back into the
customer table.

And, if you make quotes a sub-form, then ms-access *CAN* enter the
customerId into the quotes "customer_id" field for you (you still have to
set what field you used).

When you add a new job, then you HAVE to enter the Customer_Id field, but
the Quotes_id field is of course optional....
 
Back
Top