Data Modelling Using Entity-Relationship (ER) Model Chapter 3 Data Modelling Using Entity-Relationship (ER) Model
Phases of Database Design
“Company” Example Database Application Description of the mini-world: The company is organized into departments. Each department has a unique name, a unique number and a particular employee who manages the department, including the date he/she began managing the department. A department may have several locations.
Cont’d… A department controls a number of projects Each project has a unique name, number and a single location
Cont’d… We record each employee’s name, SSN, address, salary, sex and birth date. Also we record who is the supervisor An employee works in one department but may work on several projects in different department We track work hours of employees in projects
Cont’d We record the dependants of each employee, including the first name, sex, birth date and relationship to the employee
ER Schema for “Company”
Entity & Attributes Entity is the “thing” either physical existence (person, car, house) or conceptual (company, course, job). Attributes are the properties of the entity Each attributes has values.
Entity, attribute & value example
Composite vs. Simple Attributes Composite attributes can be divided into smaller part. For example, address consist of Street Address City State Postal Code Simple (atomic) attributes are no longer divisble
Con’d
Single valued vs. Multi-valued Singe valued: Age Sex SSN Multi valued: Children
Other terms… Stored vs. derived values. Derived values example may include GPA, sub-totals, etc. Null values: “nothing”, not zero, not blank space!
Complex attributes Composite and multi-valued attributes can be nested in an arbitrary way () for nesting {} for multi value Example {Address&Phone ( {Phone(AreaCode, PhoneNumber)}, Address(StreetAddress(Number, Street, ApartmentNumber), City, State, Zip) ) }
Entity Type It defines the set of possible entities with the same attributes For example, ‘employee type’ is the set of employees in the company
Key Attributes of an Entity Type What makes an entity unique? An employee: SSN A company: name A project: number, name A purchase slip may have 2 keys: date & time Keys must be minimal
Value Sets Possible values of an attribute. Usually: Numeric Text Boolean Etc. But can be more specific, for example: Birth date must be > 1850 but before <(now) Sex must be either female or male
Initial Entity Concept of Company Database
Relationship Relationship type amongst entities defines a set of associations For example between an employee and a department there is a relationship Works_For. Represented as diamond shaped boxes
Degree of relationship type Binary relationship Ternary relationship
Binary rerlationship
Ternary Relationship
Recursive relationships
Constraints on relationships Cardinality ratios 1:1, the relation Manages M:N, the relation Works_On N:1, the relation Works_FOR Participation constraints For example, an employee must be working for a department (null value is impossible)
M:N Relationship
1:1 Relationship
Attribute of a relationship Yes… a relationship may include additional attributes For example Start managing in the Manages relationship
Weak Entity Dependants do not have any key on its own Why? Because there might be small chance that 2 employees have the same first name, birth date, sex for their son! Personally, I do not like weak entities (hard to query).
The New ER Diagram
Summary of ER Diagram Notations
Cont’d…