IDBMS1
IDBMS1
1
General Course Outline
• Database Management system Concepts:
• Introduction and history
• conventional file handling versus database.
• Conceptual, Community and user views of data, the interface
between their view
• Data modeling: Hierarchical, network and relational models
(we will study in detail), entities, attributes and relations,
Relationship one-to-one, one-to-N, M to N representations
Bachman diagrams. We will study most commonly used ERDs
rather to explain the above terms.).
2
Course Outline
3
Course Outline
4
TEXT AND REFERENCE BOOKS
5
Week 1:
Database management concepts
6
Objectives
• Definition of terms
• Explain growth and importance of databases
• Name limitations of conventional file processing
• Identify five categories of databases
• Explain advantages of databases
• Identify costs and risks of databases
• List components of database environment
• Describe evolution of database systems
7
•What is a database?
8
Database
• Database: organized collection of logically related data
9
Application of database
10
•Coming back to the definition of
database, “organized collection
of logically related data”
11
Data and Information
• Data: stored representations of meaningful objects
and events
• Broadly two types:
• Structured: numbers, text, dates
• Unstructured: images, video, documents
• Information: data processed to increase knowledge in
the person using the data
• Metadata: data that describes the properties and
context of user data
12
Data
13
Figure 1-1a Data in context
15
Descriptions of the properties or characteristics of the
data, including data types, field sizes, allowable
values, and data context
16
Flat File databases
17
Advantages of flat file DBs
• Easy to setup
Doesn’t require expert computer knowledge
Easy to understand
Simple to get information from them. Simple design
18
Disadvantages of File Processing
• Program-Data Dependence
• All programs maintain metadata for each file they use
• Duplication of Data
• Different systems/programs have separate copies of the same data
• Limited Data Sharing
• No centralized control of data
• Lengthy Development Times
• Programmers must design their own file formats
• Excessive Program Maintenance
• 80% of information systems budget
19
Problems with Data Dependency
20
Figure 1-3 Old file processing systems at Pine Valley
Furniture Company
Duplicate Data
21
Problems with Data Redundancy
22
SOLUTION:
The DATABASE Approach
23
SOLUTION:
The DATABASE Approach
24
Database Management System
A software system that is used to create, maintain, and provide
controlled access to user databases
Order Filing
System
DBMS manages data resources like an operating system manages hardware resources
25
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
26
Costs and Risks of the Database Approach
• New, specialized personnel
• Installation and management cost and complexity
• Conversion costs
• Need for explicit backup and recovery
• Organizational conflict
27
Elements of the Database Approach
• Data models
• Graphical system 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
• Relational Databases
• Database technology involving tables (relations) representing entities
and primary/foreign keys representing relationships
• Use of Internet Technology
• Networks and telecommunications, distributed databases, client-server,
and 3-tier architectures
• Database Applications
• Application programs used to perform database activities (create, read,
update, and delete) for database users
28
Segment of an Enterprise Data Model
29
One customer
may place many
orders, but each
order is placed by
a single customer
One-to-many
relationship
30
One order has
many order lines;
each order line is
associated with a
single order
One-to-many
relationship
31
One product can
be in many
order lines, each
order line refers
to a single
product
One-to-many
relationship
32
Therefore, one
order involves
many products
and one product is
involved in many
orders
Many-to-many
relationship
33
Figure 1-4 Enterprise data model for Figure 1-3 segments
34
Figure 1-5 Components of the Database Environment
35
Components of the
Database Environment
• Personal databases
• Workgroup databases
• Departmental/divisional databases
• Enterprise database
37
38
Figure 1-6
Typical data
from a
personal
database
39
Figure 1-7 Workgroup database with wireless
local area network
40
Enterprise Database Applications
41
Figure 1-8 An enterprise data warehouse
42
Evolution of DB Systems
43
INTRODUCTION TO DATABASE
SYSTEMS
1
Previously
2
CONTENTS
3
Target CLOs
4
You have already studied these in detail in
the software engineering-1 course… Just an
overview here
5
Enterprise Data Model
6
Figure 2-1 Segment from enterprise data model
7
Information Systems Architecture
(ISA)
8
Information Engineering
• A data-oriented methodology to create and
maintain information systems
• Top-down planning–a generic IS planning
methodology for obtaining a broad understanding
of the IS needed by the entire organization
• Four steps to Top-Down planning:
• Planning
• Analysis
• Design
• Implementation
9
Information Systems Planning
(Table 2-1)
• Purpose–align information technology with
organization’s business strategies
• Three steps:
1. Identify strategic planning factors
2. Identify corporate planning objects
3. Develop enterprise model
10
Identify Strategic Planning Factors (Table 2-2)
11
Identify Corporate Planning Objects (Table 2-3)
• Organizational units–departments
• Organizational locations
• Business functions–groups of business processes
• Entity types–the things we are trying to model for the database
• Information systems–application programs
12
Develop Enterprise Model
• Functional decomposition
• Iterative process breaking system description into finer and finer
detail
• Enterprise data model
• Planning matrixes
• Describe interrelationships
between planning objects
13
Figure 2-2 Example of process decomposition of an
order fulfillment function (Pine Valley Furniture)
Decomposition = breaking
large tasks into smaller tasks
in a hierarchical structure
chart
14
Planning Matrixes
• Describe relationships between planning objects in the
organization
• Types of matrixes:
• Function-to-data entity
• Location-to-function
• Unit-to-function
• IS-to-data entity
• Supporting function-to-data entity
• IS-to-business objective
15
Example business function-to-data
entity matrix (Fig. 2-3)
16
Two Approaches to Database and IS
Development
• SDLC
• System Development Life Cycle
• Detailed, well-planned development process
• Time-consuming, but comprehensive
• Long development cycle
• Prototyping
• Rapid application development (RAD)
• Cursory attempt at conceptual data modeling
• Define database during development of initial prototype
• Repeat implementation and maintenance activities with new
prototype versions
17
Systems Development Life Cycle
Planning
Analysis
Logical Design
Physical Design
Implementation
Maintenance
18
Systems Development Life Cycle
(cont.)
Planning
Planning Purpose–preliminary understanding
Deliverable–request for study
Analysis
Logical Design
Physical Design
19
Systems Development Life Cycle
How to proceed with Planning?
With any SE project, Planning is the key to success
20
Systems Development Life Cycle
How to proceed with Planning?
With any SE project, Planning is the key to success
21
Planning (Cont)
Scope
• Define the scope of the problem (i.e., what are the problems and
what problems are you going to solve)
• Scope may also include the current and future users of the system
• Avoid scope creep.
22
Systems Development Life Cycle
(cont.)
Purpose–thorough requirements analysis
Planning Deliverable–functional system specifications
Analysis
Analysis
Logical Design
Physical Design
23
Analysis (Cont)
Requirement Document
• The planning phase leads to the Requirement
document.
• An important document as it form the basis of
design and ultimately the whole system.
• Requirement engineering is major SE area.
• If you have captured requirement correctly then
your system will be sound.
• Disadvantages of water fall method.
24
Analysis (Cont)
In Database
• In database this step lead to the conceptual design
in the form of high level refined ERD (The planning
and analysis usually run in parallel)
• A conceptual model may include a few significant
attributes to augment the definition and
visualization of entities. No effort need be made to
inventory the full attribute population of such a
model
25
Planning (Cont.)
Enterprise Data Model
• First step in database development
• Overall picture of organizational data at high level of
abstraction
• Preliminary Entity-relationship diagram
• Descriptions of entity types
• Relationships between entities
• Business rules
26
Segment from enterprise data model
27
Systems Development Life Cycle
(cont.)
Purpose–information requirements elicitation
Planning and structure
Deliverable–detailed design specifications
Analysis
Logical Design
Logical Design
Physical Design
Physical Design
Physical Design
Logical Design
Physical Design
Database activity–
database implementation, Implementation
Implementation
including coded programs,
documentation, Maintenance
installation and conversion
30
Systems Development Life Cycle
(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
31
A little about testing
32
Prototyping Database Methodology
33
Prototyping Database Methodology
(cont.)
34
Prototyping Database Methodology
(cont.)
35
Prototyping Database Methodology
(cont.)
36
Prototyping Database Methodology
(cont.)
37
CASE
• Computer-Aided Software Engineering (CASE)–software tools providing
automated support for systems development
• Three database features:
• Data modeling–drawing entity-relationship diagrams
• Code generation–SQL code for table creation
• Repositories–knowledge base of enterprise information
38
Managing DB Projects: People Involved
• Systems analysts
• Database analysts and data modelers
• Users
• Programmers
• Database and Data administrators
• Other technical experts
39
Database Schema
• Physical Schema
• Physical structures–covered in Chapters 5 and 6
• Conceptual Schema
• E-R models–covered in Chapters 3 and 4
• External Schema
• User Views
• Subsets of Conceptual Schema
• Can be determined from business-function/data entity
matrices
• DBA determines schema for different users
40
Three-schema architecture
Different people
have different
views of the
database…these
are the external
schema
The internal
schema is the
underlying
design and
implementation
41
Developing the three-schema architecture
42
Figure 2-9 Three-tiered client/server database architecture
43
Pine Valley Furniture
44
Figure 2-12 Four relations (Pine Valley Furniture)
45
Figure 2-12 Four relations (Pine Valley Furniture) (cont.)
46
Conceptual Design (ERD)
1
Objectives
2
SDLC Revisited – Data Modeling is an Analysis
Activity
Analysis
Analysis
Logical Design
Physical Design
3
Business Rules
4
A Good Business Rule is:
5
A Good Data Name is:
• Related to business, not technical, characteristics
• Meaningful and self-documenting
• Unique
• Readable
• Composed of words from an approved list
• Repeatable
6
Data Definitions
• Explanation of a term or fact
• Term – word or phrase with specific meaning
• Fact – association between two or more terms
• Guidelines for good data definition
• Gathered in conjunction with systems requirements
• Accompanied by diagrams
• Iteratively created and refined
• Achieved by consensus
7
E-R Model Constructs
• Entity instance - person, place, object, event, concept
(often corresponds to a row in a table)
• Entity Type – collection of entities (often corresponds to
a table)
• Attribute - property or characteristic of an entity type
(often corresponds to a field in a table)
• Relationship instance – link between entities
(corresponds to primary key-foreign key equivalencies in
related tables)
• Relationship type – category of relationship…link
between entity types
8
Sample E-R Diagram
9
Sample E-R Diagram
(Alternate notation)
10
Relationship symbols
Entity
symbols Attribute
symbols
A special entity
that is also a
relationship
Relationship
degrees specify
number of
entity types
involved
Relationship
cardinalities
specify how
many of each
entity type is
allowed
11
Basic E-R notation (Alternate
notation in new editions)
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
12
Strong and Weak Entity
13
What Should an Entity Be?
• SHOULD BE:
• An object that will have many instances in the database
• An object that will be composed of multiple attributes
• An object that we are trying to model
• SHOULD NOT BE:
• A user of the database system
• An output of the database system (e.g. a report)
14
Inappropriate entities
Appropriate entities
15
Attributes
16
Identifiers (Keys)
17
Characteristics of Identifiers
18
A composite attribute
An attribute
broken into
component parts
19
Simple key attribute
20
Composite key attribute
21
Entity with a multivalued attribute (Skill) and derived attribute
(Years_Employed)
Multivalued:
Derived an employee can have
from date employed and current date more than one skill
22
A composite attribute
An attribute
broken into
component parts
Multivalued
an employee can have
Derived
more than one skill
from date
employed and
current date
23
An attribute that is both multivalued and composite
This is an
example of
time-stamping
24
More on Relationships
• Relationship Types vs. Relationship Instances
• The relationship type is modeled as the diamond and
lines (or only line in alternate notation) 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
25
26
Relationship types and instances
a) Relationship type
b) Relationship
instances
27
Previously
• Entities
• Entity type
• Entity Instance
• Relationships
• Type
• Instance
• Types of entities
• Degree of relationships
• Cardinalities etc.
• Visio notations and Crow’s foot representation of ERD
28
Degree of Relationships
29
Degree of relationships
Entities of
One entity two different
related to types related
another of to each other Entities of three
the same different types
entity type related to each
other
30
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
31
Cardinality Constraints
32
33
34
Note: a relationship can have attributes of its own
35
Basic relationship with only maximum cardinalities showing
36
Optional cardinalities with unary degree, one-to-one relationship
37
A binary relationship with an attribute
38
Figure 3-12c -- A ternary relationship with attributes
39
Figure 3-13a – A unary relationship with an attribute.
This has a many-to-many relationship
40
Entities can be related to one another in more than one way
41
Here,max
cardinality
constraint is 4
42
Multivalued attributes can be represented as relationships
43
Strong vs. Weak Entities, and
Identifying Relationships
• Strong entities
• exist independently of other types of entities
• has its own unique identifier
• represented with single-line rectangle
• Weak entity
• dependent on a strong entity…cannot exist on its own
• does not have a unique identifier
• represented with double-line rectangle
• Identifying relationship
• links strong entities to weak entities
• represented with double line diamond
44
Strong entity Identifying relationship Weak entity
45
Identifying relationship (Implicit)
46
Associative Entities
• It’s an entity – it has attributes
47
An associative entity (CERTIFICATE)
48
49
Unary Many to many relation (BOM): An associative entity
50
An associative entity
51
Ternary relationship as an associative entity
52
Ternary relationship as an associative entity
53
Modelling Time Dependent Data
• Time stamp
A time value that is associated with a data value, often indicating when
some event occurred that affected the data value
54
Modelling time dependent data
55
E-R diagram for Pine
Valley Furniture
56
Microsoft Visio
Notation for Pine
Valley Furniture
Different modeling
software tools may have
different notation for the
same constructs
57
Conceptual Design
The Enhanced ER Model
1
Supertypes and Subtypes
2
3
MS Visio notations
Different modeling tools may have different notation for the same
modeling constructs
4
Supertype and subtype representation in Oracle
5
Employee supertype with three subtypes
6
*Advantages of Enhanced ERD
◼ It avoids the need to describe similar
concept more than once thus saving time
for data modeller.
◼ It results in more readable and better-
looking E-R diagrams
◼ Add more information to the design in a
concise form.
8
Supertype/subtype relationships in a hospital
Both outpatients and
resident patients are
cared for by a
responsible physician
9
When to use Supertypes/subtypes
Relationships.
◼ There are attributes that apply to some but
not all of the instances of an entity type.
E.g. Employee entity
◼ The instances of a subtype participate in a
relationship unique to that subtype.
10
Generalization and
Specialization
◼ Generalization: The process of defining
a more general entity type from a set of
more specialized entity types. BOTTOM-
UP
◼ Specialization: The process of defining
one or more subtypes of the supertype,
and forming supertype/subtype
relationships. TOP-DOWN
11
Example of generalization
Three entity types: CAR, TRUCK, and MOTORCYCLE
12
Generalization to VEHICLE supertype
So we put
the shared
attributes in
a supertype
Only applies to
manufactured
parts
14
Specialization to MANUFACTURED PART and PURCHASED PART
Created 2 subtypes
15
Specialization to MANUFACTURED PART and PURCHASED PART
Note: Associative entity from supplies relationship to accommodate the unit price
attribute
16
Constraints in Supertype/ Completeness
Constraint
17
– Examples of completeness constraints
Total specialization rule
18
– Partial specialization rule
19
Constraints in Supertype/ Disjointness
constraint
20
Examples of disjointness constraints
Disjoint rule
21
Overlap rule
22
Constraints in Supertype/ Subtype
Discriminators
◼ Subtype Discriminator: An attribute of the
supertype whose values determine the target
subtype(s)
Disjoint – a simple attribute with alternative values to
indicate the possible subtypes
Overlapping – a composite attribute whose subparts
pertain to different subtypes. Each subpart contains a
boolean value to indicate whether or not the instance
belongs to the associated subtype
23
Introducing a subtype discriminator (disjoint rule)
24
Subtype discriminator (overlap rule)
A composite attribute
with sub-attributes
indicating “yes” or “no”
to determine whether it
is of each subtype
25
26
EER based on Question 1
27
Defining supertype/subtype
hierarchies
28
29
Entity Clusters
◼ EER diagrams are difficult to read when
there are too many entities and
relationships
◼ Solution: group entities and relationships
into entity clusters
◼ Entity cluster: set of one or more entity
types and associated relationships
grouped into a single abstract entity type
30
Related
groups of
entities could
become
clusters
31
EER diagram of PVF entity clusters
More readable,
isn’t it?
32
Exercise
33
End of Lecture
34
Logical Database Design
and Relational Data model
1
What is a relational data model.
Represent data in the form of tables.
First introduced by E.F. Codd of IBM in
1970.
This model consists of three
components
i. Data structure (table)
ii. Data Manipulation (SQL)
iii. Data Integrity (Constraints)
2
Relation
Definition: A relation is a named, two-dimensional table of
data
Table consists of rows (records) and columns (attribute or
field)
Requirements for a table to qualify as a relation:
It must have a unique name
Every attribute value must be atomic (not multivalued, not
composite)
Every row must be unique (can’t have two rows with exactly the
same values for all their fields)
Attributes (columns) in tables must have unique names
The order of the columns must be irrelevant
The order of the rows must be irrelevant
3
Is the following a relation?
4
Alternate Representation
5
Is the following a relation?
6
Correspondence with E-R
Model
Relations (tables) correspond with entity types
and with many-to-many relationship types
Rows correspond with entity instances and with
many-to-many relationship instances
Columns correspond with attributes
8
Schema description
Can be described by:
Short
text statements
NAME_OF_RELATION(List of Attributes)
Graphical Representation
9
Key Fields
Keys are special fields that serve two main purposes:
Primary keys are unique identifiers of the relation in question.
Examples include employee numbers, social security numbers,
etc. This is how we can guarantee that all rows are unique
Foreign keys are identifiers that enable a dependent relation
(on the many side of a relationship) to refer to its parent relation
(on the one side of the relationship)
Keys can be simple (a single field) or composite (more
than one field)
Keys usually are used as indexes to speed up the
response to user queries
10
Schema for four relations (Pine Valley Furniture Company)
Primary Key
Foreign Key
(implements 1:N relationship
between customer and order)
11
Instance of relation schema (Pine Valley Furniture Company)
12
Integrity Constraints
Domain Constraints
For each column of a table there is a set of
possible values called its domain. (Similar to
a data type in a programming language).
According to Domain constraint: All the
values that appear in a column of a relation
must be taken from the same domain.
13
Domain definitions enforce domain integrity constraints
14
Integrity Constraints
Null is a value that may be assigned to an
attribute when no other values applies or
the applicable value is unknown.
Entity Integrity
Is designed to assure that every relation has
a primary key and
No primary key attribute may be null. All
primary key fields MUST have data
15
Integrity Constraints
Referential Integrity–rule states that any foreign key value (on
the relation of the many side) MUST match a primary key value
in the relation of the one side. (Or the foreign key can be null)
Enables consistency between the rows of two tables.
For example: Delete Rules
Restrict–don’t allow delete of “parent” side if related rows exist in
“dependent” side
Cascade–automatically delete “dependent” side rows that correspond
with the “parent” side row to be deleted
Set-to-Null–set the foreign key in the dependent side to null if deleting
from the parent side not allowed for weak entities
16
Figure 5-5
Referential integrity constraints (Pine Valley Furniture)
Referential
integrity
constraints are
drawn via arrows
from dependent to
parent table
17
Figure 5-6 SQL table definitions
Referential
integrity
constraints are
implemented with
foreign key to
primary key
references
18
Logical Database Design
What do we come up with after the end of
database analysis phase?
19
Logical Design
At the end of analysis phase System and
database analyst get a clear
understanding of the data storage and
access requirement.
However, avoids any specific database
technology.
During logical design, conceptual model is
transformed in to a specific database
model.
20
Transforming EER Diagrams
into Relations
Mapping Regular Entities to Relations
1. Simple attributes: E-R attributes map directly
onto the relation
2. Composite attributes: Use only their simple,
component attributes
3. Multivalued Attribute–Becomes a separate
relation with a foreign key taken from the
superior entity
21
Figure 5-8 Mapping a regular entity
(a) CUSTOMER
entity type with
simple
attributes
22
Figure 5-9 Mapping a composite attribute
(a) CUSTOMER
entity type with
composite
attribute
23
Figure 5-10 Mapping an entity with a multivalued attribute
(a)
26
Figure 5-11 Example of mapping a weak entity (cont.)
Foreign key
27
Transforming EER Diagrams
into Relations (cont.)
Mapping Binary Relationships
One-to-Many–Primary key on the one side
becomes a foreign key on the many side
Many-to-Many–Create a new relation with
the primary keys of the two entities as its
primary key
One-to-One–Primary key on the mandatory
side becomes a foreign key on the optional
side
28
Figure 5-12 Example of mapping a 1:M relationship
a) Relationship between customers and orders
29
Figure 5-13 Example of mapping an M:N relationship
a) Completes relationship (M:N)
30
Figure 5-13 Example of mapping an M:N relationship (cont.)
b) Three resulting relations
31
Figure 5-14 Example of mapping a binary 1:1 relationship
a) In_charge relationship (1:1)
32
Figure 5-14 Example of mapping a binary 1:1 relationship (cont.)
b) Resulting relations
33
Transforming EER Diagrams
into Relations (cont.)
Mapping Associative Entities
Identifier Not Assigned
Default primary key for the association
relation is composed of the primary keys of
the two entities (as in M:N relationship)
Identifier Assigned
It
is natural and familiar to end-users
Default identifier may not be unique
34
Figure 5-15 Example of mapping an associative entity
a) An associative entity
35
Figure 5-15 Example of mapping an associative entity (cont.)
b) Three resulting relations
36
Figure 5-16 Example of mapping an associative entity with
an identifier
a) SHIPMENT associative entity
37
Figure 5-16 Example of mapping an associative entity with
an identifier (cont.)
b) Three resulting relations
38
Transforming EER Diagrams
into Relations (cont.)
Mapping Unary Relationships
One-to-Many–Recursive foreign key in the
same relation
Many-to-Many–Two relations:
One for the entity type
39
Figure 5-17 Mapping a unary 1:N relationship
(b) EMPLOYEE
relation with
recursive foreign
key
40
Transforming EER Diagrams
into Relations (cont.)
Many-to-Many–Two relations:
• One for the entity type
• One for an associative relation in which
the primary key has two attributes, both
taken from the primary key of the entity
41
Mapping a unary M:N relationship
42
Transforming EER Diagrams
into Relations (cont.)
Mapping Ternary (and n-ary)
Relationships
One relation for each entity and
one for the associative entity
Associative entity has foreign keys
to each entity in the relationship
43
Mapping a ternary relationship
44
Figure 5-19 Mapping a ternary relationship (cont.)
46
Figure 5-20 Supertype/subtype relationships
47
Figure 5-21
Mapping Supertype/subtype relationships to relations
48
Well-Structured Relations
A relation that contains minimal data redundancy and
allows users to insert, delete, and update rows
without causing data inconsistencies
Goal is to avoid anomalies
Insertion Anomaly–adding new rows forces user to create
extra data
Deletion Anomaly–deleting rows may cause a loss of data
that would be needed for other future rows
Modification Anomaly–changing data in a row forces
changes to other rows because of duplication
49
Example–Figure 5-2b
50
Anomalies in this Table
51
52
The End
53
Logical Database
Design
1
Contents
Normalization
1 Normal Form
Functional Dependencies
Identifying Functional Dependencies
Transitive Dependencies
2nd Normal Form
3rd Normal Form
Merging Relations
Enterprise Keys
2
CLO(s) & Taxonomy Level
The contents target CLO 3
Taxonomy Level is 3
3
Data Normalization
Primarily a tool to validate and improve
a logical design so that it satisfies
certain constraints that avoid
unnecessary duplication of data
The process of decomposing relations
with anomalies to produce smaller,
well-structured relations
4
Well-Structured Relations
A relation that contains minimal data redundancy and
allows users to insert, delete, and update rows
without causing data inconsistencies
Goal is to avoid anomalies
Insertion Anomaly–adding new rows forces user to create
duplicate data
Deletion Anomaly–deleting rows may cause a loss of data
that would be needed for other future rows
Modification Anomaly–changing data in a row forces
changes to other rows because of duplication
6
Anomalies in this Table
Insertion–can’t enter a new employee without
having the employee take a class
Deletion–if we remove employee 140, we lose
information about the existence of a Tax Acc class
Modification–giving a salary increase to employee
100 forces us to update multiple records
8
First Normal Form
No multivalued attributes
9
Table with multivalued attributes, not in 1st normal form
Is this a relation?
10
Table with no multivalued attributes and unique rows, in 1st
normal form
11
Anomalies in this Table
Insertion–if new product is ordered for order 1007
of existing customer, customer data must be re-
entered, causing duplication
Deletion–if we delete the Dining Table from Order
1006, we lose information concerning this item's
finish and price
Update–changing the price of product ID 4 requires
update in several records
13
Functional Dependencies and Keys
Functional Dependency: The value of
one attribute (the determinant)
determines the value of another
attribute
14
Functional Dependencies (FD) -
Definition
Let R be a relation scheme and A, B be sets of attributes in R.
A functional dependency from A to B exists if and only if:
For every instance of |R| of R, if two tuples in |R| agree on the
values of the attributes in A, then they agree on the values of the
attributes in B
We write A B and say that A determines B
15
Example
16
Example (cont…)
17
Example Functional Dependency
that holds for all Time
Consider the values shown in staffNo and
sName attributes of the Staff relation.
staffNo → sName
sName → staffNo
32
© Pearson Education Limited 1995, 2005
Identifying the Primary Key for a
Relation using Functional
Dependencies
Main purpose of identifying a set of
functional dependencies for a relation is to
specify the set of integrity constraints that
must hold on a relation.
38
Example 1
39
Example 2
40
Back to Normalisation
Second Normal Form
1NF PLUS every non-key attribute is
fully functionally dependent on the
ENTIRE primary key
Every non-key attribute must be defined by
the entire key, not by only part of the key
No partial functional dependencies
41
Table with no multivalued attributes and unique rows, in 1st
normal form
42
Figure 5-27 Functional dependency diagram for INVOICE
Getting it into
Second Normal
Form
44
Third Normal Form
2NF PLUS no transitive dependencies
(functional dependencies on non-primary-key
attributes)
Note: This is called transitive, because the
primary key is a determinant for another
attribute, which in turn is a determinant for a
third
Solution: Non-key determinant with transitive
dependencies go into a new table; non-key
determinant becomes primary key in the new
table and stays as foreign key in the old table
45
Figure 5-28 Removing partial dependencies
Getting it into
Third Normal
Form
46
Merging Relations
View Integration–Combining entities from
multiple ER models into common relations
Issues to watch out for when merging entities
from different ER models:
Synonyms–two or more attributes with different
names but same meaning (e.g., Student_ID and
Matriculation_No)
Homonyms–attributes with same name but different
meanings (E.g., Account_No)
Transitive dependencies–even if relations are in 3NF
prior to merging, they may not be after merging (e.g.,
Student(ID,Major) and Student(ID,Advisor)
Supertype/subtype relationships–may be hidden prior
to merging e.g. Pat1(ID,Name,Address, 47
Date_treated)& Pat2(ID,Name,Add,Room_No).
Enterprise Keys
48
Figure 5-31 Enterprise keys
a) Relations with
enterprise key
49
Example
50
Introduction to
SQL
1
Previously
▪Logical database design
▪ Anomalies
▪Normalization
▪ Normalization forms
▪ First Normal Form
▪ Functional Dependencies
▪ Second Normal Form
▪ Third Normal Form
2
Contents
▪ history and role of SQL in database development.
▪ Database definition using the SQL data definition language.
▪ Writing single-table queries using SQL commands.
▪ Establishing referential integrity using SQL.
▪ Discussion on SQL:1999 and SQL:200n standards.
3
Target CLO & Taxonomy Level
This content targets CLO 4 at Taxonomy Level 3
4
SQL Overview
Structured Query Language
5
History of SQL
1970–E. Codd develops relational database concept
1974-1979–System R with Sequel (later SQL) created at
IBM Research Lab
1979–Oracle markets first relational DB with SQL
1986–ANSI SQL standard released
1989, 1992, 1999, 2003–Major ANSI standard updates
(2006 and 2008)
Current–SQL is supported by most major database
vendors
6
Purpose of SQL Standard
Specify syntax/semantics for data definition and
manipulation
Define data structures
Enable portability
Allow for later growth/enhancement to standard
Many ‘extensions’ to standards by vendors.
7
Benefits of a Standardized
Relational Language
Reduced training costs
Productivity
Application portability
Application longevity
Reduced dependence on a single vendor
Cross-system communication
8
SQL Environment
Catalog
◦ A set of schemas that constitute the description of a database
◦ Two catalogs are maintained
◦ Dev_C (development catalog)
◦ Prod_C (Production catalog)
Schema
◦ The structure that contains descriptions of objects created by a user
(base tables, views, constraints) (More like database)
9
Figure 7-1
A simplified schematic of a typical SQL environment, as
described by the SQL-2003 standard
10
Figure 7-1
A simplified schematic of a typical SQL environment, as
described by the SQL-2008 standard
11
Types of SQL Statements
Can be divided into three types
◦ Data Definition Language (DDL)
◦ create, modify, or delete database objects such as tables, views, schemas,
domains, triggers, and stored procedures.
◦ The SQL keywords most often associated with DDL statements are CREATE,
ALTER, and DROP
◦ Data Manipulation Language (DML)
◦ Commands that maintain and query a database i.e. statements are used to
retrieve, add,modify, or delete data stored in your database objects. The
primary keywords associated with DML statements are SELECT, INSERT, UPDATE,
and DELETE.
◦ Data Control Language (DCL)
◦ Commands that control a database, including administering privileges
and committing data. GRANT, ADD and REVOKE are primary DCL
commands.
12
Some SQL Data types
13
SQL Database Definition
Data Definition Language (DDL)
Major CREATE statements:
◦ CREATE SCHEMA–defines the schema structure.
◦ CREATE TABLE–defines a table and its columns
◦ CREATE VIEW–defines a logical table from one or more
views
Other CREATE statements: CHARACTER SET(for
globalization), COLLATION, TRANSLATION,
ASSERTION, DOMAIN
14
Table Creation Steps in table creation:
1. Identify data types for
Figure 7-5 General syntax for CREATE TABLE
attributes
2. Identify columns that can
and cannot be null
3. Identify columns that
must be unique
(candidate keys)
4. Identify primary key–
foreign key mates
5. Determine default values
6. Identify constraints on
columns (domain
specifications)
7. Create the table and
associated indexes
15
The following slides create tables for this
enterprise data model
16
Figure 7-6 SQL database definition commands for Pine Valley Furniture
Overall table
definitions
17
Defining attributes and their data types
18
Non-nullable specification
Primary keys
can never have
Identifying primary key NULL values
19
Non-nullable specifications
Primary key
20
Controlling the values in attributes
Default value
Domain constraint
21
Identifying foreign keys and establishing relationships
Primary key of
parent table
Foreign key of
dependent table
22
Data Integrity Controls
Referential integrity–constraint that ensures that foreign key values of a
table must match primary key values of a related table in 1:M
relationships
Restricting:
◦ Deletes of primary records
◦ Updates of primary records
◦ Inserts of dependent records
23
Figure 7-7 Ensuring data integrity through updates
Relational
integrity is
enforced via
the primary-
key to foreign-
key match
24
Changing and Removing
Tables
ALTER TABLE statement allows you to rename tables and
change column specifications:
Syntax: ALTER TABLE table_name
RENAME TO new_table_name;
Syntax: ALTER TABLE table_name
ADD column_name column-definition;
◦ ALTER TABLE CUSTOMER_T ADD (TYPE VARCHAR(2))
25
Changing and Removing
Tables
Modify Columns
Syntax: ALTER TABLE table_name
MODIFY column_name column_type;
Dropping Columns in a table.
ALTER TABLE table_name
DROP COLUMN column_name;
DROP TABLE statement allows you to remove tables
from your schema:
◦ DROP TABLE CUSTOMER_T
26
Schema Definition
Control processing/storage efficiency:
◦ Choice of indexes
◦ File organizations for base tables
◦ File organizations for indexes
◦ Data clustering
◦ Statistics maintenance
Creating indexes
◦ Speed up random/sequential access to base table data
◦ Example
◦ CREATE INDEX NAME_IDX ON CUSTOMER_T(CUSTOMER_NAME)
◦ This makes an index for the CUSTOMER_NAME field of the CUSTOMER_T
table
27
Insert Statement
Adds data to a table
Inserting into a table
◦ INSERT INTO CUSTOMER_T VALUES (001, ‘Contemporary Casuals’,
‘1355 S. Himes Blvd.’, ‘Gainesville’, ‘FL’, 32601);
Inserting a record that has some null attributes requires
identifying the fields that actually get data
◦ INSERT INTO PRODUCT_T (PRODUCT_ID, PRODUCT_DESCRIPTION,PRODUCT_FINISH,
STANDARD_PRICE, PRODUCT_ON_HAND) VALUES (1, ‘End Table’, ‘Cherry’, 175, 8);
28
Delete Statement
Removes rows from a table
Delete certain rows
◦ DELETE FROM CUSTOMER_T WHERE STATE = ‘HI’;
29
Update Statement
Modifies data in existing rows
30
SELECT Statement
Used for queries on single or multiple tables
Clauses of the SELECT statement:
◦ SELECT
◦ List the columns (and expressions) that should be returned from the query
◦ FROM
◦ Indicate the table(s) or view(s) from which data will be obtained
◦ WHERE
◦ Indicate the conditions under which a row will be included in the result
◦ GROUP BY
◦ Indicate categorization of results
◦ HAVING
◦ Indicate the conditions under which a category (group) will be included
◦ ORDER BY
◦ Sorts the result according to specified criteria
31
SELECT Example
Find products with standard price less than $275
32
SELECT Example Using Alias
Alias is an alternative column or table name
33
SELECT Example
Using a Function
Functions implemented by most DBMSs
◦ COUNT Returns the number of rows
◦ SUM Returns the total of the values in a column from a group of
rows
◦ AVG Returns the average of the values in a column from a group of
rows
◦ MIN Returns the minimum value in a column from among a group
ofrows
◦ MAX Returns the maximum value in a column from among a group
of rows
34
Using the aggregate functions.
SELECT COUNT(*) FROM ORDER_LINE_V
WHERE ORDER_ID = 1004;
SELECT SUM(population) from city
where city.district = 'Zuid-Holland';
SELECT AVG(population) from city
where city.district = 'Zuid-Holland';
SELECT MIN(population) from city;
SELECT MAX(population) from city;
35
SELECT Example–Boolean Operators
AND, OR, and NOT Operators for customizing conditions in
WHERE clause
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
36
SELECT Example –
sorting results with the ORDER BY clause
and selecting a list of values with IN clause.
Note: the IN operator in this example allows you to include rows whose
STATE value is either FL, TX, CA, or HI. It is more efficient than separate
OR conditions
37
Result
38
SELECT Example–
Categorizing Results Using the GROUP BY Clause
For use with aggregate functions
◦ Scalar aggregate: single value returned from SQL query with aggregate
function
◦ Vector aggregate: multiple values returned from SQL query with aggregate
function (via GROUP BY)
39
Result
40
SELECT Example–
Qualifying Results by Categories
Using the HAVING Clause
For use with GROUP BY
Like a WHERE clause, but it operates on groups (categories), not on individual rows.
Here, only those groups with total numbers greater than 1 will be included in final
result
41
Result
42
Using and Defining Views
Views provide users controlled access to tables
Base Table–table containing the raw data
Dynamic View
◦ A “virtual table” created dynamically upon request by a user
◦ No data actually stored; instead data from base table made available to user
◦ Based on SQL SELECT statement on base tables or other views
Materialized View
◦ Copy or replication of data
◦ Data actually stored
◦ Must be refreshed periodically to match the corresponding base tables
43
Sample CREATE VIEW
CREATE VIEW EXPENSIVE_STUFF_V AS
SELECT PRODUCT_ID, PRODUCT_NAME, UNIT_PRICE
FROM PRODUCT_T
WHERE UNIT_PRICE >300;
44
Advantages of Views
Simplify query commands
Assist with data security (but don't rely on views for security, there are more
important security measures)
Enhance programming productivity
Contain most current base table data
Use little storage space
Provide customized view for user
45
Disadvantages of Views
Use processing time each time view is referenced
May or may not be directly updateable
46
END OF LECTURE
47
Introduction to Database
Systems
WEEK 13
Advanced SQL
1
Previously
• Introduction to SQL
• MySQL environment
• Basic SQL statements
• Create
• Alter
• Drop
• Single Table DML Statements
• Insert
• Delete
• Update
• Select and various clauses
2
Contents
• Write multiple table SQL queries
• Define and use three types of joins
• Write subqueries
• Understand triggers and stored procedures
3
Target CLOs & Taxonomy Levels
4
Processing Multiple Tables–Joins
• Join–a relational operation that causes two or more tables with a common
domain to be combined into a single table or view
• Equi-join–a join in which the joining condition is based on equality
between values in the common columns; common columns appear
redundantly in the result table
• Natural join–an equi-join in which one of the duplicate columns is
eliminated in the result table
• 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)
• Union join–includes all columns from each table in the join, and an
instance for each row of each table
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
5
MySql Supported Join statements
6
The following slides create tables for this
enterprise data model
7
Figure 8-1 Pine Valley Furniture Company Customer and Order
tables with pointers from customers to their orders
8
Equi-Join or Inner Join
9
Natural Join Example
CUSTOMER_T.CUSTOMER_ID = ORDER_T.CUSTOMER_ID;
11
Results
Unlike
INNER
join, this
will include
customer
rows with
no
matching
order rows
12
Multiple Table Join Example
• Assemble all information necessary to create an invoice for order
number 1006 Four tables involved in this join
SELECT CUSTOMER_T.CUSTOMER_ID, CUSTOMER_NAME, CUSTOMER_ADDRESS, CITY, SATE,
POSTAL_CODE, ORDER_T.ORDER_ID, ORDER_DATE, QUANTITY, PRODUCT_DESCRIPTION,
STANDARD_PRICE, (QUANTITY * UNIT_PRICE)
FROM CUSTOMER_T, ORDER_T, ORDER_LINE_T, PRODUCT_T
13
Figure 8-2 Results from a four-table join
14
Union Join
15
Union Queries
• Combine the output (union of multiple queries)
together into a single result table
First query
Combine
Second query
16
End of Lecture
17
Introduction to Database
Systems
WEEK 14
Advanced SQL
Part II
18
Previously
19
Contents
• Write subqueries
• Correlated vs Non-correlated subqueries
• Combining queries (union)
• Transaction integrity (commit/roll back)
• SQL triggers
• Stored procedures
• Embedded and Dynamic SQL
20
Target CLOs & Taxonomy Levels
21
Processing Multiple Tables
Using Subqueries
• Subquery–placing an inner query (SELECT
statement) inside an outer query
22
Using Join
23
Same Query Using subquery
24
Subquery Example
Subquery is embedded in
parentheses. In this case it
returns a list that will be used
in the WHERE clause of the
outer query
25
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
26
Processing a
noncorrelated
subquery
No reference to data in
outer query, so
1. The subquery
subquery executes once
executes and only
returns the
customer IDs from
the ORDER_T table
27
Correlated Subquery Example
28
Figure
Processing a
correlated Subquery refers to outer-
subquery query data, so executes once
for each row of outer query
29
Correlated or Non-correlated??
30
Combining Queries (Union Join)
31
Union Queries
• Combine the output (union of multiple queries)
together into a single result table
First query
Combine
Second query
• Just like UNION, we can also use INTERSECT and MINUS operations
on two queries for combined output.
• INTERSECT return common records in two sets
• MINUS returns all records of SET A which are not in SET B
• There is no INTERSECT and MINUS operations in MySQL
33
Conditional Expressions
34
Ensuring Transaction Integrity
35
Figure 8-5 An SQL Transaction sequence (in pseudocode)
36
Data Dictionary Facilities
• System tables that store metadata
• Users usually can view some of these tables
• Users are restricted from updating them
• Some examples in Oracle 10g
• DBA_TABLES–descriptions of tables
• DBA_CONSTRAINTS–description of constraints
• DBA_USERS–information about the users of the system
• Examples in Microsoft SQL Server 2000
• SYSCOLUMNS–table and column definitions
• SYSDEPENDS–object dependencies based on foreign keys
• SYSPERMISSIONS–access permissions granted to users
37
Routines and Triggers
• Routines
• Program modules that execute on demand
• Functions–routines that return values and take input parameters
• Procedures–routines that do not return values and can take input or output
parameters
• Triggers
• Routines that execute in response to a database event (INSERT, UPDATE, or
DELETE)
38
Figure 8-6 Triggers contrasted with stored procedures
Procedures are called explicitly
39
Figure 8-7 Simplified trigger syntax, SQL:2003
40
Trigger Example
41
Stored Procedure Example
42
Embedded and Dynamic SQL
• Embedded SQL
• Including hard-coded SQL statements in a program written in another
language such as C or Java
• Dynamic SQL
• Ability for an application program to generate SQL code on the fly, as the
application is running
43
END OF LECTURE
44
Introduction to Database
Systems
WEEK 14
Advanced SQL
Part II
1
Previously
2
Contents
• Write subqueries
• Correlated vs Non-correlated subqueries
• Combining queries (union)
• Transaction integrity (commit/roll back)
• SQL triggers
• Stored procedures
• Embedded and Dynamic SQL
3
Target CLOs & Taxonomy Levels
4
Processing Multiple Tables
Using Subqueries
• Subquery–placing an inner query (SELECT
statement) inside an outer query
5
Using Join
6
Same Query Using subquery
7
Subquery Example
Subquery is embedded in
parentheses. In this case it
returns a list that will be used
in the WHERE clause of the
outer query
8
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
9
Processing a
noncorrelated
subquery
No reference to data in
outer query, so
1. The subquery
subquery executes once
executes and only
returns the
customer IDs from
the ORDER_T table
10
Correlated Subquery Example
11
Figure
Processing a
correlated Subquery refers to outer-
subquery query data, so executes once
for each row of outer query
12
Correlated or Non-correlated??
13
Combining Queries (Union Join)
14
Union Queries
• Combine the output (union of multiple queries)
together into a single result table
First query
Combine
Second query
• Just like UNION, we can also use INTERSECT and MINUS operations
on two queries for combined output.
• INTERSECT return common records in two sets
• MINUS returns all records of SET A which are not in SET B
• There is no INTERSECT and MINUS operations in MySQL
16
Conditional Expressions
17
Ensuring Transaction Integrity
18
Figure 8-5 An SQL Transaction sequence (in pseudocode)
19
Data Dictionary Facilities
• System tables that store metadata
• Users usually can view some of these tables
• Users are restricted from updating them
• Some examples in Oracle 10g
• DBA_TABLES–descriptions of tables
• DBA_CONSTRAINTS–description of constraints
• DBA_USERS–information about the users of the system
• Examples in Microsoft SQL Server 2000
• SYSCOLUMNS–table and column definitions
• SYSDEPENDS–object dependencies based on foreign keys
• SYSPERMISSIONS–access permissions granted to users
20
Routines and Triggers
• Routines
• Program modules that execute on demand
• Functions–routines that return values and take input parameters
• Procedures–routines that do not return values and can take input or output
parameters
• Triggers
• Routines that execute in response to a database event (INSERT, UPDATE, or
DELETE)
21
Figure 8-6 Triggers contrasted with stored procedures
Procedures are called explicitly
22
Figure 8-7 Simplified trigger syntax, SQL:2003
23
Trigger Example
24
Stored Procedure Example
25
Embedded and Dynamic SQL
• Embedded SQL
• Including hard-coded SQL statements in a program written in another
language such as C or Java
• Dynamic SQL
• Ability for an application program to generate SQL code on the fly, as the
application is running
26
END OF LECTURE
27
Introduction to Database
Systems
WEEK 15
Advanced SQL
Stored Procedures & Triggers
1
Previously
• Write subqueries
• Correlated vs Non-correlated subqueries
• Combining queries (union)
• Transaction integrity (commit/roll back)
• SQL triggers
• Stored procedures
2
Contents
• Stored procedures
• SQL triggers
• Embedded and Dynamic SQL
• MySQL Implementation
• Write subqueries
• Correlated vs Non-correlated subqueries
• Combining queries (union)
• Transaction integrity (commit/roll back)
• Stored procedures
• SQL triggers
3
Target CLOs & Taxonomy Levels
4
Routines and Triggers
• Routines
• Program modules that execute on demand
• Functions–routines that return values and take input parameters
• Procedures–routines that do not return values and can take input or output
parameters
• Triggers
• Routines that execute in response to a database event (INSERT, UPDATE, or
DELETE)
5
Figure 8-6 Triggers contrasted with stored procedures
Procedures are called explicitly
6
Stored Procedure Example
7
MySQL Syntax
• Creating Procedure
DELIMITER //
DELIMITER ;
• Calling procedure
CALL GetAllProducts();
8
MySQL stored procedure parameters
DELIMITER ;
9
MySQL stored procedure parameters
DELIMITER $$
DELIMITER ;
10
Calling procedure with parameters
CALL GetOrderCountByStatus('Shipped',@total,@remaining);
SELECT @total,@remaining;
11
Stored Functions vs Procedures
Functions Procedures
A function has a return type and returns a value. A procedure does not have a return type. But it
returns values using the OUT parameters.
You cannot use a function with Data Manipulation You can use DML queries such as insert, update, select
queries. Only Select queries are allowed in functions. etc… with procedures.
A function does not allow output parameters A procedure allows both input and output parameters.
You cannot manage transactions inside a function. You can manage transactions inside a procedure.
You cannot call stored procedures from a function You can call a function from a stored procedure.
You can call a function using a select statement. You cannot call a procedure using select statements.
12
Stored Functions
DELIMITER $$
DELIMITER ;
13
Stored Functions
DELIMITER $
CREATE FUNCTION getCustomers(state VARCHAR(2))
RETURNS INT
DETERMINISTIC
BEGIN
DECLARE x int;
Select count(*) into x from customer_t where CustomerState=state;
RETURN x;
END $
DELIMITER ;
• Triggers
• Routines that execute in response to a database event (INSERT, UPDATE, or
DELETE)
• Triggers are useful for tasks such as enforcing business rules, validating input
data, and keeping an audit trail.
15
Figure 8-7 Simplified trigger syntax, SQL:2003
16
MySQL Trigger
Delimiter $$
CREATE TRIGGER trigger_name
{BEFORE | AFTER} {INSERT | UPDATE| DELETE }
ON table_name FOR EACH ROW
BEGIN
trigger_body;
END $$
Delimiter ;
• If you want to execute multiple statements, you use the BEGIN END
compound statement otherwise not needed.
17
Insert Trigger Example
Delimiter $$
Drop trigger if exists safety_trg;
Create trigger safety_trg
After insert on order_t for each row
Begin
Insert into order1_t(order1_t.OrderID, order1_t.CustomerID,
order1_t.OrderDate) values (new.orderID, new.customerID, new.orderDate);
End $$
Delimiter ;
In this case order1_t should be replicated table which would store a copy of
each new row inserted into the order table.
18
Update trigger example
Delimiter $$
Drop trigger if exists price_udpate;
Create trigger price_udpate
After update on product_t for each row
Begin
Insert into pricehistory_t(productid, updatedprice, pricehistory.date)
values (old.productid , new.productstandardprice, NOW());
End $$
Delimiter ;
19
Embedded and Dynamic SQL
• Embedded SQL
• Including hard-coded SQL statements in a program written in another
language such as C or Java
• Dynamic SQL
• Ability for an application program to generate SQL code on the fly, as the
application is running
20
END OF LECTURE
21
INTRODUCTION TO DATABASE SYSTEMS
DATA WAREHOUSING
Dr. Sohail
Data Mart
A data warehouse that is limited in scope
T
E
Separate ETL for each Data access complexity
independent data mart due to multiple data marts
Chapter 9 Copyright © 2016 Pearson Education, Inc. 9-9
Figure 9-3 Dependent data mart with ODS provides option for
operational data store: a three-level architecture obtaining current data
T
E
Simpler data access
Single ETL for Dependent data marts
enterprise data warehouse (EDW) loaded from EDW
Chapter 9 Copyright © 2016 Pearson Education, Inc. 9-10
Figure 9-4 Logical data mart and real
ODS and data warehouse
time warehouse architecture are one and the same
T
E
Near real-time ETL for Data marts are NOT separate databases,
Data Warehouse but logical views of the data warehouse
➔ Easier to create new data marts
Chapter 9 Copyright © 2016 Pearson Education, Inc. 9-11
DATA CHARACTERISTICS
STATUS VS. EVENT DATA
Figure 9-6
Example of DBMS
Status log entry
Event = a
database action
(create/ update/
delete) that
results from a
transaction
Status
With transient
data, changes
to existing
records are
written over
previous
records, thus
destroying the
previous data
content.
Periodic data
are never
physically
altered or
deleted once
they have been
added to the
store.
Excellent for ad-hoc queries, but bad for online transaction processing
Chapter 9 Copyright © 2016 Pearson Education, Inc. 9-16
Figure 9-10 Star schema example
Conformed
dimension
Associated with
multiple fact
tables
Sisense
Microsoft Power BI
Clear analytics