relationships between tables

  • Thread starter Thread starter melinda.pluma
  • Start date Start date
M

melinda.pluma

I have about 5 tables that I cannot enforce referential integrity
on... 3 of them have a common field, but the error messages I am
receiving are way above my head technically. Any suggestions? Or
even documentation on relationships (from the very beginning) would
help a lot!

Thanks
Mindy
 
First suggestion is to post the error messages you are getting.

It could be that you can't enforce referential integrity for a variety of
reasons. To name two off the top.
-- No unique index on field in the table on the one side
-- Fields in many side already have values and there are no related values
in the one side table

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
First suggestion is to post the error messages you are getting.

It could be that you can't enforce referential integrity for a variety of
reasons. To name two off the top.
-- No unique index on field in the table on the one side
-- Fields in many side already have values and there are no related values
in the one side table

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.







- Show quoted text -

"The SQL statement could not be executed ebcause it contains ambiguous
outer joins. To force one of the joins to be performed first, creat a
separate query that performs the first join and then include that
query in you SQL statement."

I have tried that... or what I understand to be these directions. I
created a query, and tried to add it to this query, but I get the same
message... Also, this (the second one) query is not connected to
anything... I'm sure this effects it... but I really don't understand
relationships.
 
Ok, that message is telling you that you need to break the query into
two (or more parts).

Drop one table from the query and see if the query runs. IF it does
Save the query as Part One.

Now Open a new query and add the table you dropped in the first query
AND the query you just saved as sources. Establish your join and run
this query and see if it runs.

It helps if you post the SQL statement of the query that doesn't run.
Sometimes we can figure out the problem from the query (Hint: View: SQL
from the menu).



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
I have about 5 tables that I cannot enforce referential integrity
on... 3 of them have a common field, but the error messages I am
receiving are way above my head technically. Any suggestions? Or
even documentation on relationships (from the very beginning) would
help a lot!

Thanks
Mindy

Mindy,

Referential Integrity is a feature offered by relational databases.

In MS Access, referential integrity (RI) is enforced by a Relationship object.

When you--the database designer--establish a Relationship between two tables, it is
usually done so that you can be sure that values in a column in the first table are the
only values used in a column of the second table, and that values in the second column
cannot exist when there are no matching values in the first column.

From the first table, the most common column to use for a Relationship would be the
Primary Key.

From the second table, the most common column to use for a Relationship would be a column
that was used to store values from a Primary Key column in the first table. This column
is called a Foreign Key (because it is really a key from another "foreign" table).

A Relationship object establishes a hidden index on the column in the second table, and
there must be a Primary Key or Unique Index on the column in the first table.

(This works on multiple columns as well.)


Why does anyone want to establish RI?


If you are a grocery retailer, at the simplest level you probably have an Items table and
a Prices table.

Items
ItemID -- Primary Key
ItemName

Prices
PriceID -- Primary Key
ItemID -- Foreign Key
Price

If you delete and item row from Items, and you have prices for those items in Prices, you
suddenly have a situation where no one can determine what any of those prices were
attached to (the item is gone).

Nobody wants that.

When a Relationship object exists between ItemID in Items and ItemID in Prices, the
database automatically checks to make sure this can't happen. If you try to delete an
ItemID value from Items when there are any of those ItemID values left in Prices, the
query will fail. If you try to insert a row into Prices with and ItemID value that
doesn't already exist in ItemID in Items, that query will fail.

This keeps your database neat and tidy.

You can use CASCASE DELETE and CASCADE UPDATE when setting up a Relationship.

CASCADE DELETE makes it so that if you delete a row in Items, and there are any prices in
Prices for it, the rows in Prices are automatically deleted.

CASCADE UPDATE makes it so that if you change an ItemID value in Items, any occurrences of
that value in Prices are also automatically updated.

There is no such thing as CASCADE INSERT.

----------------

You want to match every Primary Key's Foreign Key (Items.ItemID and Prices.ItemID type
combination) with a Relationship object throughout the database.

----------------

It is possible to establish RI constraints on columns other than Primary Key/Foreign Key
pairs, but it is fairly rare, except for recursive relationships, which are well beyond
the scope of our discussion.

----------------

Based on your further description in the other branch of this topic, I'm not sure that RI
has anything to do with your query's error.

IMO this: "The SQL statement could not be executed ebcause it contains ambiguous
outer joins. To force one of the joins to be performed first, creat a
separate query that performs the first join and then include that
query in you SQL statement."

Usually means that there are column (or table) names in the query that cannot be resolved
(the database can't figure out what they belong to).

This is usually, but not always, the result of one or more missing table qualifiers (like
"Items.ItemID, Prices.ItemID" is fully qualified, but "ItemID, ItemID" isn't.).

More cannot be said (by me) without viewing your SQL. (Open your query in Design View,
then View > SQL View, and then copy and paste post the code.)


Sincerely,

Chris O>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top