Home‎ > ‎Database‎ > ‎

Table Relationships in Access

Table Relationships

 
One of the major advantages of databases such as Microsoft Access is their ability to maintain relationships between different data tables. The power of a database makes it possible to correlate data in many ways and ensure the  consistency of a  (Foreign key) of this data from table to table. Establishing table relationships is the way we draw together data from separate tables. This minimizes redundant data and maintains higher levels of data base reliability.
 
To illustrate, if you are designing a database that will track information about books, you may have a table called Titles, that stores information about each book , such as the book's title, date of publication, and publisher. There are also information you might want to store about the publisher, such as the publisher's phone number, address, and zip code. If you were to store all of this information in title table, the publisher's phone number would be duplicated for each title that publisher prints. A better solution is to store the publisher information only once in a separate table, Publishers. You would then put a pointer in the Titles table that references an entry in the publishers table.
 
To make sure that you data is not out of sync, you can enforce referential integrity between the Titles and Publishers tables. Referential Integrity relationships help ensures that information in one table matches information in another. For Example, each title in the Titles table must be associated with a specific publisher in the Publishers table. A title cannot be added to the database for a publisher that does not exist in the dabase.Referential integrity
is the tool  that Microsof Access uses to ensure that relationships between records in related tables are valid and that the designer does not accidentally delete or change related data.

Types of Table Relationships
 
You bring information together by creating relationships among tables of your database. There are three kinds of relationships that you can create:
The type of relationship you chose depends a lot on how entities are related to each other.
 
To illustrate, take a sales representative and customers as an example:
 
Ones sales representative has many customers; this is one -to many relationships.
 
Now consider and order a product:
 
An order can have many products and product can appear on many orders, this is referred to as many-to many relationships.
 
Finally, think about and employee and salary. One employee receives one salary. This is one-to -one relationship.
 
     A relationship works by matching data in key columns; usually columns with the same name in both tables. In most cases, the relationship matches the
Primary key from one table, and  provides a unique identifier for each row, with an entry in the foreign key in other table. For example, sales can be associated with the specific titles sold by creating a relationship between the title id column in the Title table (The primary key) and the Sales table (the foreign key).
 
The type of relationship that is created depends on how the related columns are defined.
 
One-To-Many Relationships
 
    A one-to- many relationship, is the most common type of relationship. In this type of relationship, a row in table A can have many matching rows in a table B, but a row in table B can have only the matching in table A. For example, the publishers and Titles tables have one-to-many relationships: each publisher produces many titles, but each title comes from only one publisher.
 
 
A one-to-many relationships is created if only one of the related columns is a primary key or has unique constraint.
 
In Access, the primary key side of one-to-many relationships is denoted by a key symbol. The foreign key side of a relationship is denoted by an infinity
symbol.
 
 Many-to-Many Relationships
 
    In a many-to-many relationship, a row in a table A can have many matching rows in table B, and vice versa. You create such a relationship by defining a third table, called a junction table, whose primary key consists of the foreign keys from both Table A and Table B. For example, the Authors table and the
Titles table have a many-to-many relationship that is defined by a one-to-many relationship from each of these tables to the Title Authors table. The primary key of the Title Authorss table is the combination of the au_id column (the author's table's primary key) and the title_id column ( The Titles table's primary key).
 
One-To-One Relationships
 
    In a one-to-one relationshp, a row in table A can have no more than one matching row in table B, and vice versa. A one-to-one relationship is created if both of the related columns are primary keys or have unique constraints.
 
 
This type of relationship is not common because most information related in this way would be all in one table. You might use one-to-one relationship to:

  • Divide a table with many columns
  • Isolate part of a table for security reasons
  • Store data that is short-lived and could be easily deleted by simply deleting the table
  • Store information that applies only to a subset of the main table
The primary key side of a one-to-one relationship is denoted by a key symbol. The foreign key side is also denoted by a key symbol.


The First Step is to Organize Your Data


    Before we can create a relationship between tables, we must ensure that the tables on each side of the relationship contains fields of the same data type and that they will contain matching data. If the Country is referred to in the country field of one table as United Kingdom the relationship will be meaningless if in the other  table it is referred to as U.K here must be an exact match for the relationship to work. Combo Boxes in forms and lookup fields in Tables help to ensure that discrepancies like this don not occur.
If you are interested in learning more about Table Relationships here is the Microsoft  link where you can  obtain more information.

References:

 

 




 
 
 
 
 
 
 
 
 
Comments