How to create relationship between tables in ms access 2010

how to create relationship between tables in ms access 2010

An example of how to design the tables in a Microsoft Access databsea, to handle a After creating the three tables, Margaret needs to create a link between them. In Access and , Relationships is on the Database Tools ribbon. Describes how to define relationships in a database in Access , Access , Access , Access , or Access Launch Access , navigate to Database Tools on new Access ribbon and click Relationships button. MS Office Here you can create new relationship between tables, Specify Join Type, and Enforce Referential Integrity.

Access draws a relationship line between the two tables. If you selected the Enforce Referential Integrity check box, the line appears thicker at each end.

This means that the Indexed property for these fields should be set to Yes No Duplicates. If both fields have a unique index, Access creates a one-to-one relationship. This means that the Indexed property for this field should be set to Yes No Duplicates.

Microsoft Access tips: Relationships between Tables

The field on the many side should not have a unique index. It can have an index, but it must allow duplicates. When one field has a unique index, and the other does not, Access creates a one-to-many relationship.

Create a relationship in an Access web app The Relationships window isn't available in an Access web app.

how to create relationship between tables in ms access 2010

Instead of creating a relationship in an Access web app, you create a lookup field that gets values from a related field in another table. The field that your lookup will use as the source for values must already exist before you create your lookup field.

Open the table where you want to create a new lookup field by double-clicking it in the navigation. In the above example, click the Employees table. Click in the Field Name column just below the last field in the table and type a name for your new lookup field.

Create a relationship - Access

In the example, type Region as the field name. In the Data Type column, click the arrow and select Lookup. The Lookup Wizard starts. On the first page of the Lookup Wizard, select I want the lookup field to get values from another table or query.

More options appear in the dialog box. Select the name of the table or query that should provide the values for your lookup. In the example, select Table: After you select the table, use the Which value do you want to display in your lookup list to select the field that you want to use as a display value for your lookup field.

To create a relationship between a table and itself, add that table two times.

how to create relationship between tables in ms access 2010

Drag the field that you want to relate from one table to the related field in the other table. To drag multiple fields, press Ctrl, click each field, and then drag them.

In most cases, you drag the primary key field this field is displayed in bold text from one table to a similar field this field frequently has the same name that is called the foreign key in the other table. Make sure that the field names that are displayed in the two columns are correct.

You can change the names if it is necessary.

Create, edit or delete a relationship

Set the relationship options if it is necessary. These options will be explained in detail later in this article. Click Create to create the relationship. Repeat steps 4 through 7 for each pair of tables that you want to relate. Whether you save the layout or do not save the layout, the relationships that you create are saved in the database. However, referential integrity is not enforced with queries. How to define a many-to-many relationship To create a many-to-many relationship, follow these steps: Create the two tables that will have a many-to-many relationship.

Create a third table. This is the junction table. In the junction table, add new fields that have the same definitions as the primary key fields from each table that you created in step 1. In the junction table, the primary key fields function as foreign keys. You can add other fields to the junction table, just as you can to any other table.

how to create relationship between tables in ms access 2010

In the junction table, set the primary key to include the primary key fields from the other two tables. Note To create a primary key, follow these steps: Open a table in Design view. Select the field or fields that you want to define as the primary key.

  • How to define relationships between tables in an Access database
  • Relationships between Tables
  • Create a relationship

To select one field, click the row selector for the desired field. To select multiple fields, hold down the Ctrl key, and then click the row selector for each field. In Access or in Accessclick Primary Key on the toolbar. Define a one-to-many relationship between each primary table and the junction table. Referential integrity Referential integrity is a system of rules that Access uses to make sure that relationships between records in related tables are valid, and that you do not accidentally delete or change related data.

The matching field from the primary table is a primary key or has a unique index. The related fields have the same data type. There are two exceptions.

Both tables belong to the same Access database. If the tables are linked tables, they must be tables in Access format, and you must open the database in which they are stored to set referential integrity. Referential integrity cannot be enforced for linked tables from databases in other formats. The following rules apply when you use referential integrity: You cannot enter a value in the foreign key field of the related table that does not exist in the primary key of the primary table.

However, you can enter a Null value in the foreign key. This specifies that the records are unrelated. For example, you cannot have an order that is assigned to a customer who does not exist. 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 the employee in the "Orders" table.

You cannot change a primary key value in the primary table if that record has related records.

how to create relationship between tables in ms access 2010

For example, you cannot change an employee's ID in the "Employees" table if there are orders assigned to that employee in the "Orders" table.

Cascading updates and deletes For relationships in which referential integrity is enforced, you can specify whether you want Access to automatically cascade update or cascade delete related records.

If you set these options, delete and update operations that would usually be prevented by referential integrity rules are enabled. When you delete records or change primary key values in a primary table, Access makes the necessary changes to related tables to preserve referential integrity.

Access cascades updates without displaying any message. For example, if you delete a customer record from the "Customers" table, all the customer's orders are automatically deleted from the "Orders" table. This includes records in the "Order Details" table that are related to the "Orders" records. However, when you delete records by using a delete query, Access automatically deletes the records in related tables without displaying a warning.

Join types There are three join types. You can see them in the following screen shot: