Book: Database System Concepts, Silberschatz, Korth, Sudarshan
The task of creating a database application is a complex one, involving design of the database schema, design of the programs that access and update the data,and design of a security scheme to control access to data.
In this chapter, we focus on the DESIGN of the database schema.
The entity-relationship (E-R) data model was developed to facilitate database design by allowing specification of an enterprise schema that represents the overall logical structure of a database.
The E-R model is very useful in mapping the meanings and interactions of real-world enterprises onto a conceptual schema. Because of this usefulness, many database-design tools draw on concepts from the E-R model. The E-R data model employs three basic concepts: entity sets, relationship sets, and attributes, which we study first. The E-R model also has an associated diagrammatic representation, the E-R diagram, which we study later in this chapter.
Study Strategy: Retrieval Practice
The task of creating a database application is a complex one, involving design of the _____, design of the programs that _____ and _____ the data,and design of a _____ scheme to control access to data.
In this chapter, we focus on the DESIGN of the _____ schema.
The entity-relationship (E-R) data model was developed to facilitate database design by allowing specification of an _____ that represents the overall _____ structure of a database.
The E-R model is very useful in mapping the _____ and _____ of real-world enterprises onto a _____ schema. Because of this usefulness, many database-design tools draw on concepts from the E-R model. The E-R data model employs three basic concepts: _____, _____, and _____, which we study first. The E-R model also has an associated diagrammatic representation, the _____, which we study later in this chapter.
An entity is a “thing” or “object” in the real world that is distinguishable from all other objects. For example, each person in a university is an entity. An entity has a set of properties, and the values for some set of properties may uniquely identify an entity. For instance, a person may have a person id property whose value uniquely identifies that person. Thus, the value 677-89-9011 for person id would uniquely identify one particular person in the university. Similarly, courses can be thought of as entities, and course id uniquely identifies a course entity in the university. An entity may be concrete, such as a person or a book, or it may be abstract, such as a course, a course offering, or a flight reservation.
An entity set is a set of entities of the same type that share the same properties, or attributes. The set of all people who are instructors at a given university, for example, can be defined as the entity set instructor. Similarly, the entity set student might represent the set of all students in the university.
In the process of modeling, we often use the term entity set in the abstract, without referring to a particular set of individual entities. We use the term ex- tension of the entity set to refer to the actual collection of entities belonging to the entity set. Thus, the set of actual instructors in the university forms the exten- sion of the entity set instructor. The above distinction is similar to the difference between a relation and a relation instance, which we saw in Chapter 2.
Entity sets do not need to be disjoint. For example, it is possible to define the entity set of all people in a university (person). A person entity may be an instructor entity, a student entity, both, or neither.
An entity is represented by a set of attributes. Attributes are descriptive properties possessed by each member of an entity set. The designation of an attribute for an entity set expresses that the database stores similar information concerning each entity in the entity set; however, each entity may have its own value for each attribute. Possible attributes of the instructor entity set are ID, name, dept name, and salary. In real life, there would be further attributes, such as street number, apartment number, state, postal code, and country, but we omit them to keep our examples simple. Possible attributes of the course entity set are course id, title, dept name, and credits.
Each entity has a value for each of its attributes. For instance, a particular instructor entity may have the value 12121 for ID, the value Wu for name, the value Finance for dept name, and the value 90000 for salary.
The ID attribute is used to identify instructors uniquely, since there may be more than one instructor with the same name. In the United States, many enterprises find it convenient to use the social-security number of a person2 as an attribute whose value uniquely identifies the person. In general the enterprise would have to create and assign a unique identifier for each instructor.
A database thus includes a collection of entity sets, each of which contains any number of entities of the same type. Figure 7.1 shows part of a university database that consists of two entity sets: instructor and student. To keep the figure simple, only some of the attributes of the two entity sets are shown.
A database for a university may include a number of other entity sets. For example, in addition to keeping track of instructors and students, the university also has information about courses, which are represented by the entity set course with attributes course id, title, dept name and credits. In a real setting, a university database may keep dozens of entity sets.
An E-R enterprise schema may define certain constraints to which the contents of a database must conform. In this section, we examine mapping cardinalities and participation constraints.
For a binary relationship set R between entity sets A and B, the mapping cardinality must be one of the following:
One-to-one. An entity in A is associated with at most one entity in B, and an entity in B is associated with at most one entity in A.
One-to-many. An entity in A is associated with any number (zero or more) of entities in B. An entity in B, however, can be associated with at most one entity in A.
Many-to-one. An entity in A is associated with at most one entity in B. An entity in B, however, can be associated with any number (zero or more) of entities in A.
Many-to-many. An entity in A is associated with any number (zero or more) of entities in B, and an entity in B is associated with any number (zero or more) of entities in A.
One to Many: B at most one A
Many to one : A at most one B