Beruflich Dokumente
Kultur Dokumente
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 (now called a Foreign Key).
One-to-one
Very common, one record in the primary table can be linked to many records in the related table, but each record in the related table can be linked to only one in the primary table. Examples: A mother can have many children, but each child has only one mother; a salesman can make many sales, but any given sale is credited to only one salesman; a person can have many library books checked out but each book can be checked out by only one person (at a time).
One-to-many
Very common, when a single record in one table can relate to many records in another, and a single record in that second table can also relate to many records in the first. Examples: one author can write many books, and one book can have several authors; one student can take many classes and one 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.)
Many-to-many
Access automatically detects the type of relationship (usually one-to-many). If neither field allows duplicates a one-to-one relationship will be created.
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.
An orphan record is one that refers to a nonexistent record in another table, such as the orders placed by nonexistent customers.
The purpose of using referential integrity is to prevent orphan records and to keep references synchronized so that you don't have any records that reference other records that no longer exist. You enforce referential integrity by enabling it for a table relationship.
Once enforced, Access rejects any operation that 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.
After you have enforced referential integrity, the following rules apply:
You cannot enter a value in the foreign key field of a related table if that value doesn't exist in the primary key field of the primary table doing so creates orphan records. You cannot delete a record from a primary table if matching records exist in a related table. For example, you cannot delete an employee record from the Employees table if there are orders assigned to that employee in the Orders table.
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 orphan records. For example, you cannot change an order number in the Orders table if there are line items assigned to that Order in the Order Details table.
Referential Integrity
Cascade Delete Related Fields - permits the deletion of a record in the one table and deletes all related records in the many table.
** These options are usually turned on when needed and turned OFF the rest of the time.
Edit a Relationship
In the Relationships window, double click the relationship line to reopen the Edit Relationships box.
Delete a Relationship
In the Relationships window, right click the relationship line and choose Delete from the pop-up menu, or click Delete in the keyboard.
Thank you!