COMP3311 Week 1 Wednesday Lecture
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [0/16]
 
 
Topics:
-  Entity-Relationship (ER) Model (cont)
 -  Relational Model
 -  Mapping ER → SQL
 -  SQL Data Definition Language (DDL)
 
Reminders:
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [1/16]
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [2/16]
 
 
ER models give a visual representation of database structure
Primary components
-  Entities = objects of interest in the scenario
 -  Relationships = associations between entities
 -  Attributes = properties of entities
 
ER models don't capture all information from the scenario
-  e.g. types and constraints on attribute values
 
ER models are useful as a step towards an SQL schema
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [3/16]
 
 
❖ ER Model (recap) (cont)  |  | 
ER design elements:
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [4/16]
 
 
❖ ER Model (recap) (cont)  |  | 
Relationships:
Thick line = total participation;   thin line = partial participation
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [5/16]
 
 
Using the ER diagram below
-  give examples of entity values
 -  describe the semantics of the relationships
 
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [6/16]
 
 
For each of the informal data models
-  Course outline
 -  Instagram
 -  Gmail
 
give a suitable ER diagram
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [7/16]
 
 
ER also implements super-class / sub-class hierarchies
-  both super- and sub-classes consist of entities
 -  super-class has common properties of all entities in hierarchy
 -  sub-classes can add extra properties to specialise
 -  entities in super-class may have corresponding entities in sub-class
 -  sub-classes can be
-  disjoint ... entities are members of only one sub-class
 -  overlapping ... entities can be members of several sub-classes
 
 -  sub-classes can be involved in separate relationships
 
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [8/16]
 
 
❖ Class Hierarchies (cont)  |  | 
ER class hierarchies use circle to connect super/sub-classes:
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [9/16]
 
 
❖ Class Hierarchies (cont)  |  | 
Consider a concrete example of a class hierarchy:
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [10/16]
 
 
❖ Exercise: Student/Lecturer Class Hierarchy  |  | 
Modify the student-lecturer class hierachy to represent
-  some people in the database are students or lecturers
 -  all people in the database are students or lecturers
 -  all people in the database are students XOR lecturers
 -  some people in the database are students XOR lecturers
 
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [11/16]
 
 
A complete ER model should ...
-  include all entities and their attributes
 -  identify key attributes
 -  capture accurate semantics for all relationships
 -  include class hierarchies where appropriate
 
There are frequently different kinds of people (⇒ sub-classes)
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [12/16]
 
 
❖ Exercise: Medical Information  |  | 
Develop an ER model for the following scenario:
-  Patients are identified by an SSN, and their names, addresses and ages
must be recorded.
 -  Doctors are identified by an SSN. For each doctor, the name, specialty
and years of experience must be recorded.
 -  A pharmacist is identified by an SSN, he/she can only work for one
pharmacy. For each pharmacist, their name must be recorded.
 -  Each pharmacy has a name, address and phone number. A pharmacy must have
a manager, who is a pharmacist.
 -  For each drug, the trade name and formula must be recorded.
 -  Every patient has a primary physician. Every doctor has at least one
patient. 
 -  Each pharmacy sells several drugs, and has a price for each. A drug
could be sold at several pharmacies, and the price could vary between
pharmacies.
 -  Doctors prescribe drugs for patients. A doctor could prescribe one or
more drugs for several patients, and a patient could obtain prescriptions
from several doctors. Each prescription has a date and quantity associated
with it.
 
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [13/16]
 
 
Entity-relationship (ER) model
-  world is modelled via entities, relationships, attributes
 
Relational model
-  world is modelled via tuples, relations, constraints
 
SQL schemas
-  a good approximation of the relational model
 
Also ODL, UML, and a variety of others ... but not in this course.
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [14/16]
 
 
Attribute = data item with a name and a type/domain
-  e.g.   
account_balance has domain non-negative integer
 
Tuple = list of values   
(cf. Python tuples, C  structs)
-  e.g.   (1234567, John Smith, BE, SENG, 75.2)
 
Relation = set of tuples
-  e.g.   {  (1,2,3), (3,2,1), (1,3,5), (2,4,6) }
 
Constraint = logical statements on valid data
-  e.g.   zID is unique   and   0 ≤ WAM ≤ 100
 
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [15/16]
 
 
❖ Relational Model (cont)  |  | 
Correspondence between ER and Relational models:
-  Relational attributes correspond to ER attributes
-  although ER attributes generally don't have explicit domains
 
 -  Relational tuples  correspond to ER entities
 -  Relations correspond to sets of ER entities
 -  Relations also correspond ER relationships
 
 
COMP3311 23T3 ♢ Week 1 Wednesday Lecture ♢ [16/16]
Produced: 13 Sep 2023