Relationships in a database
Tuesday, January 15th, 2008 |Once you have set up different tables for each subject in your database, you need a way to tell Microsoft Access how to gather this information again. The first step in this process is to define relationships between your tables. After having done this, you can create queries, forms and reports to display information from multiple tables at once.
How relationships?
A one-to-many
The one-to-many relationship is the most common type of relationship. In a one-to-many relationship, a record in Table A can have many matching records in Table B, but a record in Table B has only one matching record in Table A.
A many-to-many
In a many-to-many relationship, a record in Table A can have many matching records in Table B, and a record in Table B can have many matching records in Table A. This type of relationship is only possible by defining a third table (called an association table) whose primary key consists of two fields foreign keys from both Tables A and B. In fact, a many-to-many relationships are a two-to-many relationship with a third table. For example, the Orders table and the Products table have a many-to-many relationship that is defined by creating two one-to-many for the Order Details table.
A one-to-one
In a one-to-one, each record in Table A can have only one matching record in Table B, and each record in Table B can have only one matching record in Table A. This type of relationship is not common because most information related well be in a single table. The use of a one-to-one is recommended when you want to share a table with many fields, to isolate part of a table for security or store information that applies only to a subset of the main table. You may want, for example, create a table to record the employees participating in a football game to raise funds.
Defining relationships
You define a relationship by adding the tables you want to relate to the Relationships window and then dragging the key field of a table and dropping it into the key of another table.
The kind of relationship that Microsoft Access creates depends on how the related fields are defined:
• A one-to-many relationship is created if only one of the related fields is a primary key or has a unique index.
• A one-to-one is created when both the related fields are primary keys or have unique indexes.
• In fact, a many-to-many relationships are a two-to-many relationship with a third table whose primary key consists of two fields foreign keys of the other two tables.
Note If you drag a field that is not a primary key and does not have a unique index to another field that is not a primary key and does not have a unique index, an indeterminate relationship is created. In queries containing tables with an indeterminate relationship, Microsoft Access displays a default join line between the tables, but referential integrity is not enforced and there is no guarantee that records are unique in each table.





























