Week 4_Relationship_Transferability_Documenting Business Rules and CRUD_Analysis - EditedCopy
Week 4_Relationship_Transferability_Documenting Business Rules and CRUD_Analysis - EditedCopy
2
Database System Concepts - 7th Edition 1.2 ©Silberschatz, Korth and Sudarshan
Relationship Transferability
3
Database System Concepts - 7th Edition 1.3 ©Silberschatz, Korth and Sudarshan
Outline
Database System Concepts - 7th Edition 1.4 ©Silberschatz, Korth and Sudarshan
Introduction
▪ Once a class has been allocated to a lecturer, can that class later be
transferred to another lecturer, possibly in mid-semester?
▪ Usually yes, because if not, what would we do if the original lecturer
becomes sick or resigns suddenly?
▪ Some gyms/health clubs allow memberships to be transferred from one
person to another, but other health clubs don’t.
▪ This business rule is normally determined by what is most efficient and
most profitable for the club.
Database System Concepts - 7th Edition 1.5 ©Silberschatz, Korth and Sudarshan
Relationship Review
Database System Concepts - 7th Edition 1.6 ©Silberschatz, Korth and Sudarshan
Relationship Review
▪ Optionality:
• Must every EMPLOYEE be assigned to a DEPARTMENT?
• Must every DEPARTMENT be responsible for an employee?
• Can you have an EMPLOYEE not assigned to a DEPARTMENT?
ANSWER: NO, so relationship is drawn as mandatory (solid line).
• Can you have a DEPARTMENT not responsible for any EMPLOYEEs?
ANSWER: It depends on the business rules of the company in
question, but in this case YES “We have some departments that
currently have no employees assigned to them”, so relationship is
drawn as optional (dashed line).
Database System Concepts - 7th Edition 1.7 ©Silberschatz, Korth and Sudarshan
Relationship Review
▪ Transferability:
• Can an EMPLOYEE be transferred from one DEPARTMENT to
another DEPARTMENT?
▪ Answer: yes, an EMPLOYEE and change from one DEPARTMENT to
another. This makes the relationship transferable.
▪ Does the ERD indicate this possibility (transferability)?
Database System Concepts - 7th Edition 1.8 ©Silberschatz, Korth and Sudarshan
Relationship Transferability
Database System Concepts - 7th Edition 1.9 ©Silberschatz, Korth and Sudarshan
Relationship Transferability
Database System Concepts - 7th Edition 1.10 ©Silberschatz, Korth and Sudarshan
Relationship Transferability
Database System Concepts - 7th Edition 1.11 ©Silberschatz, Korth and Sudarshan
More Nontransferable Relationships
Database System Concepts - 7th Edition 1.12 ©Silberschatz, Korth and Sudarshan
One-to-Many (1:M) Relationships
Database System Concepts - 7th Edition 1.13 ©Silberschatz, Korth and Sudarshan
Many-to-Many (M:M) Relationships
Database System Concepts - 7th Edition 1.14 ©Silberschatz, Korth and Sudarshan
One-to-One Relationships For Roles
▪ Usually you will find just a few of the various types of 1:1 relationships in
every ER model.
▪ Mandatory at one end of the 1:1 relationship commonly occurs when roles
are modeled.
▪ Alternatively, TEACHER and STUDENT could have been modeled as
subtypes of PERSON, unless a PERSON can be both a TEACHER and a
STUDENT at the same time.
Database System Concepts - 7th Edition 1.15 ©Silberschatz, Korth and Sudarshan
One-to-One Relationships For Processes
▪ 1:1 relationships (of all three variations) also occur when some of the
entities represent various stages in a process.
▪ Mandatory 1:1 A 1:1 relationship, mandatory at both ends, tightly
connects two entities: when you create an instance of one entity, there
must be exactly one dedicated instance for the other simultaneously.
▪ This leads to the question why you want to make a distinction between the
two entities anyway. The only acceptable answer is: only if there is a
business need.
Database System Concepts - 7th Edition 1.16 ©Silberschatz, Korth and Sudarshan
Resolving Many-to-Many Relationships
Database System Concepts - 7th Edition 1.17 ©Silberschatz, Korth and Sudarshan
Purpose
▪ This lesson will help you complete your model -you may need to create
new entities or new relationships based on the business needs.
▪ It will also help you define the scope of your data model -you only model
what is of importance to the business.
Database System Concepts - 7th Edition 1.18 ©Silberschatz, Korth and Sudarshan
Relationship Hiding an Attribute
Database System Concepts - 7th Edition 1.19 ©Silberschatz, Korth and Sudarshan
Relationship Hiding an Attribute
Database System Concepts - 7th Edition 1.20 ©Silberschatz, Korth and Sudarshan
Resolution of a M:M Relationship
Database System Concepts - 7th Edition 1.21 ©Silberschatz, Korth and Sudarshan
Barred Relationships
▪ The unique identifier (UID) of the intersection entity often comes from the
originating relationships and is represented by the bars.
▪ In this case, the relationships from the originating entities to the
intersection entity are called "barred" relationships.
▪ Barred relationship: A relationship that participates in an entity's unique
identifier
Database System Concepts - 7th Edition 1.22 ©Silberschatz, Korth and Sudarshan
Documenting Business Rules
Database System Concepts - 7th Edition 1.23 ©Silberschatz, Korth and Sudarshan
Purpose
▪ One of the primary goals of data modeling is to ensure that all pieces of
information that are required to run a business are recognized.
▪ Identifying and documenting business rules are keys to checking your data
model for accuracy and completeness.
▪ It is important to recognize that not all business rules can be represented in
the ERD.
▪ Some business rules must be implemented by programming.
Database System Concepts - 7th Edition 1.24 ©Silberschatz, Korth and Sudarshan
Structural and Procedural Business Rules
Database System Concepts - 7th Edition 1.25 ©Silberschatz, Korth and Sudarshan
Structural Rule Example
Database System Concepts - 7th Edition 1.26 ©Silberschatz, Korth and Sudarshan
Rule Discussion
▪ Our University has many business rules that answer the following
questions:
▪ Is it reasonable/effective for a class not to have a lecturer assigned?
▪ Is it reasonable/effective for two students to have the same student id
number or no student id number at all?
▪ Is it reasonable to schedule a lecturer to teach a course if no students are
enrolled?
▪ Is it reasonable to allow someone to attend lectures/sit for final exams if
they are not enrolled in any classes?
Database System Concepts - 7th Edition 1.27 ©Silberschatz, Korth and Sudarshan
Procedural Rule Example
Database System Concepts - 7th Edition 1.28 ©Silberschatz, Korth and Sudarshan
Business Rule diagrammed in an ERD
Database System Concepts - 7th Edition 1.29 ©Silberschatz, Korth and Sudarshan
Procedural Rule Example
Database System Concepts - 7th Edition 1.30 ©Silberschatz, Korth and Sudarshan
Documenting Rules
Database System Concepts - 7th Edition 1.31 ©Silberschatz, Korth and Sudarshan
Understanding CRUD Requirements
Database System Concepts - 7th Edition 1.32 ©Silberschatz, Korth and Sudarshan
CRUD Analysis
Database System Concepts - 7th Edition 1.33 ©Silberschatz, Korth and Sudarshan
Purpose
▪ From the business scenarios that you develop and the list of business
rules that you identify during client interviews, you will build the ERD.
▪ The ERD is the conversation tool between the consultant and the client,
and it is also the blueprint for the DBA who will eventually build the
database.
▪ You need a way to check that you haven’t missed any entities or
relationships in your data model.
▪ You also want to ensure that you haven’t modeled anything that the
business does not require.
▪ CRUD analysis will help you do this.
▪ A good way to validate an ERD is to do a CRUD analysis on it.
Database System Concepts - 7th Edition 1.34 ©Silberschatz, Korth and Sudarshan
CRUD Analysis
Database System Concepts - 7th Edition 1.35 ©Silberschatz, Korth and Sudarshan
CRUD Analysis—Create Function
▪ During the client interview, and while writing the business scenarios and
rules, look for keywords like:
• INPUT, ENTER, LOAD, IMPORT, RECORD, & CREATE
▪ These all indicate that a record is created in the database at this time.
▪ Review the requirements for these keywords.
▪ Does your data model account for all of these functions?
Database System Concepts - 7th Edition 1.36 ©Silberschatz, Korth and Sudarshan
CRUD Analysis—Retrieve Function
▪ During the client interview, and while writing the business scenarios and
rules, look for keywords like:
• VIEW, REPORT, BRING UP, PRINT, FIND, READ, & LOOK UP
▪ These all point to retrieving information from the database.
▪ Review the requirements for these keywords.
▪ Does your data model account for all these functions?
Database System Concepts - 7th Edition 1.37 ©Silberschatz, Korth and Sudarshan
CRUD Analysis—Update Function
▪ During the client interview, and while writing the business scenarios and
rules, look for keywords like:
• CHANGE, MODIFY, ALTER, & UPDATE
▪ These all point to updating information that is already in the database.
▪ Review the requirements for these keywords.
▪ Does your data model account for all these functions?
Database System Concepts - 7th Edition 1.38 ©Silberschatz, Korth and Sudarshan
CRUD Analysis—Delete Function
▪ During the client interview, and while writing the business scenarios and
rules, look for keywords like:
• DISCARD, REMOVE, TRASH, PURGE, & DELETE
▪ These all point to deleting information that is already in the database.
▪ Review the requirements for these keywords.
▪ Does your data model account for all these functions?
▪ “A number of our customers were small businesses that were hit hard
by the recession. They went out of business. We deleted them from
our current records.” (DELETE)
Database System Concepts - 7th Edition 1.39 ©Silberschatz, Korth and Sudarshan
CRUD Validation
▪ Performing a CRUD analysis on your data model helps you check for
scope and completeness.
▪ If you have a business rule that has no entity to CRUD against, then your
data model may be incomplete.
▪ Similarly, if you have entities in your ERD that are not touched by any
CRUD function (no business rule creates, retrieves, updates, or deletes
from it), then you may not need that entity in your model.
Database System Concepts - 7th Edition 1.40 ©Silberschatz, Korth and Sudarshan
Artificial, Composite, and Secondary UIDs
Database System Concepts - 7th Edition 1.41 ©Silberschatz, Korth and Sudarshan
Purpose
Database System Concepts - 7th Edition 1.42 ©Silberschatz, Korth and Sudarshan
Simple UIDs vs. Composite UIDs
▪ The date of performance or seat number alone does not identify a concert
ticket. On any given date, there are many seats available. The same seat
number is sold for many different dates.
Database System Concepts - 7th Edition 1.43 ©Silberschatz, Korth and Sudarshan
Artificial UIDs
▪ Artificial UIDs are those that don’t occur in the natural world but are
created for purposes of identification in a system.
▪ People are not born with “numbers,” but a lot of systems assign unique
numbers to identify people: student numbers, customer IDs, etc.
Database System Concepts - 7th Edition 1.44 ©Silberschatz, Korth and Sudarshan
Artificial UIDs - Examples
Database System Concepts - 7th Edition 1.45 ©Silberschatz, Korth and Sudarshan
Artificial UID Example
Database System Concepts - 7th Edition 1.46 ©Silberschatz, Korth and Sudarshan
UID from Barred Relationship Intersection Entity
Database System Concepts - 7th Edition 1.47 ©Silberschatz, Korth and Sudarshan
Artificial UID Intersection Entity
Database System Concepts - 7th Edition 1.48 ©Silberschatz, Korth and Sudarshan
Artificial UID Intersection Entity
Database System Concepts - 7th Edition 1.49 ©Silberschatz, Korth and Sudarshan
Candidate UIDs
Database System Concepts - 7th Edition 1.50 ©Silberschatz, Korth and Sudarshan
Examples
Database System Concepts - 7th Edition 1.51 ©Silberschatz, Korth and Sudarshan
Candidate UIDs
Database System Concepts - 7th Edition 1.52 ©Silberschatz, Korth and Sudarshan
Key terms for your Review
▪ Nontransferable relationship
▪ Transferable relationship
▪ Redundant relationship
▪ Barred relationship
▪ Intersection entity
▪ CRUD Analysis
▪ Artificial UID
▪ Candidate UID
▪ Composite UID
▪ Primary UID
▪ Secondary UID
▪ Simple UID
▪ UID
Database System Concepts - 7th Edition 1.53 ©Silberschatz, Korth and Sudarshan