CH 1
CH 1
MANAGEMENT SYSTEM
Prepared By
Ms.S.S.GITE
Unit I: Introduction to DBMS
• Definition of DBMS:
Collection of interrelated data and a set of programs
to access those data
• The primary goal of a DBMS is
to provide a way to store and retrieve database
information that is both convenient and efficient
Purpose of Database Systems
In the early days, database applications were built directly on top of file
systems, which leads to:
Data redundancy and inconsistency: data is stored in multiple file formats
resulting in duplication of information in different files
Difficulty in accessing data
Need to write a new program to carry out each new task
Data isolation
Multiple files and formats
Integrity problems
Integrity constraints (e.g., account balance > 0) become “buried” in
program code rather than being stated explicitly
Hard to add new constraints or change existing ones
Purpose of Database Systems
Atomicity of updates
Failures may leave database in an inconsistent state with partial updates carried
out
Example: Transfer of funds from one account to another
should either complete or not happen at all
Concurrent access by multiple users
Concurrent access needed for performance
Uncontrolled concurrent accesses can lead to inconsistencies
Ex: Two people reading a balance (say 100) and updating it
by withdrawing money (say 50 each) at the same time
Security problems
Hard to provide user access to some, but not all, data
Limited Data Sharing:
To share data we need to write complex program.
Data dependence:
If format of any file is change, we need to changes in programs which
process the file.
Poor Data control:
It does not have centralized data control. It is in distributed in various
folders. Same field may have different names in files of different
departments of an organization leads to different meaning of same
data field
Database-System Applications
Enterprise Information: Sales, Accounting, Human
Resource, Manufacturing, Online retailers
Banking and Finance: Banking, Credit card transactions,
Finance
Universities
Airlines
Telecommunication: For keeping records of calls made,
generating monthly bills, maintaining balances on prepaid
calling cards, and storing information about the
communication networks
View of Data
A database system is a collection of interrelated data and a set of
programs that allow users to access and modify these data.
A major purpose of a database system is to provide users with an
abstract view of the data.
Complex Data structures
Database level
Storage level
2. Logical Level
Deals with what and relationships.
Entire databases with simple data structures.
Physical Data Independence
Application programs hide details of data types. Views can also hide
information (such as an employee’s salary) for security purposes.
Users and Access.
Application Programs
• E-R Model
• Logical representation of data as objects and
relationship among them
• Collection of basic objects called entities and
its relationship
• An entity is a real world thing or object
• Widely use in database Design
Object-Based Data Model
• OOP Language, C++, Java etc.
• Need for Object oriented data model
• Object based model= E-R model + OO features
• Extension of ER-Model with notions of
functions, encapsulation and object identity
• Support system with structured and collection
types
Semistructured Data Model
• Specification of data
• Individuals data items of the same type may
have different set of attributes
• Contrast to Previous Data models
• Extensible Markup Language(XML)
• Consider web-based data sources as an example of a
semi-structured data model.
• Other examples of semi-structured data models
include emails, HTML, and web pages.
Other Data Models:
• Network data Model Hierarchical data Model
• Not widely used
• Complicated
Relational Model
• All the data is stored in various tables.
• Example of tabular data in the relational model Columns
Rows
A Sample Relational Database
Data Definition Language (DDL)
• Specification notation for defining the database schema
Example: create table instructor (
ID char(5),
name varchar(20),
dept_name varchar(20),
salary numeric(8,2))
35
Relational Model Terminology
⚫ Tuple is a row of a relation.
⚫ RelationalDatabase is a collection of
normalized relations with distinct relation
names.
36
Instances of Branch and Staff (part)
Relations
37
Examples of Attribute Domains
38
Relational Model: Structure of relational
databases
Example:
instructor = (ID, name, dept_name, salary)
A relation instance r defined over schema R is
denoted by r (R).
The current values a relation are specified by a table
An element t of relation r is called a tuple and is
represented by a row in a table
Relational Model: Attributes and Domains
41
Properties of Relations
• Relation name is distinct from all other relation names in
relational schema.
42
Properties of Relations
• Each tuple is distinct; there are no duplicate
tuples.
43
Relational Algebra
• Relational algebra is a formal language
associated with the relational model.
• Informally, relational algebra is a (high-level)
procedural query language
• How to form queries in relational algebra.
• It performs set of operations on relations.
• Set of algebraic operations.
• Structured Query Language.
44
Relational Model: Relational Algebra
Logi Phon
n e
Vino 9843744345
Types of
Keys:
•Primary Key.
•Super Key.
•Candidate Key.
•Foreign Key.
•Alternate Key.
Primary Key:
⚫A primary key is a field that
uniquely identified each
record in a table.
⚫It contain can’t null values
and duplicate values.
Super Key:
⚫ A super key is a set of one or more attributes
that allows identifying uniquely an entity in
the entity set.
Candidate Key:
⚫ A candidate key can be any column or a
combination of columns that can qualify as
unique key in database.
⚫ There can be multiple candidate key in one
table.
Foreign Key:
⚫ An attributes or set of attributes
within one relation that matches the
candidate key of some relation.
Selection (or Restriction)
• predicate (Relation)
• Select row from relation that satisfy given
condition(predicate)
– Comparison operators: =, ≠,>,<,≥,and ≤
– Connectives: AND(^), OR(v), and NOT(¬)
49
Example - Selection (or Restriction)
• List all staff with a salary greater than
£10,000.
51
1. Select()
Example 1: Write an RA expression
to find all instructors working INSTRUCTOR
in Mechanical Department. ID Name Dept_Name Salary
10101 Ravi Electrical 65000
55
Example - Projection
• Produce a list of salaries for all staff, showing
only staffNo, fName, lName, and salary
details.
56
Relational Model: Relational Algebra &
Queries
Relational Model: Relational Algebra &
Queries
Union Operation (Same for Intersection and Difference)
The union operation allows us to combine two relations
Notation: r s
For r s to be valid.
1. r, s must have the same arity (same number of
attributes)
2. The attribute domains must be compatible (example: 2nd
column of r deals with the same type of values as does the
2nd column of s)
Example: to find all courses taught in the Fall 2017 semester, or in the Spring
2018 semester, or in both
instructor X teaches
We construct a tuple of the result out of each possible pair of tuples: one from
the instructor relation and one from the teaches relation (see next slide)
Since the instructor ID appears in both relations we distinguish between these
attribute by attaching to the attribute the name of the relation from which the
attribute originally came.
instructor.ID
teaches.ID
Oooo0-gv bh-23
Extended operators in relational Algebra
• Derived from basic operators.
• Types
Intersection(∩)
Inner Join
1. Natural join
2. Theta join
3. Equijoin
Outer join
Left outer Join
Right Outer Join
Full outer Join
Division
1.Intersection:
• Relation1 ∩ Relation2
• Binary Operator
• Produces new relation with rows that appear
in both relations.
• For this the degree must be same of both
relations and corresponding attributes in two
relation have same domain.
Example- STUDENT∩ EMPLOYEE
city(Branch) city(PropertyForRent)
86
Set Difference
• R–S
– Defines a relation consisting of the tuples that are
in relation R, but not in S.
– R and S must be union-compatible.
87
Example - Set Difference
• List all cities where there is a branch office but
no properties for rent.
city(Branch) – city(PropertyForRent)
88
Intersection
• RS
– Defines a relation consisting of the set of all
tuples that are in both R and S.
– R and S must be union-compatible.
89
Example - Intersection
• List all cities where there is both a branch
office and at least one property for rent.
city(Branch) city(PropertyForRent)
90
Cartesian product
• RXS
– Defines a relation that is the concatenation of
every tuple of relation R with every tuple of
relation S.
91
Example - Cartesian product
• List the names and comments of all clients who have viewed a
property for rent.
(clientNo, fName, (Client)) X (clientNo,
lName propertyNo, comment
(Viewing))
92
Example - Cartesian product and
Selection
• Use selection operation to extract those tuples where
Client.clientNo = Viewing.clientNo.
Client.clientNo = Viewing.clientNo((clientNo, fName, lName(Client)) (clientNo,
propertyNo, comment(Viewing)))
93
Join Operations
• Join is a derivative of Cartesian product.
94
Join Operations
• Various forms of join operation
– Theta join
– Equijoin (a particular type of Theta join)
– Natural join
– Outer join
– Semijoin
95
Example - Equijoin
• List the names and comments of all clients
who have viewed a property for rent.
(clientNo, fName, lName(Client)) Client.clientNo = Viewing.clientNo
(clientNo, propertyNo, comment(Viewing))
96
Natural join
• R S
– An Equijoin of the two relations R and S over all
common attributes x. One occurrence of each
common attribute is eliminated from the result.
97
Example - Natural join
• List the names and comments of all clients
who have viewed a property for rent.
(clientNo, fName, lName(Client))
(clientNo, propertyNo, comment(Viewing))
98
Relationship Model
⚫ There are two entities, both of them are of the
person type.
⚫ There is a relationship called married between
the two
person.
⚫ In this relationship each of these two person
entity has a role.
⚫ One person play the role of husband and another
person plays the role of wife.
Person Person
Entit Entit
y y
Husband(rol Wife(rol
e) e)
Relationsh
ip
Mathematical Relationship on Entity Set
Degree of Relationship:
•Unary Relationship.
•Binary Relationship.
Ternary Relationship.
•Quaternary Relationship.
Unary Relationship:
⚫ If a relationship type is between entity type
it is called an unary relationship type.
Manager
Manage by
Employees
Binary Relationship:
⚫ A binary relationship exist when two
entities are associated in a relationship .
⚫ Binary relationship are most common
conceptual design, possible most higher
order relationship.
Teach
Lecture es Class
Ternary
Relationship:
⚫ A ternary relationship implies an
association among three different entities.
⚫ A doctor writes one or more prescription.
⚫ A patient may receive one or more
prescription.
⚫ A drug may appear in one or more
prescription.
Write s e
prescriptio
Doctor receive n. Patie
nt
Appears
In
Drug
Quaternary
Relationship:
⚫ A quaternary relationship exit there are
four entity associated.
Teacher
Subject
Cardinality Constraints/Ratio
Types of Participation
Constraints:
⚫Total Participation
Constraints
⚫Partial Participation
Constraints
Entity Relationship diagram
⚫ The basic ER diagram was conceived by
Peter Chen 1976 as a unifying data model
for all data models that existed at that time.
⚫ ER diagram or data schema map or data
map is another means of capturing the data
and their organization.
Importance of ERD:
⚫ Straight forward relationship
representation.
⚫ Easy conversion of ER to other data model.
⚫ Graphical representation for better
understanding.
ER Symbol
Enhanced ER Modeling
• Specialization
• Generalization
• Attribute Inheritance
• Constraints on Generalization
• Aggregation
Specialization
Top-down design process;
we designate sub-groupings within an entity set that are distinctive from other entities in the
set.
These sub-groupings become lower-level entity sets that have attributes or participate in
relationships that do not apply to the higher-level entity set.
Depicted by a triangle component labeled ISA (e.g., instructor “is a” person).
Specialization is the process of one or more sub type of the super type and forming
relationship.
Attribute inheritance – a lower-level entity set inherits all the attributes and relationship
participation of the higher-level entity set to which it is linked.
e.g., Person entity set can be divided into customer, student, employee. Person is superclass
and other specialized entity sets are subclasses.
1. We have “is-a” relationship between superclass and subclass.
2. Depicted by triangle component.
Specialization and Generalization
Generalisation
:
⚫ In data modeling generalisation is the process of
defining a more general entity type from a set of
more specialised entity types.
⚫ This is an generalisation is a bottom up 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.
Attribute Inheritance:
⚫ Condition-Defined
⚫ User-Defined
⚫ Disjoint
⚫ Overlapping
Aggregation:
• One limitation of E-R model is that it cannot
Express relationships among relationships.
Student_Id Hobby
Course_Id Course_Name