官术网_书友最值得收藏!

Relationships

Relationships identify associations between the data stored in different tables. Entities relate to other entities in a variety of ways. Table relationships come in several forms, listed as follows:

  • A one-to-one relationship
  • A one-to-many relationship
  • A many-to-many relationship

A one-to-one relationship

A one-to-one relationship represents a relationship between entities in which one occurrence of data is related to one and only one occurrence of data in the related entity. For example, every employee should have a payroll record, but only one payroll record. Have a look at the following diagram to get a better understanding of one-to-one relationships:

A one-to-many relationship

A one-to-many relationship seems to be the most common relationship that exists in relational databases. In the one-to-many relationship, each occurrence of data in one entity is related to zero or more occurrences of data in a second entity. For example, each department in a Department table can have one or more employees in the Employee table. The following diagram will give you a better understanding of one-to-many relationships:

A many-to-many relationship

In a many-to-many relationship, each occurrence of data in one entity is related to zero or more occurrences of data in a second entity, and at the same time, each occurrence of the second entity is related to zero or more occurrences of data in the first entity. For example, one instructor teaches many classes, and one class is taught by many instructors, as shown in the following diagram:

A many-to-many relationship often causes problems in practical examples of normalized databases, and therefore, it is common to simply break many-to-many relationships in to a series of one-to-many relationships.

主站蜘蛛池模板: 宜兴市| 黑龙江省| 富平县| 唐河县| 浦县| 宜城市| 德清县| 宜昌市| 林州市| 兖州市| 广水市| 平乐县| 富锦市| 会东县| 宁津县| 金寨县| 宕昌县| 北票市| 专栏| 台湾省| 建昌县| 鲁甸县| 始兴县| 宜兰县| 南乐县| 科技| 都安| 武陟县| 乌拉特前旗| 长治市| 涟水县| 栖霞市| 星子县| 义马市| 八宿县| 定远县| 苗栗市| 永登县| 龙里县| 将乐县| 大渡口区|