Escolar Documentos
Profissional Documentos
Cultura Documentos
RDBMS Concepts
Slide 2
Data important to us must be stored so that we can retrieve it when we need it.
Slide 3
Limitation of file
No mechanism to ensure non-redundant data.
No mechanism to ensure data consistency.
Slide 4
Slide 5
Activity
data?
Is there anyway you could make lookup more easier?
What have you done to make the data more approachable?
It is not just about storing information. It is about how to retrieve information effectively
and efficiently. So the way we store the information is directly related to way we retrieve
it.
The key to this is the way we choose to organize the information.
Slide 6
Relational Database
Relational databases store information in tabular form- in rows and
columns.
Each column has data of same type and the row has data pertaining to
one cause.
A table has many rows of similar type.
The table is also referred to as a relation.
Database is a collection of meaningful and related data.
Relational database model was introduced by E. F. Codd, of IBM's San Jose Research
Laboratory.
For a given DBMS, depending on the structural description of the type of data the
database stores (which is called Schema) the model is defined.
There are 4 models:
Hierarchical Model
Data is organized into tree-like structure.
Used by the older mainframe database systems like IMS by IBM.
Parent-child relationship between the data. 1:N mapping.
2. Network Model
Network model is very much like hierarchical model with the exception that it allows a
record to have more than one parent
N:M mapping (many to many relationship)
3. Relational Model
Most database system use this model.
The schema for relational model is a table (relation) which has a name, attributes or
column or field and a type for each field.
Relationship is maintained by the common attributes in the tables. Can be one-one or
one to many or many to many.
This is what we will be learning in this session.
4. Object Model
The new wave of database technologies use Object-oriented data model (OODM).
Slide 7
Relationships
With RDBMS, all types of relationships between entities can be be
realized.
Types of relationship
Slide 8
Name
Raghu R
Mary Molle
Henry F.Korth
Jennifer Wisdom
Uma R
Tuples, records or rows
8
Slide 9
RDBMS Products
Oracle
Sybase
IBM DB2
MS-SQL Server
MySQL
MS Access
Ingres
PostgreSQL
Slide 10
Multi-user Database
Type of location
Centralized database
Distributed database
Distributed database
Transactional or Production DBMS
Data warehousing and decision support system
10
Slide 11
11
install and manage, and is free to develop, deploy, and distribute. Oracle Database XE
makes it easy to upgrade to the other editions of Oracle without costly and complex
migrations. Oracle Database XE can be installed on any size machine with any number
of CPUs, stores up to 4GB of user data, using up to 1GB of memory, and using only one
CPU on the host machine. Support is provided by an online forum.
Oracle Database Personal Edition : Oracle Database Personal Edition supports singleuser development and deployment environments that require full compatibility with
Oracle Database Standard Edition One, Oracle Database Standard Edition, and Oracle
Database Enterprise Edition.
Slide 12
Network
12
Client takes the request from the end user, sends the request to the server, gets the
data from the server and presents in the form that end user wants to see.
Slide 13
13
Slide 14
ER Model
ER data model allows us to conceptually understand the data of the real
world that we intent to store them.
Slide 15
Defining Entity
15
Slide 16
Primary Key
A minimal set of attributes that uniquely identifies an entity is called a
candidate key.
An entity can have many candidate keys. For example, for a student
entity, if we assume that students have unique names. In that case both
registration number and name are candidate keys.
16
Slide 17
Activity
17
Slide 18
Notations in ER diagram
Entity Set
Attribute
Relationship
18
Slide 19
regNo
Students
Primary key
Attributes
name
address
Entity Set
streamId
Courses
title
noOfSems
19
Slide 20
Activity
20
Slide 21
Relationship
Relationship is the association between entities or entity sets. For
example between two entities student and course, the relationship is
Binary
Ternary
Unary
21
Slide 22
Mapping/Connectivity
teacherId
title
1
Subject
Is Taught
subId
Teacher
address
Relationship Set
22
name
Slide 23
regNo
noOfSems
1
Courses
streamId
Students
Have
title
address
Relationship Set
23
name
Slide 24
Mapping/Connectivity
acctNo
address
M
Customer
custId
Bank Account
owns
name
balance
24
acctType
Slide 25
regNo
noOfSems
1
Courses
streamId
Students
Have
title
address
enrollment-date
Attribute of relationship
25
name
Slide 26
Activity
26
Slide 27
Cardinality
regNo
noOfSems
Courses
Has
(1,6)
streamId
Students
(1,35)
title
address
enrollment-date
27
name
Slide 28
deptId
empId
Employees
M
Works-In
Departments
name
name
P
Location
address
locId
capacity
28
Slide 29
address
custId
Customer
N
name
referred
by
29
Slide 30
streamId
1
Courses
regNo
Directional arrow
N
Students
Has
title
enrollment-date
30
name
Slide 31
Activity
31
Slide 32
Participation constraints
Total participation: If all entities in an entity-set need to be in the
relationship set then the entity is in total participation with respect to
relationship.
Example: Every employee works in at least one department. Each
department has at least one employee. Therefore both Employee and
32
Slide 33
deptId
empId
Employees
name
Works-In
Departments
name
or
location
locId
Indicates total
participation
capacity
address
33
Slide 34
Modeling Attributes
Single valued attributes the examples that we have seen so far
consisted of single value attributes.
Composite Attribute
Multi-Valued Attribute
Derived Attribute
34
Slide 35
Composite Attribute
A composite attribute is an attributes that is made up of more than
one attribute.
composite attribute
street number
house number
area
pin
country
Employees
address
district
state
35
Slide 36
Multi-Valued Attribute
A multi-value attribute is an attribute which can have multiple
values.
multi-valued attribute
phone_numbers
36
Employees
Slide 37
Derived Attribute
A derived attribute is an attribute whose value is determined or computed
using existing values of the other attributes (or otherwise also called
stored attribute).
gross_salary
Employee
deductions
37
derived stored
attribute
net_salary
Slide 38
Weak Entities
A weak entity is an entity that cant be uniquely identified by its own
attributes alone, and therefore must use as its primary key both its
many.
38
Slide 39
partial key
custId
Orders
orderNo
itemNo
1
contains
Order-Items
or
orderDate
noOfPieces
or
Order-Items
Identifying
relationship
contains
39
Slide 40
Hierarchy
The entities can be classified as general type and specific type.
IS-A relationship.
For example, an Employee can be a programmer or a manager.
name
empId
generalization
Current-Project
IS-A
Programmer
area
Marketing Manager
Main-Role
num-of-contracts
40
specialization
Employee
Slide 41
empId
joiningDate
name
Employee
works
Project
machineID
Computer
uses
hours
purchaseDate
redundant relationships
41
Slide 42
Aggregation
Solution is to use aggregation. Aggregation is a relationship between
collection of entities and relationships.
Aggregation allows us to indicate that a relationship set participates
42
Slide 43
empId
joiningDate
name
Employee
works
Project
aggregation
hours
uses
Machinery
machineID
purchaseDate
43
Slide 44
Exercises
1. Draw an E-R diagram for the following application.
student can enroll for any number of courses. The date of enrollment of
the course is also maintained.
d. A course is described by its course-id, title and duration, course-id
f. There is no student who has not taken any course. There are however
courses for which there are no students.
44
(30 mins)
Slide 45
are paid in per day basis. Permanent employees are paid every month
and they have permanent id.
d. Department is identified by deptId, name.
(30 mins)
45
Slide 46
route.
f. Some of the towns have a garage where busses are kept and each of the
busses are identified by the registration number and can carry different
numbers of passengers, since the vehicles vary in size and can be single or
double-decked.
g. Each route is identified by a route number and information is available on
the average number of passengers carried per day for each route.
46
Slide 47
47
Slide 48
Activity
What are the problems if the data is repeated?
Roll Number
Name
Degree
20103001
V. Ravichandra
M.C.A
20103002
Usha Kritilal
M.C.A
20103003
Samkit Verma
M.C.A
20103001
V. Ravichandra
M.C.A
20103004
Guru Murthy
M.C.A
20103007
Jaya R
M.C.A
20105009
Vivek Sahoo
B. Tech
20105007
Booby Sharma
B.Tech
20103004
Guru Murthy
M.C.A
48
Slide 49
Redundant Storage
Update Anomalies
Insertion Anomalies
Deletion Anomalies
49
Slide 50
Definition
First proposed by Dr. Codd.
Normalization is the process of breaking down a relation schema
50
Take care :
While normalizing we also pay attention to two important aspects:
Lossless Join: There should be no loss of information when tables are split.
Dependency Preservation: The dependency between the attributes must be preserved.
Slide 51
1 NF
First Normal Form
There are no duplicated rows in the table.
51
Slide 52
Un-normalized data
Stud
Id
Stud
Name
Course
No
Course
Name
Staff
ID
Staff
Name
PaperNo
Subject
Name
Grade
Sita
JEE
Preeti
Java
JEE
Web
.NET
C#
Jay
Mani
Kim
Ram
Guru
SAP
Ravi
ASP.NET
ABAP
B
A
52
Slide 53
Into 1NF
Stud
Id
Stud
Name
Course
No
Course
Name
Staff ID
Staff
Name
PaperNo
Subject
Name
Grade
Sita
JEE
Preeti
Java
Sita
JEE
Preeti
Web
Jay
.NET
Guru
C#
Mani
.NET
Guru
C#
Mani
.NET
Guru
ASP.NET
Kim
SAP
Ravi
ABAP
Ram
SAP
Ravi
ABAP
Slide 54
2 NF
Second Normal Form:
54
Slide 55
determined.
dependent A.
55
Slide 56
Into 2 NF
Student
Stud
Id
Stud
Name
Course
No
Course
Name
Paper
No
Subject
Name
Grade
Sita
JEE
Java
Sita
JEE
Web
Jay
.NET
C#
Mani
.NET
C#
Mani
.NET
ASP.NET
Kim
SAP
ABAP
Ram
SAP
ABAP
56
Slide 57
Course
Course
No
Course
Name
Staff
ID
Staff
Name
PaperNo
Subject
Name
JEE
Preeti
Java
JEE
Preeti
Web
.NET
Guru
C#
.NET
Guru
ASP.NET
SAP
Ravi
ABAP
57
Slide 58
3 NF
Third Normal Form
A table is in 3NF if it is in 2NF and if it has no transitive
dependencies of a non-key attribute on the primary key.
58
Slide 59
Into 3NF
Transitive dependency:
Student table
StudID Course No
Course table
CourseID StaffID
StaffIDStaffName
59
No
Slide 60
Stud
Id
Stud
Name
Course
No
Paper
No
Grade
Course
No
Paper
No
Subject
Name
Sita
Java
Sita
Web
Jay
C#
Mani
ASP.NET
Kim
ABAP
Ram
60
Course
No
Course
Name
JEE
.NET
.NET
SAP
Slide 61
Course
No
Course
Name
Staff
ID
PaperNo
Subject
Name
JEE
Java
JEE
Web
.NET
C#
.NET
ASP.NET
SAP
ABAP
61
Staff
ID
Staff
Name
Preeti
Guru
Ravi
Slide 62
BCNF comes into picture only where there are two candidate keys.
62
Slide 63
Activity
Tom has to compute the result based on the Grade. (A and B are
Pass, C is fail)
Stud
Id
Stud
Name
Course
No
Paper
No
Grade
Sita
Sita
Jay
Mani
Kim
Ram
Result is null,
So update Grade to C
TOM: Update the Result to Pass
Result
Can you identify the problem here? How do you propose to make sure that problem
does not occur again?
63
Slide 64
Activity
Alice and Akshay have a joint account in ABC Bank. The account
has Rs.5000. Alice is in London visiting her parents and Akshay is at
work. Both are in need for some money and they withdraw 3000
rupees simultaneously.
Do you foresee any problems that could happen if bank has not
dealt with this situation?
64
Slide 65
Dirty read
Transaction A tries to read the data it has already read and now finds
that the data in the row(s) is/are changed or deleted by another
transaction B.
Phantom records
Transaction A executes the same query twice to find that the both the
queries return different result set.
65
Slide 66
Transaction Processing
Logical unit of program execution that takes a database from one
consistent state to another consistent state.
66
Concurrency techniques:
Locking
Time stamping
Slide 67
ACID properties
Atomicity
Either all the sql statements that is part of the transaction, are
committed or none
Consistency
The result of the transaction must be visible only after the transaction
has been committed.
67
Atomicity
Example: if a transaction starts updating salaries for all the 1000 employees and
database crashes after 999th record, then the database rolls back the all the changes to
1000 records.
Consistency
Example, transfer of money from one account to another account must not stop with
debiting the amount in one account and not crediting in another.
Isolation
In the 1st example, imagine what would happen if the an employee sees his salary has
increased and his colleague does not see it being reflected.
Slide 68
Durability
Changes made by the committed transactions which are
temporarily held in the current in-memory database image are
68
Slide 69
Exercises
1. Normalize the given table to 2NF and 3NF.
Happy Home Super market deals with groceries, household items,
15 mins
69
Slide 70
2. Normalize the given table ensuring no data loss and data redundancy.
15 mins
70
Slide 71
Every LOB has a unique ID, Name and multiple locations(address) from
where they operate.
Design an appropriate set of Normalized Relations to represent this
information
71