Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 66

Session 1

Foundations of Database Management System:


A Review

November 9, 2013
Course Outline
 Relational Data Model
 Relational Calculus
 Exercises
 Entity – relationship diagram
 3 easy step
 Transformation
 Exercise/Activity
 Assignment
 Machine Problem
Relational Data Model
 enables programmer to view logically rather than physically
Tables and Their Characteristics
 Table: two-dimensional structure composed of rows and
columns
 also known as relation
 Tuples/rows/records/instance
 Attributes/columns/field names
Tables and Their Characteristics (cont)
Keys
 Consists of one or more attributes that determine other
attributes
 Primary keys
 attribute (or a combination of attributes) that uniquely
identifies any given entity (row)
 entity integrity constraints
 Foreign key (FK)
 An attribute whose values match primary key values in the
related table
 referential integrity constraint
Integrity Rules
Relational Database Operators
 Relational algebra

 Defines theoretical way of manipulating table contents


using relational operators
 Use of relational algebra operators on existing tables
(relations) produces new relations
Relational Database Operators (cont)
 UNION
 INTERSECT
 DIFFERENCE
 PRODUCT
 SELECT
 PROJECT
 JOIN
 DIVIDE
Relational Database Operators (cont)
 Union:
 Combines all rows from two tables,
excluding duplicate rows
 Tables must have the same attribute
characteristics
 Intersect:
 Yields only the rows that appear in both
tables
Relational Database Operators (cont)
Relational Database Operators (cont)
Relational Database Operators (cont)
 Difference
 Yields all rows in one table not found in
the other table — that is, it subtracts one
table from the other
 Product
 Yields all possible pairs of rows from two
tables
 Also known as the Cartesian product
Relational Database Operators (cont)
Relational Database Operators (cont)
Relational Database Operators (cont)
 Select
 Yields values for all rows found in a table
 Can be used to list either all row values or it
can yield only those row values that match a
specified criterion
 Yields a horizontal subset of a table
 Project
 Yields all values for selected attributes
 Yields a vertical subset of a table
Relational Database Operators (cont)
Relational Database Operators (cont)
Relational Database Operators (cont)
 Join
Allows information to be combined
from two or more tables
Real power behind the relational
database, allowing the use of
independent tables linked by common
attributes
Relational Database Operators (cont)
Relational Database Operators (cont)
 Natural Join
 Links tables by selecting only rows with common
values in their common attribute(s)
 Result of a three-stage process:
 PRODUCT of the tables is created
 SELECT is performed on Step 1 output to yield only the
rows for which the AGENT_CODE values are equal
 Common column(s) are called join column(s)
 PROJECT is performed on Step 2 results to yield a single
copy of each attribute, thereby eliminating duplicate columns
Relational Database Operators (cont)
Relational Database Operators (cont)
Relational Database Operators (cont)
Relational Database Operators (cont)
 Natural Join:
 Final outcome yields table that
 Does not include unmatched pairs
 Provides only copies of matches
 If no match is made between the table
rows
 the new table does not include the unmatched
row
Relational Database Operators (cont)
 DIVIDE requires the use of one single-column table and one
two-column table
Relational Database Operators (cont)
Exercise 1
Exercise 2
Lunch break!
The Entity Relationship (ER) Model
 ER model forms the basis of an ER diagram
 ERD represents conceptual database as viewed by end user
 ERDs depict database’s main components:
 Entities
 Attributes
 Relationships

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Entities

 Refers to entity set and not to single entity occurrence


 Corresponds to table and not to row in relational
environment
 In both Chen and Crow’s Foot models, entity is represented
by rectangle containing entity’s name
 Entity name, a noun, is usually written in capital letters

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Attributes
 Characteristics of entities
 In Chen model, attributes are represented by ovals and are
connected to entity rectangle with a line
 Each oval contains the name of attribute it represents
 In Crow’s Foot model, attributes are written in attribute box
below entity rectangle

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Attributes (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
Domains
 Attributes have domain
 Domain is attribute’s set of possible values
 Attributes may share a domain

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Identifiers (Primary Keys)
 Underlined in the ERD
 Key attributes are also underlined in frequently used table
structure shorthand

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Composite Primary Keys
 Primary keys ideally composed of only single attribute
 Possible to use a composite key
 Primary key composed of more than one attribute

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Composite Primary Keys (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
Composite and Simple Attributes
 Composite attribute can be subdivided
 Simple attribute cannot be subdivided

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Single-Valued Attributes
 Single-value attribute can have only a single value

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Multivalued Attributes
 Multivalued attributes can have many values

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Multivalued Attributes (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
Derived Attributes
 Attribute whose value may be calculated (derived) from
other attributes
 Need not be physically stored within database
 Can be derived by using an algorithm

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Derived Attributes (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
Derived Attributes (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
Relationships
 Association between entities
 Participants are entities that participate in a relationship
 Relationships between entities always operate in both directions
 Relationship can be classified as 1:M
 Relationship classification is difficult to establish if know only one
side of the relationship

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Relationship Participation
 Optional participation
 One entity occurrence does not require corresponding entity
occurrence in particular relationship
 Mandatory participation
 One entity occurrence requires corresponding entity
occurrence in particular relationship

Database Systems: Design,


Implementation, & Management,
7th Edition, Rob & Coronel
Relationship Participation (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
Relationship Participation (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
Relationship Participation (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
Relationship Participation (continued)

Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
Exercise 1
Consider the following information about a university database:
 Each student has an id (sid), a name (sname), a major study
direction (major) and an age (age).
 Each course has a name (cname), a time at which the course
takes place (meets_at) and a room in which the course takes
place (room).
 Each faculty has an id (fid) and a name (fname).
 Students can be enrolled in several courses and for each course
there exists at least one student who is enrolled in that course.
 Each course belongs to one faculty and for each faculty exists at
least one course which belongs to this faculty.
Exercise 2
A company database needs to store information about employees
(identified by a social security number (ssn), with salary and phone as
attributes) and departments (identified by dno, with dname and budget
as attributes). Employees work in departments and each department
is managed by one employee.

Draw an ER diagram that captures this information. Be sure to


indicate any key and participation constraints.
Exercise 3
Each semester, each student must be assigned an adviser who counsels
students about degree requirements and helps students register for classes.
Students must register for classes with the help of an adviser, but if their
assigned adviser is not available, they may register with any adviser. We
must keep track of students, their assigned adviser, and with whom the
student registered for the current term.

Represent this situation of students and advisers with an E-R diagram.


Session 1 Activity 1a
 A patient can make many appointments with one or more doctors in a clinic, and a
doctor can accept appointments with many patients. However, each appointment is made
with only one doctor, and each appointment references a single patient.
 Emergency cases do not require appointment. However, an emergency is entered into
the appointment book as “unscheduled” for appointment management purposes.
 If kept, an appointment yields a visit with the doctor specified in the appointment. The
visit yields a diagnosis and when appropriate, treatment.
 Each visit updates the patient’s records to provide a medical history.
 Each patient visit is billed by a doctor and each doctor can bill many patients.
 Each bill may be paid in many installments, and a payment may cover more than one bill.
 A patient can pay the bill directly, or the bill may be the basis for a claim submitted to an
insurance company.
 If the bill is paid by an insurance company, the deductible is submitted to the patient for
payment.
ERD Transformation
One-to-One
One-to-One (cont)
One-to-Many
One-to-Many (cont)
Many-to-Many
Exercise 1
Exercise 2
Exercise 3
Session 1 Activity 1b
Thank you!

You might also like