Presentation is loading. Please wait.

Presentation is loading. Please wait.

Define Table Relationships—1 of 3 One of the most powerful features of a relational database management system, such as Access, is its ability to define.

Similar presentations


Presentation on theme: "Define Table Relationships—1 of 3 One of the most powerful features of a relational database management system, such as Access, is its ability to define."— Presentation transcript:

1 Define Table Relationships—1 of 3 One of the most powerful features of a relational database management system, such as Access, is its ability to define relationships between tables. You use a common field, which is a field that appears in two tables, to relate one table to another. The process of relating tables is often called performing a join. When you join tables that have a common field, you can extract data from them as if they were one larger table.

2 Define Table Relationships—2 of 3 For example, you can join the Client and Contract tables using Client# as the common field. common field

3 Define Table Relationships—3 of 3 Then you can use a query, form, or report to extract selected data from both tables, even though the data is contained in two separate tables. The joining of records in the query below is based on the common field of Client#. In the query results shown below, the Client Name column is from the Client table, and the other columns are from the Contract table. fields from Contract tablefield from Client table

4 The Client and Contract tables have a one-to-many relationship. A one-to-many relationship exists between two tables when one record in the first table matches zero, one, or many records in the second table, and when one record in the second table matches exactly one record in the first table. One-to-Many Relationships—1 of 3

5 Access refers to the two tables that form a relationship as the primary table and the related table. The primary table is the “one” table in a one-to-many relationship; the Client table is a primary table because there is only one client for each contract. The related table is the “many” table; the Contract table is a related table because there can be many contracts for each client. One-to-Many Relationships—2 of 3

6 Because related data is stored in two tables, inconsistencies between the tables can occur. Consider the following scenarios: Travis adds a contract to the Contract table for a client that does not exist. The data is inconsistent, and the contract record is considered to be an orphaned record. Travis changes a client number in the Client table without changing that same client number for related records in the Contract table. These contract records are now orphaned records. Travis deletes a client record because the client is no longer an AdZ client. The data is again inconsistent, if contract records still exist for that deleted client. One-to-Many Relationships—3 of 3

7 You can avoid data inconsistencies by specifying referential integrity between tables when you define their relationships. Referential integrity is a set of rules that Access enforces to maintain consistency between related tables when you update data in a database. Referential Integrity—1 of 2

8 Specifically, the referential integrity rules are as follows: When you add a record to a related table, a matching record must already exist in the primary table. If you attempt to change the value of the primary key in the primary table, Access prevents this change if matching records exist in the related table. However, if you choose the cascade updates option, Access permits the change in value to the primary key and changes the appropriate foreign key values in the related table. If you attempt to delete a record in the primary table, Access prevents the deletion if matching records exist in the related table. However, if you choose the cascade deletes option, Access deletes the record in the primary table and also deletes all records in related tables that have matching foreign key values. Referential Integrity—2 of 2

9 Define a Relationship Between Two Tables When two tables have a common field, you define a relationship between them in the Relationships window, which you open by clicking the Relationships button on the toolbar. The Relationships window illustrates the relationships among a database’s tables. In this window you can view or change existing relationships, define new relationships between tables, and rearrange the placement of tables in the window.


Download ppt "Define Table Relationships—1 of 3 One of the most powerful features of a relational database management system, such as Access, is its ability to define."

Similar presentations


Ads by Google