SlideShare a Scribd company logo
1 of 56
Download to read offline
DATABASE SCHEMA DESIGN
ENTITY-RELATIONSHIP
MODEL
slide credit: Caltech.edu
Designing Database Applications
¨
¨
¨
Database applications are large and complex
A few of the many design areas:
Also requires familiarity with the problem domain
¤
¤
¤
¤
Database schema (physical/logical/view)
Programs that access and update data
Security constraints for data access
Domain experts must help drive requirements
2
Database Design Process
1. Requirements analysis
• What is going to be stored?
• How is it going to be used?
• What are we going to do with the data?
• Who should access the data?
1. Requirements Anallysis 2.
. Conceptual Desiign 3. Logical, Physical, Security, etc.
3
2. Conceptual Design
• A high-level description of the database
• Sufficiently precise that technical people can understand it
• But, not so precise that non-technical people cannot
participate
Database Design Process
1. Requirements Anallysis 2.
. Conceptual Desiign 3. Logical, Physical, Security, etc.
4
Database Design Process
1. Requirements Anallysis 2.
. Conceptual Desiign 3. Logical, Physical, Security, etc.
5
3. Implementation:
• Logical Database Design
• Physical Database Design
• Security Design
ER is a visual syntax for DB design which is precise
eno ugh for technical points, but abstracted enou gh for
non-technical people.
Database Design Process
1. Requirements Anallysis 2.
. Conceptual Desiign 3. Logical, Physical, Security, etc.
Makes
Product
name category
price
Company
name
ER Model & Diagrams
6
General Approach
3
¨
¨
Collect user requirements
Develop a conceptual schema of the database
¤
¤
¤
¤
¤
¤
Information that needs to be represented
Operations to perform on that information
Several techniques for representing this info, e.g. UML
A high-level representation of the database’s structure and
Constraints
• Physical and logical design issues are ignored at this stage
Follows a specific data model
Often represented graphically
Conceptual Schema
¨
¨
Also need to create a specification of functional
requirements
Designer can use functional requirements to verify the
conceptual schema
¤
¤
¤
¤
¤
Is each operation possible?
How complicated or involved is it?
Performance or scalability concerns?
“What operations will be performed against the data?”
Updating data, adding data, deleting data, …
4
Implementation Phases
¨ Finally: any necessary physical design
¨Once conceptual schema and functional requirements
are verified:
• Convert conceptual schema into an implementation data Model
• Want to have a simple mapping from conceptual model to implementation model
• Not always present!
• Smaller applications have few physical design concerns
• Larger systems usually need additional design and tuning (e.g. indexes, disk-level
partitioning of data)
5
Importance of Design Phase
¨
¨
¨
¨
Not all changes have the same impact!
Physical-level changes have the least impact
Logical-level changes are typically much bigger
Very important to spend time up front designing the
database schema
¤
¤
¤
¤
¤
(Thanks, relational model!)
Typically affect performance, scalability, reliability
Little to no change in functionality
Affects how to interact with the data…
Also affects what is even possible to do with the data
6
Design Decisions
¨
¨
Many different ways to represent data
Must avoid two major problems:
¤
¤
Unnecessary redundancy
Incomplete representation
• Redundant information wastes space
• Greater potential for inconsistency!
• Ideally: each fact appears in exactly one place
• Schema must be able to fully represent all details and
relationships required by the application
7
More Design Decisions
8
¨
¨
Even with correct design, usually many other concerns
Schema design requires a good balance between
aesthetic and practical concerns
¤ Frequently need to make compromises between
conflicting design principles
• How easy/hard is it to access useful information?
(e.g. reporting or summary info)
• How hard is it to update the system?
• Performance considerations?
• Scalability considerations?
The Entity-Relationship Model
• A very common model for schema design
• Also written as “E-R model”
• Allows for specification of complex schemas in graphical form
• Basic concepts are simple, but can also represent very sophisticated
abstractions (e.g. type hierarchies)
• Can be mapped very easily to the relational model!
• Simplifies implementation phase
• Mapping process can be automated by design tools
1
0
Entities and Entity-Sets
• An entity is any “thing” that can be uniquely represented
• An entity-set is a named collection of entities of the
same type, with the same attributes
¤
e.g. a product, an employee, a software defect
¤
¤
Can have multiple entity-sets with same entity type,
representing different (possibly overlapping) sets
Each entity has a set of attributes
Entities are uniquely identified by some set of attributes
1
1
Entities and Entity-Sets (2)
¨
¨
An entity has a set of attributes
Entity-sets also specify a set of attributes
¤
¤
¤
¤
Each attribute has a name and domain
Each attribute also has a corresponding value
Every entity in the entity-set has the same set of
attributes
Every entity in the entity-set has its own value for each
attribute
1
2
Diagramming an Entity-Set
Example: a customer entity-set
¨ Attributes:
Entity-set is denoted by a box
Name of entity-set is given in the top part of box
Attributes are listed in the lower part of the box
¨
¨
¨
¤
¤
¤
¤
cust_id
name
street_address
city
customer
cust_id
name
street_address
city
1
3
Entities and Entity Sets
• Entities & entity types are the primitive
units of the ER model
• Entities are the individual objects (instances),
which are members of entity types
• Entity type are the classes or types of objects
in our model
• Example: Person is an entity type while
Michael is an entity.
• We use entity types in ER models
Product
Person
17
Entities and Entity Types
• An entity type has attributes
represented by ovals attached to an
entity type
name category
price
Product
Shapes are
important. Colors
used here are
not.
18
Entities vs. Entity Sets
Example:
Product
name category
price
Entity type
Product
Name: Xbox
Category:
Gamming Console
Price: $250
Name: My Little Pony Doll
Category: Toy
Price: $25
Entity
Entity
Attribute
Entities are not explicitly
represented in ER
diagrams!
19
Keys
A key is a minimal set of attributes that uniquely identifies an entity.
name category
price
Denote elements of
the primary key by
underlining.
Here, {name, category} is
not a key (it is not minimal).
If it were, what would it
mean?
Product
The ER model forces us to designate a single primary key, though
there may be multiple candidate keys. Often, we introduce an artificial
key attribute (also called a synthetic or surrogate key).
20
Entity Types Define Relations
name category
price
Product
category price
name
$9.99
Electronics
Gizmo
$7.50
Electronics
GizmoLite
$5.50
Toys
Gadget
Product
21
Relationships
• A relationship is an association between two or more entities
• e.g. a bank loan, and the customer who owns it
• A relationship-set is a named collection of relationships of the
same type
• i.e. involving the same entities
• Formally, a relationship-set is a mathematical relation involving
nentity-sets, n≥ 2
1
4
Relationships (2)
¨
¨
Entity-sets participate in relationship-sets
Example: bank loans
• Specific entities participate in a relationship instance
• Customer and loan are entity-sets
• (555-55-5555, Jackson, Woodside) is a customer entity and
(L-14, 1500) is a loan entity
• Borrower is a relationship-set
• customer and loan participate in borrower
• borrower contains a relationship instance that associates customer
“Jackson” and loan “L-14”
1
5
Relationships and Roles
¨
¨ Roles are usually obvious, and therefore unspecified
An entity’s role in a relationship is the function that the
entity fills
Example: a purchase relationship between a product
and a customer
• The product’s role is that it was purchased
• The customer did the purchasing
• Entities participating in relationships are distinct…
• Names clearly indicate the roles of various
entities…
• In these cases, roles are left unstated.
1
6
Relationships and Roles (2)
• Sometimes the roles of entities are not obvious
• Example: a relationship-set named works_for, specifying
employee/manager assignments
Situations where entity-sets in a relationship-set are not distinct
Roles are given names to distinguish entities
• Relationship involves two entities, and both are employee entities
• The relationship is a set of entities ordered by role:
(manager, worker)
• First entity’s role is named manager, Second entity’s role is named
worker
1
7
The R in ER: Relationships
• A relationship type is between two entity types
15
Product
name category
price
Company
name
Makes
How to read a relationship in both directions:
1. A product is made by a company
2. A company makes a product
16
makes
Product
name category
price
buys
Person
address name ssn
Company
stockprice
name
What is a Relationship?
category price
name
$9.99
Electronics
Gizmo
$7.50
Electronics
GizmoLite
$5.50
Toys
Gadget
name
GizmoWorks
GadgetCorp
Company Product
Makes
Product
name category
price
Company
name
A relationship between entity sets P
and C is a subset of all possible pairs
of entities in P and C, with tuples
uniquely identified by P and C’s keys
28
What is a Relationship?
category price
name
name
$9.99
Electronics
Gizmo
GizmoWorks
$7.50
Electronics
GizmoLite
GadgetCorp
$5.50
Toys
Gadget
Company Product
P.category P.price
P.name
C.name
$9.99
Electronics
Gizmo
GizmoWorks
$7.50
Electronics
GizmoLite
GizmoWorks
$5.50
Toys
Gadget
GizmoWorks
$9.99
Electronics
Gizmo
GadgetCorp
$7.50
Electronics
GizmoLite
GadgetCorp
$5.50
Toys
Gadget
GadgetCorp
Company C x Product P
Makes
Product
name category
price
Company
name
A relationship between entity sets P
and C is a subset of all possible pairs
of entities in P and C, with tuples
uniquely identified by P and C’s keys
29
What is a Relationship?
category price
name
$9.99
Electronics
Gizmo
$7.50
Electronics
GizmoLite
$5.50
Toys
Gadget
name
GizmoWorks
GadgetCorp
Company Product
P.category P.price
P.name
C.name
$9.99
Electronics
Gizmo
GizmoWorks
$7.50
Electronics
GizmoLite
GizmoWorks
$5.50
Toys
Gadget
GizmoWorks
$9.99
Electronics
Gizmo
GadgetCorp
$7.50
Electronics
GizmoLite
GadgetCorp
$5.50
Toys
Gadget
GadgetCorp
Company C x Product P
P.name
C.name
Gizmo
GizmoWorks
GizmoLite
GizmoWorks
Gadget
GadgetCorp
Makes
Makes
Product
name category
price
Company
name
A relationship between entity sets P
and C is a subset of all possible pairs
of entities in P and C, with tuples
uniquely identified by P and C’s keys
30
What is a Relationship?
• There can only be one relationship for every
unique combination of entities
• This also means that the relationship is
uniquely determined by the keys of its entities
• Example: the key for Makes (to right) is
{Product.name, Company.name}
24
This follows from our
mathematical definition
of a relationship (it is a
set)
Makes
Product
name category
price
Company
name
25
Product
name category
price
Company
name
Makes
since
Relationships may have attributes as well.
For example: “since”
records when company
started making a
product
Note: For each product/company
pair there is automatically only a
single since value since there
can only be one unique product/
company pair in makes.
Relationships and Attributes
Decision: Relationship vs. Entity?
Purchased
Product
name category
price
Person
name
Q: What does this say?
date
A: A person can only buy a specific product once per day (date)
Modeling something as a relationship makes it
unique. What if this is not appropriate?
34
Decision: Relationship vs. Entity?
What about this way?
Product
name category
price
Person
name
date
Purchase
quantity
PID#
ProductOf BuyerOf
Now we can have multiple purchases per product, person pair!
We can always use a new entity instead of a relationship.
For example, to permit multiple instances of each entity
combination!
35
Note on Relationships vs. Relation
28
category price
name
$9.99
Electronics
Gizmo
$7.50
Electronics
GizmoLite
$5.50
Toys
Gadget
Makes
Product
name category
price
Company
name
Relationship/Relationship type Relation
Product
ER Model: How do Entity types relate to each other Math: A Relation
Relational Algebra: A table with data (a set)
Relations are used to implement entity types and certain
relationship types!
Degree of Relationship Set
• Most relationships in a schema are binary
• Sometimes there are ternary relationships
• The number of entity-sets that participate in a relationship-set
is called its degree
• Binary relationship: degree = 2
• Ternary relationship: degree = 3
• Two entities are involved in the relationship
• Three entities are involved
• Far less common, but still useful at times
2
0
Attribute Source
¨
¨
Base attributes (aka source attributes) are stored in
the database
¤ e.g. the birth_date of a customer entity
Derived attributes are computed from other
attributes
¤ e.g. the age of a customer entity would be computed
from their birth_date
2
4
Diagramming Attributes
¨ Example: Extend customers with more detailed info
¨ Composite attributes are shown
as a hierarchy of values
¤
¤
Indented values are components of
the higher-level value
e.g. name is comprised of
first_name, middle_initial,
and last_name
customer
cust_id
name
first_name
middle_initial
last_name
address
street
city
state
zip_code
2
5
Diagramming Attributes (2)
• Example: Extend customers with more detailed info
• Multivalued attributes are enclosed with curly-braces
e.g. each customer can have zero or more
phone numbers
customer
cust_id
name
first_name
middle_initial
last_name
address
street
city
state
zip_code
{phone_number}
2
6
Diagramming Attributes (3)
¨ Example: Extend customers with more detailed info
¨ Derived attributes are indicated
by a trailing set of parentheses ()
¤
¤
e.g. each customer has a base attribute
recording their date of birth
Also a derived attribute that reports
the customer’s current age
customer
cust_id
name
first_name
middle_initial
last_name
address
street
city
state
zip_code
{ phone_number}
birth_date
age ()
2
7
Representing Constraints
¨ E-R model can represent different kinds of constraints
¨Allows more accurate modeling of application’s data
requirements
¤
¨Enforcing constraints can impact performance…
¤
¤
¤
¤
Mapping cardinalities
Key constraints in entity-sets Participation
Constrain design so that schema can only represent valid
information
Still ought to specify them in the design!
Can always leave out constraints at implementation time
2
8
Mapping Cardinalities
¨
¨
¨
Example:
¨Mapping cardinality represents:
Also known as the cardinality ratio
Easiest to reason about with binary relationships
“How many other entities can be associated with an entity, via a
particular relationship set?”
How many customer entities can the borrower relationship
associate with a single loan entity?
How many loans can borrower relationship associate with a
single customer entity?
Specific answer depends on what is being modeled
¤
¤
¤
2
9
Mapping Cardinalities (5)
¨ Goal:
¤
¨Which mapping cardinality is most appropriate for a
given relationship?
¤
¤
¤
¤
Answer depends on what you are trying to model!
Could just use many-to-many relationships everywhere, but
that would be dumb.
Constrain the mapping cardinality to most accurately reflect
what should be allowed
Database can enforce these constraints automatically
Good schema design reduces or eliminates the possibility of
storing bad data
3
3
Diagramming Cardinalities
¨ In relationship-set diagrams:
¤
¤
¤
an arrow towards an entity represents “one”
a simple line represents “many”
arrow is always towards the entity
3
5
Construct an E-R diagram for a hospital with a
set of patients and a set of doctors. Associate
with each patient a log of the various tests and
examinations conducted by the doctors
ER diagram slides for datanase stujdy-1.pdf

More Related Content

Similar to ER diagram slides for datanase stujdy-1.pdf

Data and functional modeling
Data and functional modelingData and functional modeling
Data and functional modelingSlideshare
 
Salesforce Training Institute & Courses Pune | SFDC Training PCMC
Salesforce Training Institute & Courses Pune | SFDC Training PCMCSalesforce Training Institute & Courses Pune | SFDC Training PCMC
Salesforce Training Institute & Courses Pune | SFDC Training PCMCvictoriousdigital
 
Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...
Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...
Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...Massimo Cenci
 
Non-functional requirements
Non-functional requirements Non-functional requirements
Non-functional requirements Rohela Raouf
 
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Karen Thompson
 
Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)Zhang Bo
 
Object-Oriented Systems Analysis and Design Using UML.pptx
Object-Oriented Systems Analysis and Design Using UML.pptxObject-Oriented Systems Analysis and Design Using UML.pptx
Object-Oriented Systems Analysis and Design Using UML.pptxXanGwaps
 
iOS Beginners Lesson 1
iOS Beginners Lesson 1iOS Beginners Lesson 1
iOS Beginners Lesson 1Calvin Cheng
 
Common Data Model - A Business Database!
Common Data Model - A Business Database!Common Data Model - A Business Database!
Common Data Model - A Business Database!Pedro Azevedo
 
Entity-Relationship Data Model
Entity-Relationship Data ModelEntity-Relationship Data Model
Entity-Relationship Data ModelBishrul Haq
 
Chapter – 2 Data Models.pdf
Chapter – 2 Data Models.pdfChapter – 2 Data Models.pdf
Chapter – 2 Data Models.pdfTamiratDejene1
 
Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "AchrafJbr
 
Object oriented analysis and design
Object oriented analysis and designObject oriented analysis and design
Object oriented analysis and designnaveed428
 

Similar to ER diagram slides for datanase stujdy-1.pdf (20)

Data and functional modeling
Data and functional modelingData and functional modeling
Data and functional modeling
 
Software Design
Software DesignSoftware Design
Software Design
 
Analysis
AnalysisAnalysis
Analysis
 
Salesforce Training Institute & Courses Pune | SFDC Training PCMC
Salesforce Training Institute & Courses Pune | SFDC Training PCMCSalesforce Training Institute & Courses Pune | SFDC Training PCMC
Salesforce Training Institute & Courses Pune | SFDC Training PCMC
 
Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...
Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...
Recipes 6 of Data Warehouse and Business Intelligence - Naming convention tec...
 
Non-functional requirements
Non-functional requirements Non-functional requirements
Non-functional requirements
 
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
Cis 555 Week 4 Assignment 2 Automated Teller Machine (Atm)...
 
Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)Data massage! databases scaled from one to one million nodes (ulf wendel)
Data massage! databases scaled from one to one million nodes (ulf wendel)
 
Ch05lect1 ud
Ch05lect1 udCh05lect1 ud
Ch05lect1 ud
 
Database design
Database designDatabase design
Database design
 
Object-Oriented Systems Analysis and Design Using UML.pptx
Object-Oriented Systems Analysis and Design Using UML.pptxObject-Oriented Systems Analysis and Design Using UML.pptx
Object-Oriented Systems Analysis and Design Using UML.pptx
 
iOS Beginners Lesson 1
iOS Beginners Lesson 1iOS Beginners Lesson 1
iOS Beginners Lesson 1
 
Common Data Model - A Business Database!
Common Data Model - A Business Database!Common Data Model - A Business Database!
Common Data Model - A Business Database!
 
Entity-Relationship Data Model
Entity-Relationship Data ModelEntity-Relationship Data Model
Entity-Relationship Data Model
 
Chapter – 2 Data Models.pdf
Chapter – 2 Data Models.pdfChapter – 2 Data Models.pdf
Chapter – 2 Data Models.pdf
 
Database system
Database system Database system
Database system
 
Object Modelling Technique " ooad "
Object Modelling Technique  " ooad "Object Modelling Technique  " ooad "
Object Modelling Technique " ooad "
 
BDD Primer
BDD PrimerBDD Primer
BDD Primer
 
Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
 
Object oriented analysis and design
Object oriented analysis and designObject oriented analysis and design
Object oriented analysis and design
 

More from SadiaSharmin40

16807097.ppt b tree are a good data structure
16807097.ppt b tree are a good data structure16807097.ppt b tree are a good data structure
16807097.ppt b tree are a good data structureSadiaSharmin40
 
chap09alg.ppt for string matching algorithm
chap09alg.ppt for string matching algorithmchap09alg.ppt for string matching algorithm
chap09alg.ppt for string matching algorithmSadiaSharmin40
 
brown.ppt for identifying rabin karp algo
brown.ppt for identifying rabin karp algobrown.ppt for identifying rabin karp algo
brown.ppt for identifying rabin karp algoSadiaSharmin40
 
huffman algoritm upload for understand.ppt
huffman algoritm upload for understand.ppthuffman algoritm upload for understand.ppt
huffman algoritm upload for understand.pptSadiaSharmin40
 
HuffmanStudent.ppt used to show how huffman code
HuffmanStudent.ppt used to show how huffman codeHuffmanStudent.ppt used to show how huffman code
HuffmanStudent.ppt used to show how huffman codeSadiaSharmin40
 
08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertexSadiaSharmin40
 
MergeSort.ppt shows how merge sort is done
MergeSort.ppt shows how merge sort is doneMergeSort.ppt shows how merge sort is done
MergeSort.ppt shows how merge sort is doneSadiaSharmin40
 
how to use counting sort algorithm to sort array
how to use counting sort algorithm to sort arrayhow to use counting sort algorithm to sort array
how to use counting sort algorithm to sort arraySadiaSharmin40
 

More from SadiaSharmin40 (8)

16807097.ppt b tree are a good data structure
16807097.ppt b tree are a good data structure16807097.ppt b tree are a good data structure
16807097.ppt b tree are a good data structure
 
chap09alg.ppt for string matching algorithm
chap09alg.ppt for string matching algorithmchap09alg.ppt for string matching algorithm
chap09alg.ppt for string matching algorithm
 
brown.ppt for identifying rabin karp algo
brown.ppt for identifying rabin karp algobrown.ppt for identifying rabin karp algo
brown.ppt for identifying rabin karp algo
 
huffman algoritm upload for understand.ppt
huffman algoritm upload for understand.ppthuffman algoritm upload for understand.ppt
huffman algoritm upload for understand.ppt
 
HuffmanStudent.ppt used to show how huffman code
HuffmanStudent.ppt used to show how huffman codeHuffmanStudent.ppt used to show how huffman code
HuffmanStudent.ppt used to show how huffman code
 
08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex
 
MergeSort.ppt shows how merge sort is done
MergeSort.ppt shows how merge sort is doneMergeSort.ppt shows how merge sort is done
MergeSort.ppt shows how merge sort is done
 
how to use counting sort algorithm to sort array
how to use counting sort algorithm to sort arrayhow to use counting sort algorithm to sort array
how to use counting sort algorithm to sort array
 

Recently uploaded

HIGH PRESSURE PROCESSING ( HPP ) .pptx
HIGH PRESSURE  PROCESSING ( HPP )  .pptxHIGH PRESSURE  PROCESSING ( HPP )  .pptx
HIGH PRESSURE PROCESSING ( HPP ) .pptxparvin6647
 
Estimation of protein quality using various methods
Estimation of protein quality using various methodsEstimation of protein quality using various methods
Estimation of protein quality using various methodsThiviKutty
 
Affordable PriceD Call Girls In Crowne Plaza Greater Noida 8377877756 Short 2...
Affordable PriceD Call Girls In Crowne Plaza Greater Noida 8377877756 Short 2...Affordable PriceD Call Girls In Crowne Plaza Greater Noida 8377877756 Short 2...
Affordable PriceD Call Girls In Crowne Plaza Greater Noida 8377877756 Short 2...dollysharma2066
 
Planning your Restaurant's Path to Profitability
Planning your Restaurant's Path to ProfitabilityPlanning your Restaurant's Path to Profitability
Planning your Restaurant's Path to ProfitabilityAggregage
 
Irradiation preservation of food advancements
Irradiation preservation of food advancementsIrradiation preservation of food advancements
Irradiation preservation of food advancementsDeepika Sugumar
 
Call Girls Laxmi Nagar Delhi reach out to us at ☎ 9711199012
Call Girls Laxmi Nagar Delhi reach out to us at ☎ 9711199012Call Girls Laxmi Nagar Delhi reach out to us at ☎ 9711199012
Call Girls Laxmi Nagar Delhi reach out to us at ☎ 9711199012rehmti665
 
VIP Kolkata Call Girl Jadavpur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Jadavpur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Jadavpur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Jadavpur 👉 8250192130 Available With Roomdivyansh0kumar0
 
Chocolate Milk Flavorful Indulgence to RD UHT Innovations.pptx
Chocolate Milk Flavorful Indulgence to RD UHT Innovations.pptxChocolate Milk Flavorful Indulgence to RD UHT Innovations.pptx
Chocolate Milk Flavorful Indulgence to RD UHT Innovations.pptxRD Food
 
Food-Allergy-PowerPoint-Presentation-2.ppt
Food-Allergy-PowerPoint-Presentation-2.pptFood-Allergy-PowerPoint-Presentation-2.ppt
Food-Allergy-PowerPoint-Presentation-2.pptIsaacMensah62
 
Gwal Pahari Call Girls 9873940964 Book Hot And Sexy Girls
Gwal Pahari Call Girls 9873940964 Book Hot And Sexy GirlsGwal Pahari Call Girls 9873940964 Book Hot And Sexy Girls
Gwal Pahari Call Girls 9873940964 Book Hot And Sexy Girlshram8477
 
(办理学位证)加州大学圣塔芭芭拉分校毕业证成绩单原版一比一
(办理学位证)加州大学圣塔芭芭拉分校毕业证成绩单原版一比一(办理学位证)加州大学圣塔芭芭拉分校毕业证成绩单原版一比一
(办理学位证)加州大学圣塔芭芭拉分校毕业证成绩单原版一比一Fi sss
 
Russian Escorts DELHI - Russian Call Girls in Delhi Greater Kailash TELL-NO. ...
Russian Escorts DELHI - Russian Call Girls in Delhi Greater Kailash TELL-NO. ...Russian Escorts DELHI - Russian Call Girls in Delhi Greater Kailash TELL-NO. ...
Russian Escorts DELHI - Russian Call Girls in Delhi Greater Kailash TELL-NO. ...dollysharma2066
 
526350093-Online-Food-Ordering-System-Ppt.pptx
526350093-Online-Food-Ordering-System-Ppt.pptx526350093-Online-Food-Ordering-System-Ppt.pptx
526350093-Online-Food-Ordering-System-Ppt.pptxJaidBagwan2
 
Call Girls in Ghitorni Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Ghitorni Delhi 💯Call Us 🔝8264348440🔝Call Girls in Ghitorni Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Ghitorni Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Prepare And Cook Meat.pptx Quarter II Module
Prepare And Cook Meat.pptx Quarter II ModulePrepare And Cook Meat.pptx Quarter II Module
Prepare And Cook Meat.pptx Quarter II Modulemaricel769799
 
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile ServiceJp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile ServiceHigh Profile Call Girls
 
thanksgiving dinner and more information
thanksgiving dinner and more informationthanksgiving dinner and more information
thanksgiving dinner and more informationlialiaskou00
 
FUTURISTIC FOOD PRODUCTS OFTEN INVOLVE INNOVATIONS THAT
FUTURISTIC FOOD PRODUCTS OFTEN INVOLVE INNOVATIONS THATFUTURISTIC FOOD PRODUCTS OFTEN INVOLVE INNOVATIONS THAT
FUTURISTIC FOOD PRODUCTS OFTEN INVOLVE INNOVATIONS THATBHIKHUKUMAR KUNWARADIYA
 

Recently uploaded (20)

HIGH PRESSURE PROCESSING ( HPP ) .pptx
HIGH PRESSURE  PROCESSING ( HPP )  .pptxHIGH PRESSURE  PROCESSING ( HPP )  .pptx
HIGH PRESSURE PROCESSING ( HPP ) .pptx
 
Estimation of protein quality using various methods
Estimation of protein quality using various methodsEstimation of protein quality using various methods
Estimation of protein quality using various methods
 
Affordable PriceD Call Girls In Crowne Plaza Greater Noida 8377877756 Short 2...
Affordable PriceD Call Girls In Crowne Plaza Greater Noida 8377877756 Short 2...Affordable PriceD Call Girls In Crowne Plaza Greater Noida 8377877756 Short 2...
Affordable PriceD Call Girls In Crowne Plaza Greater Noida 8377877756 Short 2...
 
Planning your Restaurant's Path to Profitability
Planning your Restaurant's Path to ProfitabilityPlanning your Restaurant's Path to Profitability
Planning your Restaurant's Path to Profitability
 
Irradiation preservation of food advancements
Irradiation preservation of food advancementsIrradiation preservation of food advancements
Irradiation preservation of food advancements
 
Call Girls Laxmi Nagar Delhi reach out to us at ☎ 9711199012
Call Girls Laxmi Nagar Delhi reach out to us at ☎ 9711199012Call Girls Laxmi Nagar Delhi reach out to us at ☎ 9711199012
Call Girls Laxmi Nagar Delhi reach out to us at ☎ 9711199012
 
VIP Kolkata Call Girl Jadavpur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Jadavpur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Jadavpur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Jadavpur 👉 8250192130 Available With Room
 
Chocolate Milk Flavorful Indulgence to RD UHT Innovations.pptx
Chocolate Milk Flavorful Indulgence to RD UHT Innovations.pptxChocolate Milk Flavorful Indulgence to RD UHT Innovations.pptx
Chocolate Milk Flavorful Indulgence to RD UHT Innovations.pptx
 
Food-Allergy-PowerPoint-Presentation-2.ppt
Food-Allergy-PowerPoint-Presentation-2.pptFood-Allergy-PowerPoint-Presentation-2.ppt
Food-Allergy-PowerPoint-Presentation-2.ppt
 
Gwal Pahari Call Girls 9873940964 Book Hot And Sexy Girls
Gwal Pahari Call Girls 9873940964 Book Hot And Sexy GirlsGwal Pahari Call Girls 9873940964 Book Hot And Sexy Girls
Gwal Pahari Call Girls 9873940964 Book Hot And Sexy Girls
 
(办理学位证)加州大学圣塔芭芭拉分校毕业证成绩单原版一比一
(办理学位证)加州大学圣塔芭芭拉分校毕业证成绩单原版一比一(办理学位证)加州大学圣塔芭芭拉分校毕业证成绩单原版一比一
(办理学位证)加州大学圣塔芭芭拉分校毕业证成绩单原版一比一
 
Russian Escorts DELHI - Russian Call Girls in Delhi Greater Kailash TELL-NO. ...
Russian Escorts DELHI - Russian Call Girls in Delhi Greater Kailash TELL-NO. ...Russian Escorts DELHI - Russian Call Girls in Delhi Greater Kailash TELL-NO. ...
Russian Escorts DELHI - Russian Call Girls in Delhi Greater Kailash TELL-NO. ...
 
526350093-Online-Food-Ordering-System-Ppt.pptx
526350093-Online-Food-Ordering-System-Ppt.pptx526350093-Online-Food-Ordering-System-Ppt.pptx
526350093-Online-Food-Ordering-System-Ppt.pptx
 
Call Girls in Ghitorni Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Ghitorni Delhi 💯Call Us 🔝8264348440🔝Call Girls in Ghitorni Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Ghitorni Delhi 💯Call Us 🔝8264348440🔝
 
Prepare And Cook Meat.pptx Quarter II Module
Prepare And Cook Meat.pptx Quarter II ModulePrepare And Cook Meat.pptx Quarter II Module
Prepare And Cook Meat.pptx Quarter II Module
 
Cut & fry Potato is Not FRENCH FRIES ..
Cut & fry Potato is Not FRENCH FRIES  ..Cut & fry Potato is Not FRENCH FRIES  ..
Cut & fry Potato is Not FRENCH FRIES ..
 
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile ServiceJp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Jp Nagar Call Girls Bangalore WhatsApp 8250192130 High Profile Service
 
9953330565 Low Rate Call Girls In Sameypur-Bodli Delhi NCR
9953330565 Low Rate Call Girls In Sameypur-Bodli Delhi NCR9953330565 Low Rate Call Girls In Sameypur-Bodli Delhi NCR
9953330565 Low Rate Call Girls In Sameypur-Bodli Delhi NCR
 
thanksgiving dinner and more information
thanksgiving dinner and more informationthanksgiving dinner and more information
thanksgiving dinner and more information
 
FUTURISTIC FOOD PRODUCTS OFTEN INVOLVE INNOVATIONS THAT
FUTURISTIC FOOD PRODUCTS OFTEN INVOLVE INNOVATIONS THATFUTURISTIC FOOD PRODUCTS OFTEN INVOLVE INNOVATIONS THAT
FUTURISTIC FOOD PRODUCTS OFTEN INVOLVE INNOVATIONS THAT
 

ER diagram slides for datanase stujdy-1.pdf

  • 2. Designing Database Applications ¨ ¨ ¨ Database applications are large and complex A few of the many design areas: Also requires familiarity with the problem domain ¤ ¤ ¤ ¤ Database schema (physical/logical/view) Programs that access and update data Security constraints for data access Domain experts must help drive requirements 2
  • 3. Database Design Process 1. Requirements analysis • What is going to be stored? • How is it going to be used? • What are we going to do with the data? • Who should access the data? 1. Requirements Anallysis 2. . Conceptual Desiign 3. Logical, Physical, Security, etc. 3
  • 4. 2. Conceptual Design • A high-level description of the database • Sufficiently precise that technical people can understand it • But, not so precise that non-technical people cannot participate Database Design Process 1. Requirements Anallysis 2. . Conceptual Desiign 3. Logical, Physical, Security, etc. 4
  • 5. Database Design Process 1. Requirements Anallysis 2. . Conceptual Desiign 3. Logical, Physical, Security, etc. 5 3. Implementation: • Logical Database Design • Physical Database Design • Security Design
  • 6. ER is a visual syntax for DB design which is precise eno ugh for technical points, but abstracted enou gh for non-technical people. Database Design Process 1. Requirements Anallysis 2. . Conceptual Desiign 3. Logical, Physical, Security, etc. Makes Product name category price Company name ER Model & Diagrams 6
  • 7. General Approach 3 ¨ ¨ Collect user requirements Develop a conceptual schema of the database ¤ ¤ ¤ ¤ ¤ ¤ Information that needs to be represented Operations to perform on that information Several techniques for representing this info, e.g. UML A high-level representation of the database’s structure and Constraints • Physical and logical design issues are ignored at this stage Follows a specific data model Often represented graphically
  • 8. Conceptual Schema ¨ ¨ Also need to create a specification of functional requirements Designer can use functional requirements to verify the conceptual schema ¤ ¤ ¤ ¤ ¤ Is each operation possible? How complicated or involved is it? Performance or scalability concerns? “What operations will be performed against the data?” Updating data, adding data, deleting data, … 4
  • 9. Implementation Phases ¨ Finally: any necessary physical design ¨Once conceptual schema and functional requirements are verified: • Convert conceptual schema into an implementation data Model • Want to have a simple mapping from conceptual model to implementation model • Not always present! • Smaller applications have few physical design concerns • Larger systems usually need additional design and tuning (e.g. indexes, disk-level partitioning of data) 5
  • 10. Importance of Design Phase ¨ ¨ ¨ ¨ Not all changes have the same impact! Physical-level changes have the least impact Logical-level changes are typically much bigger Very important to spend time up front designing the database schema ¤ ¤ ¤ ¤ ¤ (Thanks, relational model!) Typically affect performance, scalability, reliability Little to no change in functionality Affects how to interact with the data… Also affects what is even possible to do with the data 6
  • 11. Design Decisions ¨ ¨ Many different ways to represent data Must avoid two major problems: ¤ ¤ Unnecessary redundancy Incomplete representation • Redundant information wastes space • Greater potential for inconsistency! • Ideally: each fact appears in exactly one place • Schema must be able to fully represent all details and relationships required by the application 7
  • 12. More Design Decisions 8 ¨ ¨ Even with correct design, usually many other concerns Schema design requires a good balance between aesthetic and practical concerns ¤ Frequently need to make compromises between conflicting design principles • How easy/hard is it to access useful information? (e.g. reporting or summary info) • How hard is it to update the system? • Performance considerations? • Scalability considerations?
  • 13. The Entity-Relationship Model • A very common model for schema design • Also written as “E-R model” • Allows for specification of complex schemas in graphical form • Basic concepts are simple, but can also represent very sophisticated abstractions (e.g. type hierarchies) • Can be mapped very easily to the relational model! • Simplifies implementation phase • Mapping process can be automated by design tools 1 0
  • 14. Entities and Entity-Sets • An entity is any “thing” that can be uniquely represented • An entity-set is a named collection of entities of the same type, with the same attributes ¤ e.g. a product, an employee, a software defect ¤ ¤ Can have multiple entity-sets with same entity type, representing different (possibly overlapping) sets Each entity has a set of attributes Entities are uniquely identified by some set of attributes 1 1
  • 15. Entities and Entity-Sets (2) ¨ ¨ An entity has a set of attributes Entity-sets also specify a set of attributes ¤ ¤ ¤ ¤ Each attribute has a name and domain Each attribute also has a corresponding value Every entity in the entity-set has the same set of attributes Every entity in the entity-set has its own value for each attribute 1 2
  • 16. Diagramming an Entity-Set Example: a customer entity-set ¨ Attributes: Entity-set is denoted by a box Name of entity-set is given in the top part of box Attributes are listed in the lower part of the box ¨ ¨ ¨ ¤ ¤ ¤ ¤ cust_id name street_address city customer cust_id name street_address city 1 3
  • 17. Entities and Entity Sets • Entities & entity types are the primitive units of the ER model • Entities are the individual objects (instances), which are members of entity types • Entity type are the classes or types of objects in our model • Example: Person is an entity type while Michael is an entity. • We use entity types in ER models Product Person 17
  • 18. Entities and Entity Types • An entity type has attributes represented by ovals attached to an entity type name category price Product Shapes are important. Colors used here are not. 18
  • 19. Entities vs. Entity Sets Example: Product name category price Entity type Product Name: Xbox Category: Gamming Console Price: $250 Name: My Little Pony Doll Category: Toy Price: $25 Entity Entity Attribute Entities are not explicitly represented in ER diagrams! 19
  • 20. Keys A key is a minimal set of attributes that uniquely identifies an entity. name category price Denote elements of the primary key by underlining. Here, {name, category} is not a key (it is not minimal). If it were, what would it mean? Product The ER model forces us to designate a single primary key, though there may be multiple candidate keys. Often, we introduce an artificial key attribute (also called a synthetic or surrogate key). 20
  • 21. Entity Types Define Relations name category price Product category price name $9.99 Electronics Gizmo $7.50 Electronics GizmoLite $5.50 Toys Gadget Product 21
  • 22. Relationships • A relationship is an association between two or more entities • e.g. a bank loan, and the customer who owns it • A relationship-set is a named collection of relationships of the same type • i.e. involving the same entities • Formally, a relationship-set is a mathematical relation involving nentity-sets, n≥ 2 1 4
  • 23. Relationships (2) ¨ ¨ Entity-sets participate in relationship-sets Example: bank loans • Specific entities participate in a relationship instance • Customer and loan are entity-sets • (555-55-5555, Jackson, Woodside) is a customer entity and (L-14, 1500) is a loan entity • Borrower is a relationship-set • customer and loan participate in borrower • borrower contains a relationship instance that associates customer “Jackson” and loan “L-14” 1 5
  • 24. Relationships and Roles ¨ ¨ Roles are usually obvious, and therefore unspecified An entity’s role in a relationship is the function that the entity fills Example: a purchase relationship between a product and a customer • The product’s role is that it was purchased • The customer did the purchasing • Entities participating in relationships are distinct… • Names clearly indicate the roles of various entities… • In these cases, roles are left unstated. 1 6
  • 25. Relationships and Roles (2) • Sometimes the roles of entities are not obvious • Example: a relationship-set named works_for, specifying employee/manager assignments Situations where entity-sets in a relationship-set are not distinct Roles are given names to distinguish entities • Relationship involves two entities, and both are employee entities • The relationship is a set of entities ordered by role: (manager, worker) • First entity’s role is named manager, Second entity’s role is named worker 1 7
  • 26. The R in ER: Relationships • A relationship type is between two entity types 15 Product name category price Company name Makes How to read a relationship in both directions: 1. A product is made by a company 2. A company makes a product
  • 28. What is a Relationship? category price name $9.99 Electronics Gizmo $7.50 Electronics GizmoLite $5.50 Toys Gadget name GizmoWorks GadgetCorp Company Product Makes Product name category price Company name A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identified by P and C’s keys 28
  • 29. What is a Relationship? category price name name $9.99 Electronics Gizmo GizmoWorks $7.50 Electronics GizmoLite GadgetCorp $5.50 Toys Gadget Company Product P.category P.price P.name C.name $9.99 Electronics Gizmo GizmoWorks $7.50 Electronics GizmoLite GizmoWorks $5.50 Toys Gadget GizmoWorks $9.99 Electronics Gizmo GadgetCorp $7.50 Electronics GizmoLite GadgetCorp $5.50 Toys Gadget GadgetCorp Company C x Product P Makes Product name category price Company name A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identified by P and C’s keys 29
  • 30. What is a Relationship? category price name $9.99 Electronics Gizmo $7.50 Electronics GizmoLite $5.50 Toys Gadget name GizmoWorks GadgetCorp Company Product P.category P.price P.name C.name $9.99 Electronics Gizmo GizmoWorks $7.50 Electronics GizmoLite GizmoWorks $5.50 Toys Gadget GizmoWorks $9.99 Electronics Gizmo GadgetCorp $7.50 Electronics GizmoLite GadgetCorp $5.50 Toys Gadget GadgetCorp Company C x Product P P.name C.name Gizmo GizmoWorks GizmoLite GizmoWorks Gadget GadgetCorp Makes Makes Product name category price Company name A relationship between entity sets P and C is a subset of all possible pairs of entities in P and C, with tuples uniquely identified by P and C’s keys 30
  • 31. What is a Relationship? • There can only be one relationship for every unique combination of entities • This also means that the relationship is uniquely determined by the keys of its entities • Example: the key for Makes (to right) is {Product.name, Company.name} 24 This follows from our mathematical definition of a relationship (it is a set) Makes Product name category price Company name
  • 32.
  • 33. 25 Product name category price Company name Makes since Relationships may have attributes as well. For example: “since” records when company started making a product Note: For each product/company pair there is automatically only a single since value since there can only be one unique product/ company pair in makes. Relationships and Attributes
  • 34. Decision: Relationship vs. Entity? Purchased Product name category price Person name Q: What does this say? date A: A person can only buy a specific product once per day (date) Modeling something as a relationship makes it unique. What if this is not appropriate? 34
  • 35. Decision: Relationship vs. Entity? What about this way? Product name category price Person name date Purchase quantity PID# ProductOf BuyerOf Now we can have multiple purchases per product, person pair! We can always use a new entity instead of a relationship. For example, to permit multiple instances of each entity combination! 35
  • 36. Note on Relationships vs. Relation 28 category price name $9.99 Electronics Gizmo $7.50 Electronics GizmoLite $5.50 Toys Gadget Makes Product name category price Company name Relationship/Relationship type Relation Product ER Model: How do Entity types relate to each other Math: A Relation Relational Algebra: A table with data (a set) Relations are used to implement entity types and certain relationship types!
  • 37. Degree of Relationship Set • Most relationships in a schema are binary • Sometimes there are ternary relationships • The number of entity-sets that participate in a relationship-set is called its degree • Binary relationship: degree = 2 • Ternary relationship: degree = 3 • Two entities are involved in the relationship • Three entities are involved • Far less common, but still useful at times 2 0
  • 38.
  • 39.
  • 40. Attribute Source ¨ ¨ Base attributes (aka source attributes) are stored in the database ¤ e.g. the birth_date of a customer entity Derived attributes are computed from other attributes ¤ e.g. the age of a customer entity would be computed from their birth_date 2 4
  • 41. Diagramming Attributes ¨ Example: Extend customers with more detailed info ¨ Composite attributes are shown as a hierarchy of values ¤ ¤ Indented values are components of the higher-level value e.g. name is comprised of first_name, middle_initial, and last_name customer cust_id name first_name middle_initial last_name address street city state zip_code 2 5
  • 42. Diagramming Attributes (2) • Example: Extend customers with more detailed info • Multivalued attributes are enclosed with curly-braces e.g. each customer can have zero or more phone numbers customer cust_id name first_name middle_initial last_name address street city state zip_code {phone_number} 2 6
  • 43. Diagramming Attributes (3) ¨ Example: Extend customers with more detailed info ¨ Derived attributes are indicated by a trailing set of parentheses () ¤ ¤ e.g. each customer has a base attribute recording their date of birth Also a derived attribute that reports the customer’s current age customer cust_id name first_name middle_initial last_name address street city state zip_code { phone_number} birth_date age () 2 7
  • 44. Representing Constraints ¨ E-R model can represent different kinds of constraints ¨Allows more accurate modeling of application’s data requirements ¤ ¨Enforcing constraints can impact performance… ¤ ¤ ¤ ¤ Mapping cardinalities Key constraints in entity-sets Participation Constrain design so that schema can only represent valid information Still ought to specify them in the design! Can always leave out constraints at implementation time 2 8
  • 45. Mapping Cardinalities ¨ ¨ ¨ Example: ¨Mapping cardinality represents: Also known as the cardinality ratio Easiest to reason about with binary relationships “How many other entities can be associated with an entity, via a particular relationship set?” How many customer entities can the borrower relationship associate with a single loan entity? How many loans can borrower relationship associate with a single customer entity? Specific answer depends on what is being modeled ¤ ¤ ¤ 2 9
  • 46.
  • 47.
  • 48.
  • 49. Mapping Cardinalities (5) ¨ Goal: ¤ ¨Which mapping cardinality is most appropriate for a given relationship? ¤ ¤ ¤ ¤ Answer depends on what you are trying to model! Could just use many-to-many relationships everywhere, but that would be dumb. Constrain the mapping cardinality to most accurately reflect what should be allowed Database can enforce these constraints automatically Good schema design reduces or eliminates the possibility of storing bad data 3 3
  • 50.
  • 51. Diagramming Cardinalities ¨ In relationship-set diagrams: ¤ ¤ ¤ an arrow towards an entity represents “one” a simple line represents “many” arrow is always towards the entity 3 5
  • 52.
  • 53.
  • 54.
  • 55. Construct an E-R diagram for a hospital with a set of patients and a set of doctors. Associate with each patient a log of the various tests and examinations conducted by the doctors