+ All Categories
Home > Documents > Table Relationships (Microsoft Access)

Table Relationships (Microsoft Access)

Date post: 14-Apr-2018
Category:
Upload: john-kenneth-leal
View: 219 times
Download: 0 times
Share this document with a friend
26
TABLE RELATIONSHIPS IN  ACCESS 2010
Transcript

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 1/26

TABLE RELATIONSHIPS IN ACCESS 2010

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 2/26

Table Relationship  A Relationship - is how you tell the program that a piece

of information means the same thing in more than one

table. Table relationships can be created between two tables as

long as they have a common field.

Relationships are created using a Primary Key from one

table and linking it to a related field in another table (nowcalled a Foreign Key).

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 3/26

Types of Relationships between Tables

1. One-to-one

Rarely used, a record in the primary table

corresponds to one and only one record in therelated table. (Rare because fields that would go intothe second table are usually just put into the

primary table itself.)

Sample use: some information about a record mustbe confidential; the confidential information is put ina table with a one-to-one relationship to the maintable, and access to the second table is restricted.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 4/26

One-to-one

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 5/26

Types of Relationships between Tables

2. One-to-many

 Very common, one record in the primary table can be

linked to many records in the related table, but eachrecord in the related table can be linked to only onein the primary table.

Examples: A mother can have many children, but

each child has only one mother; a salesman canmake many sales, but any given sale is credited toonly one salesman; a person can have many librarybooks checked out but each book can be checked outby only one person (at a time).

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 6/26

One-to-many

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 7/26

Types of Relationships between Tables

3. Many-to-many

 Very common, when a single record in one table can relate to

many records in another, and a single record in that secondtable can also relate to many records in the first.

Examples: one author can write many books, and one book canhave several authors; one student can take many classes andone class will have many students; one order can contain many

items, and one item can appear in many orders. These relationships are not established directly; they must be

accomplished through a “junction table” like Grades below.)

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 8/26

Many-to-many

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 9/26

Steps in Establishing Relationships

between Tables

1. Create all tables, giving tables that will be relateda common field.

Give the common field the same name in bothtables; make sure it is the same data type.

(Autonumber fields correspond to Number fields

with a field size of Long Integer.)

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 10/26

Steps in Establishing Relationships

between Tables 

2. Click the Database Tools tab to view the DatabaseTools Ribbon. Click the Relationships button in the

Relationships group.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 11/26

Steps in Establishing Relationships

between Tables 3. You will see the Show Tables box listing all available tables. Double-click on the desired tables (or click table then click Add) to put them inthe Relationships window. Arrange the tables by dragging.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 12/26

Steps in Establishing Relationships

between Tables 4. Create the relationship by dragging the common field from onetable on top of the common field in the other table, and droppingit. (Another way to describe this is to say, “Drag the primary key

field and drop it on top of the foreign key field.”) The EditRelationships box will appear.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 13/26

Steps in Establishing Relationships

between Tables 

 Access automatically detects the type of relationship (usually one-to-many). If neither field

allows duplicates a one-to-one relationship will becreated.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 14/26

Steps in Establishing Relationships

between Tables 

5. Click the check box to enforce referential integrity,then click Create to establish the relationship.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 15/26

Steps in Establishing Relationships

between Tables 

6. Click the Close button in the Relationshipsgroup of the Design Ribbon to close theRelationships window.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 16/26

Enforce Referential Integrity Imagine a business database like the one in

the example above.

Many customers (in the Customers table)have placed orders (in the Orders table).

One day an employee accidentally deletes

several records in the Customers table.  Any orders belonging to those customers are

now orphan records .

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 17/26

Enforce Referential Integrity   An orphan record is one that refers to a

nonexistent record in another table, such as

the orders placed by nonexistent customers.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 18/26

Enforce Referential Integrity  The purpose of using referential integrity is to

prevent orphan records and to keep

references synchronized so that you don'thave any records that reference other recordsthat no longer exist.

You enforce referential integrity by enablingit for a table relationship.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 19/26

Enforce Referential Integrity 

Once enforced, Access rejects any operationthat would violate referential integrity for that

table relationship.

 Access rejects updates that change the target of a reference, and also deletions that remove the

target of a reference.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 20/26

 After you have enforced referential

integrity, the following rules apply:

 You cannot enter a value in the foreign key field of arelated table if that value doesn't exist in the primary

key field of the primary table — doing so createsorphan records.

 You cannot delete a record from a primary table if matching records exist in a related table. Forexample, you cannot delete an employee record fromthe Employees table if there are orders assigned tothat employee in the Orders table.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 21/26

 After you have enforced referential

integrity, the following rules apply:  You cannot change a primary key value in the

primary table if doing so would create orphanrecords. For example, you cannot change an ordernumber in the Orders table if there are line itemsassigned to that Order in the Order Details table.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 22/26

Referential Integrity Options 

Cascade Update Related Fields

- permits the change of the primary key of the “one” table and modifies the related records inthe “many” table to match (e.g. if a librarypatron loses her card, any books she has

checked out can be switched to her new cardnumber.)

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 23/26

Referential Integrity 

Cascade Delete Related Fields

- permits the deletion of a record in the “one” table and deletes all related recordsin the “many” table. 

** These options are usually turned onwhen needed and turned OFF the rest of the time.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 24/26

Edit a Relationship In the Relationships window, double

click the relationship line to reopen the

Edit Relationships box.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 25/26

Delete a Relationship In the Relationships window, right click 

the relationship line and choose Delete

from the pop-up menu, or click Deletein the keyboard.

7/29/2019 Table Relationships (Microsoft Access)

http://slidepdf.com/reader/full/table-relationships-microsoft-access 26/26

Thank   you!  

Prepared By: Prof. LRQ Natividad


Recommended