Designing Database Applications
Walid G. Aref
Designing Database Applications Walid G. Aref Roadmap for - - PowerPoint PPT Presentation
Designing Database Applications Walid G. Aref Roadmap for Designing Database Applications 1. Analyzing real-world applications Real-world application side: Domain experts To tell their story What they need DBMS side: System
Walid G. Aref
1. Analyzing real-world applications
database application
intended to provide a standard way to visualize the design of a system
relationships
application
iPhoneNumber, iAddress
Instructor iid iName iRank
iSalary
6
7
group of entities with the same attributes
different “roles”
R1 E2 E1 Binary Relationship
Manage Employee
Manager of Managed by
9
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
Takes
Courses
semester year
Instructor Student
1st Entity 2nd Entity 3rd Entity Attribute
Takes
Courses
semester year
Instructor Student
Takes
Courses
semester year
Instructor Student Course Offering
R1
Instructor Student
R2
Courses
R3 semester year
the relationship
Many-to-Many Relationship 1-to-1 Relationship 1-to Many Relationship Many-to-1 Relationship
Entity
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
and maximum cardinalities.
courses
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits 2-5 1-1
identifying or strong) entity.
Dep_age Dep_name Dependents Insured Price
Instructor iid iName iRank
iSalary Year
some commonalities and that are distinguishable from other entities in the same entity set
subset of Tenured Instructors vs. Adjunct Faculty
entity set.
entity set.
Tenured_Prof hourly_wages IS-A Adjunct_Faculty TenureYear hours_worked
Instructor iid iName iRank
iSalary
Adjunct faculty at the same time? i.e., belong to multiple specializations?
tenured faculty nor an adjunct faculty?
super class
Tenured_Prof IS-A Adjunct_Faculty Instructor
Disjoint & Partial
(e.g., Evaluates) that relates an entity to other relationships and entities (e.g., teaches, courses, and instructor)
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
Evaluates Mentor
Date
Relationship instead?
attributes
Teaching activity is evaluated by at most
teaching activity is
to retain the Teaches relationship
feasible values for the attribute
from BirthDate)
Name Name First Name Middle Name Last Name Phone Numbers Age
address an entity and each of the sub-components an attribute of the address entity. Otherwise, make address as an atomic attribute (whose value is indivisible)
employee to work in a department for two or more periods.
wanting to record several addresses for an employee: We want to record several values of the descriptive attributes for each instance of this
introducing new entity set, Duration.
name Employees ssn lot Works_In from to dname budget did Departments dname budget did name Departments ssn lot Employees Works_In Duration from to
Database Management Systems, 3rd Edition, R. Ramakrishnan, and J. Gehrke
gets a separate discretionary budget for each dept.
discretionary budget that covers all managed depts?
each dept managed by manager.
associated with department-mgr combination.
Manages name dname budget did Employees Departments ssn lot dbudget since dname budget did Departments Manages Employees name ssn lot since Managers dbudget
ISA
This fixes the problem! Database Management Systems, 3rd Edition, R. Ramakrishnan, and J. Gehrke
employee, and each dependent is tied to the covering policy, first diagram is inaccurate.
constraints in the 2nd diagram?
age pname Dependents Covers name Employees ssn lot Policies Policy_id cost Beneficiary age pname Dependents Policy_id cost Policies Purchaser name Employees ssn lot
Bad design Better design Database Management Systems, 3rd Edition, R. Ramakrishnan, and J. Gehrke
relationships were better than one ternary relationship.
relates entity sets Parts, Departments and Suppliers, and has descriptive attribute qty. No combination of binary relationships is an adequate substitute:
that D has agreed to buy P from S.
Database Management Systems, 3rd Edition, R. Ramakrishnan, and J. Gehrke
relation’s attributes
Instructor iid iName iRank
iSalary
attributes into a relation.
them keys in the relationship è
37
Teaches
Instructor iid iName iRank
iSalary
Courses cid
semester
cname
year credits
semester)
year, semester)
R1 E2 E1 m-1 Relationship
F A B a1 b1 a2 b2 a3 b3 C D c1 d1 c2 d2 c3 d3 A C F a1 c1 f1 a2 c1 f2 a3 c3 f3 A B C F a1 b1 c1 f1 a2 b2 c1 f2 a3 b3 c3 f3 C D c1 d1 c2 d2 c3 d3
Foreign key
D C B A
E1(A,B) R1(A, C, F) E2(C,D)
A B a1 b1 a2 b2 a3 b3 C D c1 d1 c2 d2 c3 d3 A C F a1 c1 f1 a2 c1 f2 A B C F a1 b1 c1 f1 a2 b2 c1 f2 a3 b3 ⏚ ⏚ C D c1 d1 c2 d2 c3 d3
Foreign key has Null values R1 E2 E1 m-1 Relationship
F D C B A
relation è The need for renaming
Manage Employee
Manager of Managed by
key of the identifying strong entity set
Dep_age Dep_name Dependents Insured Price
Instructor iid iName iRank
iSalary Year
Price, Year)
instructor
Tenured_Prof hourly_wages IS-A Adjunct_Faculty TenureYear hours_worked
Instructor iid iName iRank
iSalary
Tenured faculty as well as an Adjunct faculty at the same time? i.e., belong to multiple specializations?
instructor that is neither a tenured faculty nor an adjunct faculty?
primary key of super-class entity set + attributes of subclass
Tenured Prof need to access two relations, the one for the super-class (Instructor) and the one for the sub-class (Tenured_Prof)
Tenured_Prof hourly_wages IS-A Adjunct_Faculty TenureYear hours_worked
Instructor iid iName iRank
iSalary
iSalary)
iSalary, hourly_wages, hours_worked)
iSalary, TenureYear)
may be stored redundantly for people who are both instructor and Tenured_Prof
need for relation Instructor
always two tables
Tenured_Prof hourly_wages IS-A Adjunct_Faculty TenureYear hours_worked
Instructor iid iName iRank
iSalary
everything
iSalary, Adjunct_Faculty, hourly_wages, hours_worked, Tenured_Prof, TenureYear)
Tenured_Prof are Boolean
lName, iRank, iSalary)
First Name Middle Name Last Name
Instructor iid iName iRank
iSalary
1. Take phone numbers out of Instructor schema, Create a separate phone table: Phones(iid, phone) 2. If we happen to know max number of phones per instructor (e.g., 3 phones), then: Instructor(iid, fName, mName, lName, iRank, iSalary, phone1, phone2, phone3) May introduce Null Values
First Name Middle Name Last Name
Instructor iid iName iRank
iSalary Phone Numbers