Sub topic 1
Entities, Entity Sets, and Relationships
Prerequisites
This chapter assumes that you know what a table, row, and column are. You should also understand basic set notation and introductory SQL.
Entities, Entity Sets, and Relationships
An entity is a distinguishable real-world object about which a database stores information. A student, course, employee, or department can be an entity. Each entity has properties that describe it, such as a student’s roll number or name.
An entity type describes the common structure of similar entities. For example, STUDENT is an entity type with attributes such as student_id and name.
An entity set is the collection of entities of one entity type at a particular time. If the database contains 500 students, those students form the STUDENT entity set. In a relational database, an entity set usually becomes a table, and each entity becomes a row.
A relationship is an association among entities. For example, a student enrolls in a course, or an employee works for a department. A relationship type describes the common form of that association. The actual associations between specific entities form a relationship set.
For example, the relationship type ENROLLS connects the entity types STUDENT and COURSE. One relationship instance might connect student 42 with course CS201.
A relationship can also have its own attributes. The ENROLLS relationship might contain enroll_date or grade. These values describe the enrollment, not the student or the course independently.
Attribute Types in an ER Diagram
An attribute is a property of an entity or relationship. Attribute design affects both the ER diagram and the tables produced from it.
- A simple attribute cannot be meaningfully divided further for the application.
Genderorsalarymay be simple attributes. - A composite attribute consists of smaller components.
Addressmight containstreet,city, andpostal_code. - A single-valued attribute has one value for each entity, such as one date of birth.
- A multivalued attribute can have several values, such as a person’s phone numbers.
- A derived attribute is calculated from other stored values.
Agecan be derived fromdate_of_birth. - A key attribute identifies an entity uniquely.
student_idcan identify one student.
| Attribute type | Example | Typical relational treatment |
|---|---|---|
| Composite | Address | Store its components separately |
| Multivalued | Phone numbers | Create a separate related table |
| Derived | Age | Calculate when needed |
| Key | Student ID | Use as a primary key |
A good design distinguishes stored facts from calculated facts. It also avoids putting a list of values in one column. A multivalued attribute normally becomes a separate relation whose rows reference the original entity.
Exercise
In an ER model, where should grade be placed for a student taking a course: STUDENT, COURSE, or ENROLLS? Why?
Show answer
Place grade on ENROLLS. It describes the association between one student and one course, not either entity alone.