Describe why relationships are important in a database




















That record relates to one, and only one, record in the Payroll table. Each record in the Payroll table relates to one, and only one, record in the Personal table. This is what looking at it from both directions means. In a one-to-one relationship, either table can be considered to be the primary or parent table. A one-to-many 1:N relationship means a record in Table A can relate to zero, one, or many records in Table B.

Many records in Table B can relate to one record in Table A. The potential relationship is what's important; for a single record in Table A, there might be no related records in Table B, or there might be only one related record, but there could be many. Look at the following tables about a company's Customers and Orders. Above, tables with data about customers and orders that have a one-to-many relationship. The Customers table holds a unique record for each customer.

Each customer can and, we hope, does place many orders. 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. In the junction table, set the primary key to include the primary key fields from the other two tables. Select the field or fields that you want to define as the primary key.

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. If you want the order of the fields in a multiple-field primary key to differ from the order of those fields in the table, click Indexes on the toolbar to display the Indexes dialog box, and then reorder the field names for the index named PrimaryKey.

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. You can set referential integrity when all the following conditions are true:. 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.

If you click to select the Cascade Update Related Fields check box when you define a relationship, any time that you change the primary key of a record in the primary table, Microsoft Access automatically updates the primary key to the new value in all related records. For example, if you change a customer's ID in the "Customers" table, the CustomerID field in the "Orders" table is automatically updated for every one of that customer's orders so that the relationship is not broken.

Access cascades updates without displaying any message. If the primary key in the primary table is an AutoNumber field, selecting the Cascade Update Related Fields check box has no effect because you cannot change the value in an AutoNumber field.

If you select the Cascade Delete Related Records check box when you define a relationship, any time that you delete records in the primary table, Access automatically deletes related records in the related table. 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. When you delete records from a form or datasheet when the Cascade Delete Related Records check box selected, Access warns you that related records may also be deleted. However, when you delete records by using a delete query, Access automatically deletes the records in related tables without displaying a warning.

Option 1 defines an inner join. An inner join is a join in which records from two tables are combined in a query's results only if values in the joined fields meet a specified condition.

In a query, the default join is an inner join that selects records only if values in the joined fields match. Option 2 defines a left outer join. A left outer join is a join in which all the records from the left side of the LEFT JOIN operation in the query's SQL statement are added to the query's results, even if there are no matching values in the joined field from the table on the right side.

Option 3 defines a right outer join. A right outer join is a join in which all the records from the right side of the RIGHT JOIN operation in the query's SQL statement are added to the query's results, even if there are no matching values in the joined field from the table on the left side. Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services. Privacy policy. Skip to main content.

This browser is no longer supported. Download Microsoft Edge More info. Contents Exit focus mode. Note Novice: Requires knowledge of the user interface on single-user computers. The primary key is a candidate key that is selected by the database designer to be used as an identifying mechanism for the whole entity set. It must uniquely identify tuples in a table and not be null.

The primary key is indicated in the ER model by underlining the attribute. A secondary key is an attribute used strictly for retrieval purposes can be composite , for example: Phone and Last Name. A foreign key FK is an attribute in a table that references the primary key in another table OR it can be null. Both foreign and primary keys must be of the same data type. A null is a special symbol, independent of data type, which means either unknown or inapplicable.

It does not mean zero or blank. Features of null include:. NOTE: The result of a comparison operation is null when either argument is null. The result of an arithmetic operation is null when either argument is null except functions that ignore nulls. To begin, find all employees emp in Sales under the jobName column whose salary plus commission are greater than 30, This result does not include E13 because of the null value in the commission column.

To ensure that the row with the null value is included, we need to look at the individual fields. By adding commission and salary for employee E13, the result will be a null value. The solution is shown below. Relationships are the glue that holds the tables together. They are used to connect related information between tables. Relationship strength is based on how the primary key of a related entity is defined. A weak, or non-identifying, relationship exists if the primary key of the related entity does not contain a primary key component of the parent entity.

Company database examples include:. A strong, or identifying, relationship exists when the primary key of the related entity contains the primary key component of the parent entity. Examples include:. A one to many 1:M relationship should be the norm in any relational database design and is found in all relational database environments. For example, one department has many employees. Figure 8. A one to one relationship is the relationship of one entity to only one other entity, and vice versa.

It should be rare in any relational database design. In fact, it could indicate that two entities actually belong in the same table. Example of mapping an M:N binary relationship type. A unary relationship, also called recursive, is one in which a relationship exists between occurrences of the same entity set. In this relationship, the primary and foreign keys are the same, but they represent two entities with different roles.

See Figure 8. For some entities in a unary relationship , a separate column can be created that refers to the primary key of the same entity set. A ternary relationship is a relationship type that involves many to many relationships between three tables. Refer to Figure 8. Note n-ary means multiple tables in a relationship. These are well suited to data modelling for use with databases.

Use the ERD of a school database in Figure 8.



0コメント

  • 1000 / 1000