Dim 1 Notes
Dim 1 Notes
The
University’s
File-Based
System
Duplication of data
✓ Same data is held by different programs.
✓ Wasted space and potentially different values and/or
different formats for the same item.
Self-describing
◼ System catalogue contains metadata (data defining other
data).
◼ Catalogue contain information about the definitions of the
database objects (for example, tables, views)and security
information about the type of access that users have to these
objects.
19
Database Management System (DBMS)
Users
2
ANSI SPARC 3 LEVEL DATABASE ARCHITECTURE
External Level
Users' view of the database.
Describes that part of database that is relevant to a
particular user.
Conceptual Level
Content view of the database.
Describes what data is stored in database and
relationships among the data. Also describes the
constraints.
4
ANSI-SPARC THREE-LEVEL
ARCHITECTURE
Internal Level
Physical representation of the database on the computer.
Describes how the data is stored in the database.
Describes the definitions of the stored records, the
representations, data fields, etc
5
ANSI-SPARC THREE-LEVEL
ARCHITECTURE
6
DIFFERENCES BETWEEN THREE LEVELS
OF ANSI-SPARC ARCHITECTURE
7
OBJECTIVES OF THREE-LEVEL
ARCHITECTURE
Allusers should be able to access same
data.
Internal
structure of database should be unaffected
by changes to physical aspects of storage.
9
MAPPINGS
10
DATA INDEPENDENCE
Data Independence means that the higher levels of the
database model are designed to be unaffected by changes to
the lower levels (internal and physical). There are two types
of Data Independence.
11
DATA INDEPENDENCE
Logical Data Independence
Refers to immunity of external schemas to
changes in conceptual schema.
Conceptual schema changes (e.g.
addition/removal of entities) should not require
changes to external schema or rewrites of
application programs.
12
DATA INDEPENDENCE
13
DATA INDEPENDENCE AND THE ANSI-
SPARC THREE-LEVEL ARCHITECTURE
14
DATABASE PLANNING, DESIGN
AND ADMINISTRATION
OBJECTIVES
Main components of an information system.
Main stages of database application lifecycle.
Main phases of database design: conceptual,
logical, and physical design.
How to evaluate and select a DBMS.
2
DATABASE DEVELOPMENT LIFECYCLE /
DATABASE SYSTEM LIFECYCLE
Consists of 11 steps which are not strictly
sequential but are iterative to some extent; there
are feedback loops between most stages of the
lifecycle.
Database planning
System definition
Database design 8
9
STAGES OF THE DATABASE
APPLICATION LIFECYCLE
10
STEP 1: DATABASE PLANNING
Management activities that allow stages of
database application lifecycle to be realized
as efficiently and effectively, as possible.
Must be integrated with overall IS strategy of
the organization.
What the database application is going to
do.
To what area it will be applied.
11
DATABASE PLANNING – MISSION
STATEMENT
13
DATABASE PLANNING
Databaseplanning should also include
development of standards that govern:
how data will be collected,
how the format should be specified,
what necessary documentation will be needed,
how design and implementation should proceed.
This step is critical and takes a lot of time in
terms of development and maintenance, but
provides a good basis for staff training and
15
quality control.
STEP 2: SYSTEM DEFINITION
Describes scope and boundaries of database
application and the major user views (both current
and future). It also involves describing or
identifying how it interfaces with the other
parts of the organization's information
system.
User view defines what is required of a database
application from perspective of:
a particular job role (such as Manager or
Supervisor) or
enterprise application area (such as marketing,
personnel, or stock control).
16
SYSTEM DEFINITION
Databaseapplication may have one or more user
views and each user view presents the data
(what data is to be held or is needed) and
transaction (what will be done with that
data) requirements of a system.
Identifyinguser views helps ensure that no major
users of the database are forgotten when
developing requirements for new application
(Requirement Elicitation).
Userviews also help in development of complex
database application allowing requirements to be
broken down into manageable pieces.
18
REPRESENTATION OF A DATABASE
APPLICATION WITH MULTIPLE USER
VIEWS
19
STEP 3: REQUIREMENTS
COLLECTION AND ANALYSIS
Process of collecting and analyzing
information about the part of organization
to be supported by the database application,
and using this information to identify users’
requirements of new system.
20
REQUIREMENTS COLLECTION
AND ANALYSIS
Information is gathered for each major user view
including:
a description of data used or generated
details of how data is to be used/generated
any additional requirements for new database
application.
centralized approach
view integration approach
combination of both approaches.
23
CENTRALIZED APPROACH TO
MANAGING MULTIPLE USER VIEWS
25
REQUIREMENTS COLLECTION
AND ANALYSIS
View integration approach
Requirements for each user view are used to
build a separate data model.
Suitable when there are significant
differences between the user views and the
database application is sufficiently complex
and requires to be broken into manageable
pieces.
26
VIEW INTEGRATION APPROACH TO
MANAGING MULTIPLE USER VIEWS
28
STEP 4: DATABASE DESIGN
Process of creating a design for a
database that will support the
enterprise’s operations and
objectives.
30
DATABASE DESIGN
Approaches include:
Top-down
Bottom-up
Inside-out
Mixed
Most Commonly used are the Top-down
(Starts with a general overview and
details keep being added) and Bottom-up
approaches (Overall design is constructed
from the smaller details).
32
DATABASE DESIGN
Top-down:
Starts by developing a model containing few
high-level entities and relationships, after
which low level entities are identified. For
example the ER model. Suitable for complex
databases.
Bottom-up:
34
DATABASE DESIGN
Inside-out:
This approach is a variant of or related to the
bottom-up approach but differs by first
identifying the major entities then spreads out
to consider other entities, relationships and
attributes associated with the first one.
Mixed:
Combines both top-down and bottom-up in
different aspects of the model before finally
combining all the parts.
35
DATABASE DESIGN
Data modeling
This is the process of building data models to
represent a designer’s understanding of the
information requirements of an enterprise
Data modeling is a method used to define and
analyze data requirements needed to support
the business processes of an organization
Main purposes of data modeling include:
36
DATABASE DESIGN
Answering such questions enables one to
understand each user view’s perspective of the
data, nature of the data itself, independent of its
physical representations; and use of data across
user views.
To facilitate communication about the information
requirements.
Data models are a means by which a designer
conveys his/her understanding of an enterprise’s
information requirements.
Provided the two parties are familiar with the
notation, these provide a basis for
communication e.g. Entity Relationship
37
Diagrams (ERD).
DATABASE DESIGN
Three phases of database design:
39
THREE-LEVEL ANSI-SPARC
ARCHITECTURE AND PHASES OF
DATABASE DESIGN
40
PHYSICAL DATABASE DESIGN
Thephysical database design deals with
the how while the logical and conceptual
design deal with the what.
48
STEP 5: DBMS SELECTION
(OPTIONAL)
This is done at any time prior to the Logical
database design phase provided there is
sufficient information regarding the systems
requirements e.g. performance, security and
integrity constraints.
The DBMS selection process must cater for the
enterprise’s current and future requirements, at
an optimum cost (purchase of the DBMS,
additional hardware/software, changeover costs
and staff training) as there may be need to
expand or replace the system.
55
DBMS SELECTION
Selection of an appropriate DBMS to
support the database application.
Main steps to selecting a DBMS:
define Terms of Reference of study
shortlist two or three products
evaluate products
recommend selection and produce report.
56
STEP 6: APPLICATION DESIGN
Design of user interface and application programs
that use and process the database.
61
APPLICATION DESIGN - TRANSACTIONS
This involves designing the application programs
that access the database and the transactions
(access methods).
This design provides a description of how the
functionality of the database application will be
achieved.
A transaction is an action, or series of
actions, carried out by a single user or
application program, which accesses or
changes content of the database.
For example, cash withdrawal, cash deposit, etc
62
APPLICATION DESIGN -
TRANSACTIONS
The purpose of the transaction design is to define
and document the high-level characteristics of the
transactions required
64
STEP 7: PROTOTYPING
(OPTIONAL)
It involves building a working model of a
database application.
It does not have all the required features functionality.
Purpose
to identify features of a system that work well,
or are inadequate
to suggest improvements or even new features
to clarify the users’ requirements
to evaluate feasibility of a particular system
design.
66
STEP 8: IMPLEMENTATION
Physical realization of the database and
application designs.
Database implementation is achieved using the data
definition language (DDL) of the selected DBMS.
68
STEP 9: DATA CONVERSION AND
LOADING
Transferring any existing data into new database
and converting any existing applications to run on
new database.
70
STEP 10: TESTING
71
STEP 11: OPERATIONAL
MAINTENANCE
Process of monitoring and maintaining
system following installation.
Monitoring performance of system.
if performance falls, may require tuning or
reorganization of the database.
Maintaining and upgrading database
application (when required).
Incorporating new requirements into database
application.
72
END
77
1
8
Database Relations
9
Relation schema
Named relation defined by a set of attribute and domain name pairs.
Employee Table
Alternate Keys
Candidate keys that are not selected to be
primary key.
Foreign Key
Attribute, or set of attributes, within one
relation that matches candidate key of some
(possibly same) relation.
Composite Key
A candidate key that consists of two or more attributes.
13 Relational Integrity
Null
Referential Integrity
If foreign key exists in a relation, either foreign
key value must match a candidate key value
of some tuple in its home relation or foreign
key value must be wholly null.
Enterprise Constraints
Additional rules specified by users or database administrators. E.g No
student is allowed to register beyond a given no. Of courses in a
semester.
16
Types of Relations
Base Relation
Named relation corresponding to an entity in
conceptual schema, whose tuples are
physically stored in database.
View Relation
Dynamic result of one or more relational
operations operating on base relations to
produce another relation.
Two main types of connection traps are called fan traps and chasm
traps.
6 Problems with ER Models
Fan Trap
Where a model represents a relationship between
entity types, but pathway between certain entity
occurrences is ambiguous.
Chasm Trap
Where a model suggests the existence of a
relationship between entity types, but pathway
does not exist between certain entity occurrences.
7 An Example of a Fan Trap
8 Semantic Net of ER Model with
Fan Trap
Relationship occurrence
Uniquely identifiable association, which includes one occurrence from each
participating entity type.
Semantic net of Has relationship
type
26
28 Relationship Types
Degree of a Relationship
Number of participating entities in relationship.
Types
One is cyclic
two is binary
three is ternary
four is quaternary.
More than two is tertiary. These are normally broken down into multiple cyclic and binary
relationships.
Binary relationship called POwns
29
30 Ternary relationship called
Registers
31 Quaternary relationship called
Arranges
32 Relationship Types
Recursive Relationship
Relationship type where same entity type participates more than once in different
roles.
Cardinality
1/25/2024
1
EER
1/25/2024
All modeling concepts of basic ER
Additional concepts:
4
subclasses/superclasses
specialization/generalization
1/25/2024
Two steps in EER modelling include:
removing all aspects that are not
acceptable in the relational model
and
identifying and adequately
representing
specialization/generalization.
5
UNACCEPTABLE ASPECTS
1/25/2024
many-to many relationships
composite attributes
multi valued attributes
cyclic relationships and
tertiary relationships.
6
ELIMINATION OF THESE ASPECTS
Many-to-many relationships:
Break them up and create two one to
1/25/2024
many relationships with a weak entity
in between the initially participating
entities
Composite attributes:
1/25/2024
Cyclic Relationships:
Eliminate them and create an entity
along the relationship so as to create
two binary relationships
Tertiary relationships:
1/25/2024
Issues of specialization and generalization are
associated with the superclass and subclass
entities.
Supertypes/ Super classes and subtypes/ sub
classes are used when there exist entities which
share common properties.
The entity supertype contains the shared
properties of all the subtypes.
An entity subtype has a more specific role and
belongs to a supertype.
9
SPECIALIZATION / GENERALIZATION
Superclass
1/25/2024
An entity type that includes one or more distinct
subgroupings of its occurrences.
Subclass
SALARIED_EMPLOYEE HOURLY_EMPLOYEE
HOURLY_EMPLOYEE
1/25/2024 12
EXAMPLE
Lname SSN
Fname Addr
1/25/2024
DEPARTMENT WORKS EMPLOYEE
14
d
TypingSpeed MANAGER
TGrade EngType HOURLY_EMP
1/25/2024
An entity CANNOT exist in the DB merely by
being a member of a subclass. It must also be a
member of the superclass.
18
An entity can be a member of more than one
subclass.
Example: A salaried employee who is also an
engineer belongs to the two subclasses
ENGINEER and SALARIED_EMPLOYEE
It is not necessary that every entity in a
superclass be a member of some subclass
Example: A technical writer is an employee
but does not belong to any subclasses.
ATTRIBUTE INHERITANCE IN SUPERCLASS /
SUBCLASS RELATIONSHIPS
1/25/2024
The type of an entity is defined by the
attributes it possesses and the relationship
types which it participates in.
19
An entity that is a member of a subclass
inherits all the attributes of the entity as a
member of the superclass, as well as all the
relationships in which the superclass
participates.
EXAMPLE
Lname SSN
Addr EMPLOYEE
Fname
Fname, Lname, SSN, Addr
SECRETARY
EMPLOYEE Fname, Lname, SSN, Addr TypingSpeed
TECHNICIAN
Fname, Lname, SSN, Addr, TGrade
d ENGINEER
Fname, Lname, SSN, Addr, EngType
TypingSpeed EngType
TGrade
SECRETARY ENGINEER
TECHNICIAN
1/25/2024 20
EXAMPLE
1/25/2024
d
d
21
TypingSpeed MANAGER
TGrade EngType HOURLY_EMP
1/25/2024
Generalization is the reverse of specialization
process. It defines a generalized entity type from
the given entity types.
25
A bottom-up design process – combine a number
of entity sets that share the same features into a
higher-level entity set.
Specialization and generalization are simple
inversions of each other; they are represented in
an E-R diagram in the same way.
The terms specialization and generalization are
used interchangeably
GENERALIZATION (CONT.)
MaxSpeed Tonnage
CAR Price TRUCK Price
VehicleID VehicleID
VEHICLE
NoOfPassengers d NoOfAxies
MaxSpeed
CAR TRUCK Tonnage
1/25/2024 26
GENERALIZATION (CONT.)
1/25/2024
We can view {CAR, TRUCK} as a specialization of
VEHICLE
27
Alternatively, we can view VEHICLE as a
generalization of CAR and TRUCK
SPECIALIZATION / GENERALIZATION
Specialization
1/25/2024
Process of maximizing differences between
occurrences of an entity by identifying their
distinguishing characteristics.
Generalization
Process of minimizing differences between
entities by identifying their common
characteristics.
28
CONSTRAINTS ON
SPECIALIZATION/GENERALIZATION
1/25/2024
Disjoint Constraints: Disjointness (OR) vs.
Overlap Constraints (Nondisjoint, AND)
29
Participation / Completeness Constraints: A
total specialization (Mandatory)vs. a partial
(Optional) specialization
DISJOINTNESS CONSTRAINT
1/25/2024
Disjointness(d) constraint (OR) specifies that the
subclasses of the specialization must be disjointed (an
30
entity can be a member of at most one of the subclasses
of the specialization)
EMPLOYEE
d d
1/25/2024
Overlap(o) (AND) specifies that the subclasses
are not constrained to be disjoint, i.e., the same
(real-world) entity may be a member of more
32
than one subclass of the specialization.
Overlap is the default constraint and displayed
by placing an o in the circle.
COMPLETENESS (PARTICIPATION)
CONSTRAINT
1/25/2024
Completeness constraint may be total or
partial.
33
A total specialization (Mandatory) constraint
specifies that every entity in the superclass must
be a member of some subclass in the
specialization.
1/25/2024
A partial specialization (Optional) allows an
entity not to belong to any of the subclasses,
using a single line in EER.
34
e.g., if some EMPLOYEE entities, for example,
sales representatives, do not belong to any of the
subclasses {SECRETARY, ENGINEER,
TECHNICIAN}, then the specialization is
partial.
1/25/2024
The disjointness and completeness constraints
are independent.
35
There are four possible constraints on
specialization:
Disjoint, total (Mandatory, Or)
Disjoint, partial (Optional, Or)
Overlapping, total (Mandatory, And)
Overlapping, partial (Optional, And)
SPECIALIZATION/GENERALIZATION OF STAFF ENTITY
INTO SUBCLASSES REPRESENTING JOB ROLES
1/25/2024
37
EER DIAGRAM WITH SHARED SUBCLASS AND
SUBCLASS WITH ITS OWN SUBCLASS
1/25/2024
38
DREAMHOME WORKED EXAMPLE - STAFF SUPERCLASS
WITH SUPERVISOR AND MANAGER SUBCLASSES
1/25/2024
39
DREAMHOME WORKED EXAMPLE - OWNER SUPERCLASS WITH
PRIVATEOWNER AND BUSINESSOWNER SUBCLASSES
1/25/2024
40
DREAMHOME WORKED EXAMPLE - PERSON SUPERCLASS
WITH STAFF, PRIVATEOWNER, AND CLIENT SUBCLASSES
1/25/2024
41
SOME INSERTION AND DELETION RULES
APPLIED TO SPECIALIZATION/GENERALIZATION
1/25/2024
Deleting an entity from a superclass implies that
it is automatically deleted from all the subclasses
to which it belongs
42
Inserting an entity in a superclass implies that
the entity is mandatorily inserted in all
applicable subclasses.
Inserting an entity in a superclass of a total
specialization implies that the entity is
mandatorily inserted in at least one of the
subclasses of the specialization.
THE DIFFERENCES BETWEEN THE
SPECIALIZATION AND GENERALIZATION
1/25/2024
The specialization process corresponds to a top-
down conceptual refinement process during
conceptual schema design.
43
we typically start with an entity type and then
define subclasses of the entity type by
successive specialization;
The generalization process corresponds to a
bottom-up conceptual synthesis.
we typically start with an entity type of
subclasses and then define superclasses of the
entity type by successive generalization.
FOOD FOR THOUGHT
1/25/2024
Assuming we have entities staff and students in
a conceptual model of a university, propose ways:
44
LECTURE SIX
Advanced select statement
Join
Other DML commands
1
SELECTING FROM MULTIPLE TABLES
❑ You are not limited to selecting from only one table. When
you select from more than one table in one select statement,
you are said to be joining tables together.
❑ When you want to select from both tables at once, there are a
few differences in the syntax of the select statement.
❑ You need to ensure that all the tables you are using appear in
the FROM clause of the select statement.
4.2
SELECTING FROM MULTIPLE TABLES
Suppose you have two tables, fruit and color; you can
select all rows from each of the two tables.
Fruit Color
ID FRUITNAME ID COLORNAME
1 Apple 1 Red
2 Orange 2 Orange
3 Grape 3 Purple
4 Banana 4 Yellow
4.3
SELECTING FROM MULTIPLE TABLES
❑ Note: When you select from multiple tables, you must build
proper WHERE clauses to ensure that you get the result you
want.
From the fruit and color tables, the query for selecting
fruitname and colorname from both tables where the id’s
match would be;
4.5
SELECTING FROM MULTIPLE TABLES
Result
ID FRUITNAME COLORNAME
1 Apple Red
2 Orange Orange
3 Grape Purple
4 Banana Yellow
4.8
LEFT JOIN
❑ Here, all rows from the first table will be returned, no matter
if there are matches in the second table or not.
4.9
LEFT JOIN
Master_name Table id firstname lastname
1 John Smith
2 Jane Smith
3 Jimbo Jones
4 Andy Smith
7 Chris Jones
45 Anna Bell
44 Jimmy Carr
43 Albert Smith
42 John Doe
4.10
LEFT JOIN
Using LEFT JOIN, you can see that if a value from the e-mail
table doesn’t exist, a null will appear in place of the email
address.
4.11
LEFT JOIN
firstname lastname Email
John Smith null
Jane Smith null
Jimbo Jones null
Andy Smith null
Chris Jones null
Anna Bell [email protected]
Jimmy Carr null
Albert Smith null
John Doe [email protected]
4.12
RIGHT JOIN
Works like a LEFT JOIN, but with the table order reversed.
When using RIGHT JOIN, all rows from the second table
will be returned no matter whether there are matches in the
first table or not.
Example
Mysql>SELECT firstname, lastname, Email
FROM Master_name RIGHT JOIN Email
ON Master_name.id= Email.id;
4.13
RIGHT JOIN
firstname lastname Email
Result Table John Doe [email protected]
Anna Bell [email protected]
http://www.mysql.com/doc/J/O/JOIN.html
4.14
Other DML Commands
UPDATE command is used to modify contents of one or
more columns in an existing record. The most basic update
syntax is as follows:
UPDATE table_name
SET column1 = “new value”,Column2 = “new value”
[Where some_condition_is_true];
The rules for updating a record are similar to those used when
inserting a record:
4.15
UPDATE Command
1. The data you are entering must be appropriate to the data type
of the field and
2. You must enclose your strings in single or double quotes.
Example
Consider the fruit table below:
Id Fruit_name status
1 Apple Ripe
2 Pear Rotten
3 Banana Ripe
4 Grape Rotten
4.16
UPDATE Command
To update the status of the fruit to “ripe”, use
Mysql>UPDATE fruit SET status = ‘Ripe’;
The above query will update all the data in the column in
question
NOTE: It is important to incorporate the WHERE condition
to specify a particular condition.
4.18
The REPLACE Command
Another method for modifying records is to use the
REPLACE command which is remarkably similar to the
INSERT.
Example
4.20
Lecture Nine: Normalization
Introduction to Normalization:
redundancy, anormalies?
1st – 3rd Normal Forms
1/25/2024 1
Objectives
Purpose of normalization.
Problems associated with redundant data.
Identification of various types of update anomalies such as
insertion, deletion, and modification anomalies.
How to recognize appropriateness or quality of the design of
relations.
How functional dependencies can be used to group attributes
into relations that are in a known normal form.
How to undertake process of normalization.
How to identify most commonly used normal forms, namely
1NF, 2NF, and 3NF
1/25/2024 2
Normalization
Normalization is defined as a technique for producing a set of
well designed relations that measure up to a set of requirements
which are outlined in various levels of normalization (or Normal
Forms).
Most commonly used normal forms are first (1NF), second (2NF)
and third (3NF) normal forms.
1/25/2024 3
Data Redundancy
Major aim of relational database design is to group attributes
into relations to minimize data redundancy and reduce file
storage space required by base relations.
1/25/2024 4
Data Redundancy
1/25/2024 5
Update Anomalies
Relations that contain redundant information may potentially
suffer from update anomalies.
1/25/2024 7
Update anomalies: Modification Anomaly
Modification Anomaly: Changing the value of one of the
columns in a table will mean changing all the values that have to
do with that column.
1/25/2024 8
Update anomalies: Deletion Anomaly
Deletion Anomaly: Occurs whenever deleting a row
inadvertently causes other data to be deleted.
Func
tiona
1/25/2024 l
2.11
Dep
ende
Example - Functional Dependency
1/25/2024 12
Example
2.13
Func
tiona
1/25/2024 l
Dep
ende
Example
1/25/2024 15
Unnormalized Form (UNF)
A table that contains one or more repeating groups.
✓ Note: A repeating group is an attribute or group of
attributes within a table that occurs with multiple
values for a single occurrence of the nominated key
attributes for that table. For example a book with
multiple authors, etc
1/25/2024 16
First normal form (1NF)
A table is in First Normal Form (1NF) if all its attributes are
atomic.
A domain is atomic if its elements are considered to be
indivisible units. A relation in which intersection of each row
and column contains one and only one value.
Implies that it should have no composite attributes or multi-
valued attributes.
In case a table is not in 1NF, we do two things
1/25/2024 17
UNF to 1NF
First identify a primary key, then
Either
Place each value of a repeating group on a tuple with duplicate
values of the non-repeating data (called “flattening” the table)
Or
Make a new table to cater for multi-valued attributes.
Nor
mali
zatio
n
UNF to 1NF
1/25/2024 20
UNF to 1NF
1/25/2024 21
HEALTH HISTORY REPORT
PROCEDURE
PET ID PET NAME PET TYPE PET AGE OWNER VISIT DATE PID PNAME
1/25/2024 25
1/25/2024 26
Third Normal Form (3NF)
Based on concept of transitive (indirect) dependency:
✓ A, B and C are attributes of a relation such that if A B
and B C,
✓ then C is transitively dependent on A through B. (Provided
that A is not functionally dependent on B or C).
Nor
mali
1/25/2024 zatio
n
2NF to 3NF
Identify the primary key in the 2NF relation.
Nor
mali
1/25/2024 zatio
n
``````3ea4EZQq `1 1
1/25/2024 29
1/25/2024 30
Exercises: Instructions
1/25/2024 31
Exercise 1
1/25/2024 32
Exercise 2
1/25/2024 33
Exercise 3
1/25/2024 34
Solution: Exercise 3
0NF
◼ ORDER(order#, customer#, name, address, orderdate(product#,
description, quantity, unitprice))
1NF
◼ ORDER(order#, customer#, name, address, orderdate)
◼ ORDER_LINE(order#, product#, description, quantity, unitprice)
2NF
◼ ORDER(order#, customer#, name, address, orderdate)
◼ ORDER_LINE(order#, product#, quantity)
◼ PRODUCT(product#, description, unitprice)
3NF
◼ ORDER(order#, customer#, orderdate)
◼ CUSTOMER(customer#, name, address)
◼ ORDER_LINE(order#, product#, quantity)
◼ PRODUCT(product#, description, unitprice)
1/25/2024 35
Logical DB Design
1/25/2024 2
MAPPING ENTITIES
Mapping strong entities: When mapping strong
entities, the entity becomes the table/relation and the
attributes become the fields.
1/25/2024 3
Mapping a Strong Entity into a Relation
Employee An Entity name: Employee
Emp_ID Attributes: Emp_ID, Emp_Lname,
Emp_Lname Emp_Fname, Salary
Emp_Fname
Salary
Primary Key: Emp_ID
Employee
EMPLOYEE CHILD
8
Name supports (First Name, Middle
(First Name, Last Name) Initial, Last Name)
Date Of Birth
10
Ship Date MSRP
11
(First Name, Last Name) Assignment Date
12
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
Multi-valued Attribute & Attributes with
Repeating Values
Create a new relation to represent the multi-valued attribute
and place a copy of the primary key of the owner entity into
the new relation (to act as a foreign key.
1/25/2024 17
Example of mapping an M:N
(Many-to-Many) relationship
a) Completes
relationship (M:N)
b) Three resulting
relations
18
Example of Mapping an m:m Relationship
Relational
schema
notation
Mapping Relationships: One-to-Many
When mapping one to many relationships, the primary key from
the one side migrates to the many side and becomes a foreign
key.
Place the primary key of the parent entity into the relation
schema representing the child entity (acting as a foreign key)
Place recursive foreign key in the same table (also true for
recursive One-to-One)
Employee ID
Name
(First Name, Last Name)
Date Of Birth
manages
Mapping Unary Relationships:
1:M Relationship
(b) Resulting Employee table with recursive foreign key
26
Mapping a Unary 1:M Relationship
(c) Example data for Employee table
PK FK
EmployeeID FirstName LastName DateOfBirth ManagerID
Materials” Name
Selling Price
relationship
consists of Quantity
30
(a) Ternary relationship as associative entity
PATIENT ADMINISTRATION PHYSICIAN
Mapping a TREATMENT
Relationship
(b) Four resulting tables
Patient PatientID FirstName LastName
Note composite PK of
associative relation
Physician PhysicianID FirstName LastName
(linking table)
Mandatory - And:
✓ Put all attributes of super class and sub class in the same
table.
Mandatory - Or:
✓ Create one table for each of the subclasses. No table for
the superclass 32
Mapping Generalized/Specialized Entities
Optional - And:
✓ Create one table for the superclass and one table for the
subclasses
Optional - Or:
✓ Create one table for each of the sub classes and one table
for the superclass
38
Redundancies
Redundancies may occur due to mapping because some tables
are represented many times, or they are not ‘normal’.
1/25/2024 39
Mapping Exercise
Task 1:
Identify any errors in the EERD and correct them
Task 2:
Derive the relations to be included in the Logical database
design; clearly indicating the primary key and the foreign
keys
DATABASE DEVELOPMENT: SQL
Introduction to SQL
DDL with tables
Example:
CREATE TABLE students
(regNo varchar(15), name varchar2(20), dob date, gender
char(1) default ‘M’);
Only the not null constraint and data types are passed onto the
new table.
Notes:
The not null constraint is added by modifying the column
that is to be defined as not null
Example:
ALTER TABLE students
MODIFY weight not null;
Example:
DROP TABLE students;
Write all SQL statements that will create the relational DB schema:
Data Constraints:
◼ A department name value must never be repeated.
◼ No person should earn a salary that is more than 5000.
Note:
◼ A foreign key is preceded by an asterisk (*);
◼ Mgr references EmpNo.
◼ Enforce another foreign key where necessary
1/25/2024 DDL with tables 2.23
DML with tables
Note:
◼ This statement will insert one row at a time.
◼ Enclose date and character values in single quotes.
◼ The list of values is by default in the order that of columns in the
relation.
◼ When using the explicit method; one must specify the NULL
keyword for the columns whose values you are not entering
Example: INSERT INTO departments
VALUES ( 30, ‘Purchasing’, NULL, NULL);
Clause
Statement
General syntax:
◼ SELECT clause
FROM table
WHERE condition;
Comparison operators are used to define conditions in the
where clause.
Basic SELECT Statements 4.16
Selection Cont’d
Note
i. Character strings and dates in the where clause
must be enclosed in single quotation marks (‘ ‘).
Numeric constants should not be enclosed in single
quotation marks.
ii. All character searches are case sensitive.
◼ Example:
DELETE FROM employees
WHERE empid = ‘c04’;