The Database Environment and Development Process
The Database Environment and Development Process
Order Filing
System
DBMS manages data resources like an operating system manages hardware resources
Elements of the Database Approach
Data models
Graphical diagram capturing nature and relationship of data
Enterprise Data Model–high-level entities and relationships for the
organization
Project Data Model–more detailed view, matching data structure in
database or data warehouse
Entities
Noun form describing a person, place, object, event, or concept
Composed of attributes
Relationships
Indicate relations between entities
Usually one-to-many (1:M) or many-to-many (M:N), but could also
be one-to-one (1:1)
Relational Databases
Database technology involving tables (relations) representing entities
and primary/foreign keys representing relationships
ACTIVITY: EXAMPLES OF
EACH Element
• Can you list some examples of entities and
relationships of database approach in the previous
slide.
Figure 1-3 Comparison of enterprise and project level data models
Segment of an enterprise data model
Many-to-many
relationship
Database management system
• A database management system (DBMS) is a software
system that enables the use of a database approach. The
primary purpose of a DBMS is to provide a systematic
method of creating, updating, storing, and retrieving the
data stored in a database
Advantages of THE DatabaSE APPROACH
Program-data independence
Planned data redundancy
Improved data consistency
Improved data sharing
Increased application development productivity
Enforcement of standards
Improved data quality
Improved data accessibility and responsiveness
Reduced program maintenance
Improved decision support
ACTIVITY: ANY RISKS
REGARDING TO DB
• Not all solutions are 100% correct, can you list
some disadvantages when using database
Costs and Risks of the Database Approach
Analysis
Logical Design
Physical Design
Implementation
Maintenance
Systems Development Life Cycle
(see also Figure 1-7) (cont.)
Planning
Planning Purpose–preliminary understanding
Deliverable–request for study
Analysis
Logical Design
Physical Design
Logical Design
Physical Design
Logical
Logical Design
Design
Physical Design
Analysis Deliverable–program/data
structures, technology purchases,
organization redesigns
Logical Design
Physical Design
Physical Design
Physical Design
Database activity–
database implementation, Implementation
Implementation
including coded programs,
documentation, Maintenance
installation and conversion
Systems Development Life Cycle
(see also Figure 1-7) (cont.)
Planning Purpose–monitor, repair, enhance
Deliverable–periodic audits
Analysis
Logical Design
Physical Design
Database activity–
database maintenance, Implementation
performance analysis
and tuning, error Maintenance
Maintenance
corrections
ACTIVITY: THOUGHT ABOUT
SDLC
• It’s any inconveniences when using this. In which
case SDLC is widely used.
Prototyping is a
classical Rapid
Application
Development
(RAD) approach
Prototyping Database Methodology
(Figure 1-8)
Prototyping Database Methodology
(Figure 1-8)
Prototyping Database Methodology
(Figure 1-8)
Prototyping Database Methodology
(Figure 1-8)
Other Rapid Application (RAD)
Approaches
• Agile – emphasizes “individuals and interactions over processes and
tools, working software over comprehensive documentation, customer
collaboration over contract negotiation, and response to change over
following a plan.” (The Agile Manifesto)
Different people
have different
views of the
database…these
are the external
schema
The internal
schema is the
underlying
design and
implementation
Managing People and Projects
Entity Attribute
symbols symbols
A special entity
that is also a Relationship
relationship symbols
Relationship
degrees specify
number of
entity types Relationship
involved cardinalities
specify how
many of each
entity type is
allowed
Business Rules
System System
user Inappropriate output
entities
Appropriate
entities
Strong vs. Weak Entities, and
Identifying Relationships
Strong entity
exists independently of other types of entities
has its own unique identifier
identifier underlined with single line
Weak entity
dependent on a strong entity (identifying owner)…cannot exist
on its own
does not have a unique identifier (only a partial identifier)
entity box and partial identifier have double lines
Identifying relationship
links strong entities to weak entities
Figure 2-5 Example of a weak identity and its identifying relationship
Names: Definitions:
Singular noun
“An X is…”
Specific to organization
Describe unique
characteristics of each
Concise, or abbreviation instance
For event entities, the Explicit about what is and is
result not the process not the entity
Name consistent for all When an instance is created
diagrams or destroyed
Changes to other entity
types
History that should be kept
Attributes
Attribute–property or characteristic of an
entity or relationship type
Classifications of attributes:
Required versus Optional Attributes
Simple versus Composite Attribute
Single-Valued versus Multivalued Attribute
Stored versus Derived Attributes
Identifier Attributes
Required vs. Optional Attributes
Required – must have a value for every Optional – may not have a value for
entity (or relationship) instance with every entity (or relationship) instance
which it is associated with which it is associated
Simple vs. Composite Attributes
The address is
broken into
component parts
Figure 2-8 Entity with multivalued attribute (Skill) and derived attribute
(Years Employed)
Multivalued Derived
an employee can Calculated
have more than one from date
skill employed
and current
date
Identifiers (Keys)
The identifier
is boldfaced
and underlined
Naming Attributes
Name should be a singular noun or noun
phrase
Name should be unique
Name should follow a standard format
e.g. [Entity type name { [ Qualifier ] } ] Class
Similar attributes of different entity types
should use the same qualifiers and classes
Defining Attributes
State what the attribute is and possibly why it is
important
Make it clear what is and is not included in the attribute’s
value
Include aliases in documentation
State source of values
State whether attribute value can change once set
Specify required vs. optional
State min and max number of occurrences allowed
Indicate relationships with other attributes
Modeling Relationships
Relationship Types vs. Relationship Instances
The relationship type is modeled as lines between
entity types…the instance is between specific entity
instances
Relationships can have attributes
These describe features pertaining to the association between the
entities in the relationship
Two entities can have more than one type of
relationship between them (multiple relationships)
Associative Entity–combination of relationship and
entity
Figure 2-10 Relationship types and instances
a) Relationship
type (Completes)
b) Relationship
instances
Degree of Relationships
Entities of
One entity two different
related to types related Entities of three
another of to each other different types
the same
related to each
entity type
other
Cardinality of Relationships
One-to-One
Each entity in the relationship will have exactly one related
entity
One-to-Many
An entity on one side of the relationship can have many
related entities, but an entity on the other side will have a
maximum of one related entity
Many-to-Many
Entities on both sides of the relationship can have many
related entities on the other side
Figure 2-12 Examples of relationships of different degrees
a) Unary relationships
Figure 2-12 Examples of relationships of different degrees (cont.)
b) Binary relationships
Figure 2-12 Examples of relationships of different degrees (cont.)
c) Ternary relationship
a) Mandatory cardinalities
c) Optional cardinalities
A person is
married to at most
one other person,
or may not be
married at all
Figure 2-21 Examples of multiple relationships
simple
composite
Associative Entities
An entity–has attributes
A relationship–links entities together
When should a relationship with attributes instead be an
associative entity?
All relationships for the associative entity should be many
The associative entity could have meaning independent of the
other entities
The associative entity preferably has a unique identifier, and
should also have other attributes
The associative entity may participate in other relationships other
than the entities of the associated relationship
Ternary relationships should be converted to associative entities
Figure 2-11a A binary relationship with an attribute
The Assignment
Modeling time-dependent data has become associative entity shows
more important due to regulations such as the date range of a
HIPAA and Sarbanes-Oxley. product’s assignment to a
particular product line.
Figure 2-22
Data model for Pine
Valley Furniture
Company in
Microsoft Visio
notation
Different modeling
software tools may have
different notation for the
same constructs.
Chapter 3:
The Enhanced E-R Model
a) EER
notation
Figure 3-1 Basic notation for supertype/subtype notation (cont.)
b) Microsoft
Visio
Notation
Different modeling tools may have different notation for the same
modeling constructs.
Figure 3-2 Employee supertype with three subtypes
So we put
the shared
attributes in
a supertype
Only applies to
manufactured parts
Created 2
subtypes
Related
groups of
entities could
become
clusters
Figure 3-13b EER diagram of PVF entity clusters
More readable,
isn’t it?
Figure 3-14 Manufacturing entity cluster
Packaged data
models are
generic models
that can be
customized for a
particular
organization’s
business rules.
Figure 3-15 PARTY, PARTY ROLE, and ROLE TYPE in
a universal data model
• The agency wants to record the following data for all vehicles: Vehicle
ID, Make, Model, Year, and Color.
• There are no unique attributes for any of the four classes of vehicle. The
entity type vehicle has a relationship (named Rents) with a customer
entity type. None of the four vehicle classes has a unique relationship
with an entity type. Would you consider creating a supertype/subtype
relationship for this problem? Why or why not?
EXCERCISES
• At a weekend retreat, the entity type PERSON has three subtypes:
CAMPER, BIKER, and RUNNER. Draw a separate EER diagram segment
for each of the following situations:
Primary Key
Foreign Key
(implements 1:N relationship
between customer and order)
Referential
integrity
constraints are
drawn via arrows
from dependent to
parent table
Figure 4-6 SQL table definitions
Referential
integrity
constraints are
implemented with
foreign key to
primary key
references.
Transforming EER Diagrams into
Relations
Mapping Regular Entities to Relations
Simple attributes: E-R attributes map
directly onto the relation
Composite attributes: Use only their
simple, component attributes
Multivalued Attribute: Becomes a separate
relation with a foreign key taken from the
superior entity
Figure 4-8 Mapping a regular entity
(a) CUSTOMER
entity type with
simple
attributes
(a) CUSTOMER
entity type with
composite
attribute
(a)
(b)
Foreign key
Foreign key
Figure 4-13 Example of mapping an M:N relationship
a) Completes relationship (M:N)
Foreign key
new
Foreign key
intersection
relation
Figure 4-14 Example of mapping a binary 1:1 relationship
a) In charge relationship (binary 1:1)
(a) EMPLOYEE
entity with unary
relationship
(b)
EMPLOYEE
relation with
recursive
foreign key
Figure 4-18 Mapping a unary M:N relationship
(a) Bill-of-materials
relationships (unary M:N)
Getting it into
Third Normal
Form
a) Relations with
enterprise key
b) Sample data
with enterprise
key
Chapter 5:
Physical Database Design and Performance
Data volumes
Figure 5-1 Composite usage map
(Pine Valley Furniture Company) (cont.)
Access Frequencies
(per hour)
Figure 5-1 Composite usage map
(Pine Valley Furniture Company) (cont.)
Usage analysis:
14,000 purchased parts
accessed per hour
8000 supplies accessed from
these 14,000 purchased part
accesses
7000 suppliers accessed from
these 8000 supplies accesses
Figure 5-1 Composite usage map
(Pine Valley Furniture Company) (cont.)
Usage analysis:
7500 suppliers accessed per
hour
4000 supplies accessed from
these 7500 supplier accesses
4000 purchased parts
accessed from these 4000
supplies accesses
Designing Fields
Combine attributes from one of the entities into the record representing the many-
to-many relationship, thus avoiding one of the join operations
Extra table
access
required
Duplicate
description
possible
Figure 5-5
A possible
denormalization
situation:
reference data
a) Join index
for common
non-key
columns
Comparative
COMPARATIVE features
FEATURES of File
OF FILE ORG.
ORG.
(Oracle 12c)
Overall table
definitions
IN MYSQL
Defining attributes and their data types
Non-nullable specification
Primary keys
can never have
NULL values
Identifying primary key
Non-nullable specifications
Primary key
Default value
Domain constraint
Identifying foreign keys and establishing relationships
Primary key of
parent table
Relational
integrity is
enforced via
the primary-
key to foreign-
key match
Changing Tables
• ALTER TABLE statement allows you to change column specifications:
• Table Actions:
Inserting into a table does not require explicit customer ID entry or field list
Figure 6-10
SQL statement
processing order
(based on van der
Lans, 2006 p.100)
SELECT Example
• Find products with standard price less than $275
Note: The LIKE operator allows you to compare strings using wildcards.
For example, the % wildcard in ‘%Desk’ indicates that all strings that
have any number of characters preceding the word “Desk” will be
allowed.
Figure 6-8 Boolean query A without use of parentheses
By default,
processing order
of Boolean
operators is NOT,
then AND, then
OR
SELECT Example–Boolean Operators
With parentheses…these override the normal precedence
of Boolean operators
You can use single-value fields with aggregate functions if they are
included in the GROUP BY clause
Qualifying Results by Categories
Using the HAVING Clause
For use with GROUP BY
The common columns in joined tables are usually the primary key
of the dominant table and the foreign key of the dependent table in
1:M relationships.
Processing Multiple Tables
• Outer join–a join in which rows that do not have
matching values in common columns are nonetheless
included in the result table (as opposed to inner join,
in which rows must have matching values in order to
appear in the result table)
Customer ID
appears twice in the
result
Equi-Join Example – alternative syntax
An INNER join will only return rows from each table that have
matching rows in the other.
Unlike
INNER join,
this will
include
customer
rows with no
matching
order rows
Multiple Table Join Example
• Assemble all information necessary to create an invoice for order
number 1006
Four tables
involved in
this join
From Chapter 2
Unary
1:N
Processing Multiple Tables
Using Subqueries
• Subquery–placing an inner query (SELECT statement)
inside an outer query
• Options:
• In a condition of the WHERE clause
• As a “table” of the FROM clause
• Within the HAVING clause
• Subqueries can be:
• Noncorrelated–executed once for the entire outer query
• Correlated–executed once for each row returned by the
outer query
Subquery Example
• Show all customers who have placed an order
The IN operator will test to see if
the CUSTOMER_ID value of a
row is included in the list
returned from the subquery
Join version
Subquery version
Figure 7-6 Graphical depiction of two ways to
answer a query with different types of joins
Figure 7-6 Graphical depiction of two ways to
answer a query with different types of joins
Correlated vs. Noncorrelated
Subqueries
• Noncorrelated subqueries:
• Do not depend on data from the outer query
• Execute once for the entire outer query
• Correlated subqueries:
• Make use of data from the outer query
• Execute once for each row of the outer query
• Can use the EXISTS operator
Figure 7-8a Processing a noncorrelated subquery
The WHERE clause normally cannot include aggregate functions, but because
the aggregate is performed in the subquery its result can be used in the outer
query’s WHERE clause.
Union Queries
• Combine the output (union of multiple queries)
together into a single result table
First query
Combine
Second query
Figure 7-9 Combining queries using UNION
Note: With
UNION queries,
the quantity and
data types of the
attributes in the
SELECT clauses
of both queries
must be identical.
Conditional Expressions Using Case
Keyword
This is available with
newer versions of SQL,
previously not part of
the standard
Figure 7-10
More Complicated SQL Queries
• Production databases contain hundreds or even
thousands of tables, and tables could include hundreds
of columns.
• So, sometimes query requirements can be very complex.
• Sometimes it’s useful to combine queries, through the
use of Views.
• If you use a view (which is a query), you could have
another query that uses the view as if it were a table.
Example of Query Using a View
Tips for Developing Queries
• Be familiar with the data model (entities and
relationships)
• Understand the desired results
• Know the attributes desired in results
• Identify the entities that contain desired attributes
• Review ERD
• Construct a WHERE equality for each link
• Fine tune with GROUP BY and HAVING clauses if
needed
• Consider the effect on unusual data
Query Efficiency Considerations