Transcript Module 2

Database Management
System
Module 2
Class Hierarchy


This classify entities into subclasses.
Two types



Specialization-Process of specifying
subclasses of an entity set (superclass)
sharing some characteristics. Superclass is
defined first followed by subclasses.
Generalization – Opposite of
specialisation. Define first subclasses
Identified by the word ISA. (ISA -
Relationship)
Class Hierarchy: Example
Aggregation


Allows us to indicate that a relationship
set participate in another relationship.
E.g. Projects is sponsored by one or
more department. Employee in the dept
assigned to monitor sponsorship. Hence
monitor is relationship set associates
sponsor relationship set
Aggregation
name
ssn
age
Employees
Monitors
Until
since
Started_on
pid
dname
pbudget
Projects
did
Sponsors
budget
Department
Conceptual Design For Large
Enterprise


For a large enterprise the design
requires the collaboration amongst
several designer, and span data and
application code used by a number of
user group.
Important thing is to ensure that it
takes on board all user requirements.
Relation Database Structure


The overall concepts of developing E-R
model is to enable designer to create
the relational database model.
In a relation model, a database consists
of one or more relations, where each
relation is a table with rows and
columns.
Relational Model




The essence is to simplify an
understanding of contents of the
database toward users.
And also it permits the use of simple,
high-level languages to query the data.
Complex queries can be performed.
It underpins the logical database
design
Relational Model: Key issues






Data representation.
Expression of integrity constraints.
Data creation and modification.
Querying and manipulating data.
Database design in the relational model
Achieving logical and physical data
independence.
Relation Model: Data
representation

The main construct of representing a
data in the relational model is a
relation.


A relation consists of a relation schema
and relation instance.
The relation instance is a table at a
particular moment.
Relation Model


The relation schema describes the
column heads of the table.
The schema specifies the relation’s
name, the name of each field (or
column, or attribute), and the
domain of each field.
Domain


A domain is referred to in a relation
schema by the domain name and its
associated values.
Example of a relation schema:
Students (sid: string, login: string, age: integer,
gpa: real)
 i.e. the field named sid has a domain name
string. The set of values associated with
domain string is the set of all character
strings.
Relation Instance


An instance of a relation is a set of
tuples or records in which each tuple
has the same number of the fields as
the relation schema.
Or is a table in which each tuple is a
row and all rows have the same number
of fields.
Key constraints


Example of general constraints is that
no two students should the same
student id (Sometimes called IC
(Integrity Constraint))
Key constraint is a statement that
certain minimal subset of the fields of a
relation is a unique identifier for a tuple.
Key constraints


A candidate key for the relation is a set
of fields that uniquely identifies a tuple
according to a key constraints.
Two types of keys


Primary key constraints - values which
uniquely identify each of the rows in a
table.
Foreign key constraints – enforce
referential integrity of database.
Example Primary Key
Definition using DDL
CREATE TABLE Students (
sid CHAR(20),
name CHAR(30),
login CHAR (20),
age INTEGER,
UNIQUE (name, age),
CONSTRAINT StudentKey PRIMARY KEY (sid)
)

Key constraints


The primary keys ensure that no
duplicate rows are allowed in a relation.
Foreign key ensures that when one of
the two or more relations is modified
the data in other relations remain
consistent.
Key constraints
Consider you have another relation
identified by the following schema:
Enrolled (sid: string, cid: string, grade:
string)
 The sid field of Enrolled relation is
called a foreign key

Illustration of Foreign Key
Constraints

In this every sid value that appears in the instance of
the Enrolled table appears in the primary key column
of Student table
Mapping Entity Sets to Table


An entity set can be mapped to a
relation in a straightforward way.
E.g. A possible instance of the
employees entity set is
name
ssn
Employee
age
Mapping Entity Sets to Table
csn
name
age
123-22-3666
Attishoo
53831
123-22-3368
Smiley
53832
123-22-3650
Smith
53833
Class Activity (15 mins)

Using your working experience,




Extract two entities that will be constituting
your database system.
Develop E-R model incorporating some
relationship.
Develop a conceptual design fom your
model. (Relational Model)
Extract individual relation with its
appropriate attributes.
Relational Algebra
Relational Algebra



Is the one the two formal queries
language associated with the relational
model.
Queries in algebra are made up of
collection of operators
A fundamental property is that every
operator in the algebra accepts (one or
two) relation instances as argument and
returns relation instance as the results.
Relational Algebra



This property makes it easy to compose
operators to form a complex query .
Each relational query describes a step-bystep procedure for computing desired
answer based on the order in which
operators are applied in the query.
Relational algebra act as plan for
evaluating a query due to its procedural
in nature.
Relational Algebra


The inputs and outputs of queries are
relations.
A query is evaluated by using instances
of each input relation and it produces
an instances of the output relation.
Selection and Projection


Relational algebra includes operators to
select rows from a relation (δ) and to
project columns ().
Consider the instance of the accounting
relation in th figure below
Selection and Projection

By projection we can retrieve rows
corresponding to customer account by using
operator  as follows
balance  250000 ( Account)
Selection and Projection

The selection operator sigma specifies the
tuples to retain through a selection
condition.

In general, the selection is boolean
combination (i.e, an expression using the
logical connectives Λ and V) of attributes and
comparison operators (<,=,>,≠,≤,≥,<=,=>)
Selection and Projection

The projection operator pi allows us to
extract columns from relation; for example,

we can find out all accounting type and
balance by using the following statement:
acc _ type, balance( Account)

The expression above evaluates to the
relation shown below
Selection and Projection

The subscript Acc_Type, balance specifies the field
to be retained and other fields are projected
out


Since the result of a relational algebra is
always a expression, we can substitute
expression wherever a relation is expected
Example we can compute account type
and balance by combining two of the
proceeding queries as follows:
Acc _ Type , balance(balance  250000 ( Account))
Exercise


Write down an expression will evaluate
the student name in the student
database.
Review Set Operations




Union
Intersection
Set-difference
Cross-product