Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 12

TABLE RELATIONSHIP

http://etutorials.org/SQL/Database+design+for+mere+mortals/
Part+II+The+Design+Process/
Chapter+10.+Table+Relationships/Types+of+Relationships/
A relationship in Access helps you combine data from two different
tables.
Each relationship consists of fields in two tables with corresponding
data. For example, you might have a ProductID field in a Products table
and in an OrderDetails table.
HOW TO CREATE TABLE
RELATIONSHIP

1. Click the Relationships command in the Show/Hide group on the Database Tools tab in


the Ribbon.
NOTE: Tables must be closed in order to establish relationships.
2. When the Show Table dialog box appears:Select each table name, then click Add for the
tables you want to relate.
3.When you're done, close the Show Table dialog box.
4. You should now see a relationship map that contains all of the tables that were selected.
Enforce Referential Integrity
 When you create a relationship between two tables, it is usually a good idea to enforce
referential integrity. Referential integrity keeps data accurate and ensures that you don't
accidentally change or delete related data in one table but not in the other.
Cascade Update Related Fields
 When you enforce referential integrity and choose the Cascade Update Related Fields
option, and you then update a primary key, Access automatically updates all fields that
reference the primary key.
 Cascade Delete Related Records
When we create a foreign key using this option, it deletes the referencing rows in the child
table when the referenced row is deleted in the parent table which has a primary key.
MOVE A TABLE THAT APPEARS IN
THE RELATIONSHIP MAP:
Move a table that appears in the relationship map:
1. Place your mouse over the table you want to move.
2. Hold down the left mouse button, then drag the table to a new location.
3. Release the mouse button to drop the table in its new place.
UNDERSTANDING THE RELATIONSHIP MAP

The relationship map lists all of the tables that were selected to relate, as well as all of the
fields that were previously set up for that table. Notice that the first field has a key icon next
to it. This is the primary key for the table.
WHAT IS A PRIMARY KEY
 A primary key is the first field in each table of the database.
 This field auto-numbers by default, so every record in the table has its own unique number
to identify it. Access uses this number to quickly pull information together when you run
queries or reports.
 For example above, the primary key for the Customers table is Customer ID, the primary
key for the Orders table is Order ID, and the primary key for the Books table is Book ID.
UNDERSTANDING THE RELATIONSHIP MAP

A foreign key is a field that is the primary field in its own table but that shows up in another
table. If you look closely at the Orders table, the fields Customer ID and Book ID appear
there, as well as in their own respective tables. These fields are the primary key in their own
tables, but in the Orders table, they are considered foreign keys.
TYPES OF RELATIONSHIPS
One to One -A pair of tables bears a one-to-one relationship when a single record in the first
table is related to only one record in the second table, and a single record in the second table is
related to only one record in the first table.
TYPES OF RELATIONSHIPS
One to One -A pair of tables bears a one-to-one relationship when a single record in the first
table is related to only one record in the second table, and a single record in the second table is
related to only one record in the first table.
One-to-Many Relationships - A one-to-many relationship exists between a pair of tables when
a single record in the first table can be related to one or more records in the second table, but a
single record in the second table can be related to only one record in the first table.
Many-to-Many Relationships - A pair of tables bears a many-to-many relationship when a
single record in the first table can be related to one or more records in the second table and a
single record in the second table can be related to one or more records in the first table.

You might also like