COP5725 Database Management ER DIAGRAM AND RELATIONAL DATA MODEL Prof: Dr. Shu-Ching Chen TA: Sheng Guan
Entity-Relationship Model
E- R Data Modeling Example: specific person, company, event, plant An entity is an object that exists and is distinguishable from other objects. Example: specific person, company, event, plant Entities have attributes Example: people have names and addresses An entity set is a set of entities of the same type that share the same properties. Example: set of all persons, companies, trees, holidays
Attributes An entity is represented by a set of attributes, that is descriptive properties possessed by all members of an entity set. Example: instructor = (ID, name, street, city, salary ) course= (course_id, title, credits) Attribute types: Simple and composite attributes. Single-valued and multivalued attributes Derived attributes
Relationship Sets A relationship is an association among several entities Example: 44553 (Peltier) advisor 22222 (Einstein) student entity relationship set instructor entity
Entity-Relationship Diagrams Representing entities we represent an entity by a named rectangle use a singular noun, or adjective + noun refer to one instance in naming CUSTOMER PART-TIME EMPLOYEE
Entity-Relationship Diagrams Representing relationship DEPT EMPLOYEE employs
Entity-Relationship Diagrams One to one One to many
Entity-Relationship Diagrams Many-to-many relationship (M:N): exists when one instance of the first entity can relate to many instances of the second entity, and one instance of the second entity can relate to many instances of the first entity. (c) Many to many
E-R Diagram for a University
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage Complex file organization and index structures. ODL definitions Diagrams (E/R) Tables: row names: attributes rows: tuples
Terminology Attribute names Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $149.99 photography Canon MultiTouch $203.99 household Hitachi tuples
More Terminology Every attribute has an atomic type. Relation Schema: relation name + attribute names + attribute types Relation instance: a set of tuples. Only one copy of any tuple! Database Schema: a set of relation schemas. Database instance: a relation instance for every relation in the schema.
name category name price makes Company Product Stock price buys employs Person name ssn address
Entity Sets to Relations name category price Product Product: Name Category Price gizmo gadgets $19.99
Relationships to Relations Start Year name category name makes Company Product Stock price Relation MAKES (watch out for attribute name conflicts) Product-name Product-Category Company-name Starting-year gizmo gadgets gizmoWorks 1963
Handling Weak Entity Sets affiliation Team University sport number name Relation TEAM: Sport Number University-name mud wrestling 15 Montezuma State U. - need all the attributes that contribute to the key of Team - don’t need a separate relation for Affiliation.
Relational Data Model Key point: Indicate your primary key Define attribute’s data type Indicate the relationship
ER Model to Relational Model
Populate your relation Key point: At least five records are needed for each table. Also indicate the PK here.
Constraint Key point: Indicate the constraint at the end