Académique Documents
Professionnel Documents
Culture Documents
0 Page 2
Introduction to
Database Management Systems
(DBMS)
Database Management
System (DBMS)
Definitions:
● Data Definition
● Data Manipulation
● Data Security and Integrity
● Data Recovery and Concurrency
● Data Dictionary
● Performance
Compiled query
Q2 Database
Database manager description
File manager
Physical
database
External level
(individual user
views)
Conceptual level
(community user view)
Internal level
(storage view)
Database
HIERARCHICAL
NETWORK
COLUMN
TABLE
ROW VALUE
RELATIONAL
LOGICAL DESIGN
Tables - Columns - Primary Keys - Foreign Keys
PHYSICAL DESIGN
DDL for Tablespaces, Tables, Indexes
● Relation : a table
● Tuple : a row in a table
● Attribute : a Column in a table
● Degree : number of attributes
● Cardinality : number of tuples
● Primary Key : a unique identifier for the table
● Domain : a pool of values from which specific
attributes of specific relations draw their values
● Key
● Super Key
● Candidate Keys
Primary Key
Alternate Key
● Secondary Keys
Enrolled Student
Primary key
Foreign key referring to
sid of STUDENT relation
R1 22 101 10/10/99
58 103 11/12/99
● Basic operations:
Selection (σ )
Projection (π)
Cross- product ( Χ)
Set- difference ( –)
Union (∪ )
sname rating
Yamuna 9 π sname, rating(S2)
Laxmi 8
Geeta 5
Roopa 10
age
35.0
55.5 π age(S2)
sname rating
Yamuna 9
Roopa 10 π sname, rating(S2) (σ rating > 8(S2))
Condition Join :
QUERY OPTIMIZER
Typical steps
Execution plan when processing
a high level
QUERY CODE GENERATOR
query.
Code to execute the query
Result of query
select *
from R1, R2, R3
where R1.r2no=R2.r2no NLJ
and R2.r3no=R3.r3no
and R1.a=5000
NLJ SS(R1, “a=5000”)
SS(R2) SS(R3)
select *
from R1, R2, R3
where R1.r2no=R2.r2no NLJ
and R2.r3no=R3.r3no
and R1.a=5000
NLJ SS(R3)
select *
from R1, R2, R3
where R1.r2no=R2.r2no NLJ
and R2.r3no=R3.r3no
and R1.a=5000
NLJ SS(R3)
Relational Calculus
Physical Design
Internal Storage Structures / Access Path / File Organizations
Talent Transformation Basic RDBMS ver 2.0 Page 47
E-R Modeling
● Entity
is anything that exists and is distinguishable
● Entity Set
a group of similar entities
● Attribute
properties that describe an entity
● Relationship
an association between entities
RELATIONSHIP TYPE
Attributes
SSN NAME LOT
ssn name lot
123- 22- 3666 Attishoo 48
231- 31- 5368 Smiley 22
Employee 131- 24- 3650 Smethurst 35
Entity Set
CREATE TABLE Employees
(ssn CHAR (11),
name CHAR (20),
lot INTEGER,
PRIMARY KEY (ssn))
Talent Transformation Basic RDBMS ver 2.0 Page 50
Types of Relationships
1 1
1:1 student Is issued ID card
Reports_To
Employee Department
Manages
Location
capacity
address
Works_in
since
Employee Dependent
policy
Employee
Hrly_wages
Hrs_worked IsA
contractid
Hourly_Emp Contract_Emp
Employee
monitors until
Employee Department
Works_in
Employee Department
Works_in
from Duration to
Employee Department
manages
DB - Dbudget
Employee Department
manages
since
Employee Dependent
covers
Policy
policyid cost
Talent Transformation Basic RDBMS ver 2.0 Page 64
Binary vs. Ternary Relationships
Better Design
ssn name lot pname
age
Employee Dependent
purchaser Beneficiary
Policy
policyid cost
• Functional dependencies
• Inclusion dependencies
• General constraints
DEPARTMENT
1
SUPPLIER
DEPT_
M
EMP
PROJ_ M
M M
M WORK M SUPP_
EMPLOYEE PROJECT PART_
M PROJ
1 1 PROJ_ SUPP_
MGR M PART
EMP_
DEP PART M
M M M
DEPENDENT
PART_
STRUC
TURE
● Company :
Organized into Departments, Each
Department has a name, no and manager
who manages the department. The
Company keeps track of the date that
employee managing the department. A
Department may have a Several locations.
● Department :
A Department controls a number of Projects each
of which has a unique name , no and a single
Location.
● Employee :
Name, Age, Gender, BirthDate, SSN, Address,
Salary. An Employee is assigned to one
department, may work on several projects which
are not controlled by the department. Track of
the number of hours per week is also controlled.
DEPARTMENT
( Name , Number , { Locations } , Manager, Start Date )
PROJECT
( Name, Number, Location , Controlling Department )
EMPLOYEE
(Name (Fname, Lname) , SSN , Gender, Address, Salary
Birthdate, Department , Supervisor , (Workson ( Project , Hrs))
DEPENDENT
( Employee, Name, Gender, Birthdate , Relationship )
● Manage:
Department and Employee
Partial Participation
Relation Attribute : StartDate.
● Works For:
Department and Employee
Total Participation
● Control :
Department , Project
Partial Participation from Department
Total Participation from Project
Control Department is a RKA.
● Supervisor :
Employee, Employee
Partial and Recursive
● Works – On :
Project , Employee
Total Participation
Hours Worked is a RKA.
● Dependants of:
Employee , Dependant
Dependant is a Weaker
Dependant is Total , Employee is Partial.
Bdate manage
s
Hours
Project
Work
Supe sOn
rvise
s Name No Loc
Depend On
Dependent Relationship
S N L H R
123- 22- 3666 Attishoo 48 40 8
8 R W
231- 31- 5368 Smiley 22 30
5 5 7
131- 24- 3650 Smethurst 35 30
8 10
434- 26- 3751 Guldu 35 32 5
612- 67- 4134 Madayan 35 40 8
Talent Transformation Basic RDBMS ver 2.0 Page 91
Second Normal Form (2NF)
● An FD X → Y in a relation schema R is a
transitive dependency if
there is a set of attributes Z that is not a
subset of any key of R, and
both X → Z and Z → Y hold.
T2 Add 2 (8) 6
(6) 3
T1 6
Add 2 (6+2=8) 3
T2 Write 1st Value 8
(8) 3
State D1 State D2
T
D1, D2 - Logically consistent states of the database data
T- Transaction for changing the database
t1, t2 - Absolute time before and after the transaction
ROLLBACK
READ , WRITE ROLLBACK
aborted terminated
When a system failure occurs, search the log file for entries
[start, <transaction-id>]
and if there are no logged entries [commit, <transaction-id>]
then undo all operations that have logged entries
[write, <transaction-id>, X, old_value, new_value]
T1 T2
R(A)
W(A)
R(B)
W(B)
R(C)
W(C)
Talent Transformation Basic RDBMS ver 2.0 Page 123
Serializable Schedule
T1 T2
R(A)
W(A)
R(A)
W(A)
abort
T1 T2 T1 T2
R(A) R(A)
W(A) W(A)
R(A) R(A)
W(A) W(A)
commit commit
abort commit
concurrency
fine granularity
◆ the smaller the data item size, the more locks to be
Strict 2PL:
– If T wants to read an object, first obtains an S lock.
– If T wants to modify an object, first obtains X lock.
– Hold all locks until end of transaction.
– Guarantees serializability, and recoverable schedule, too!
also avoids WW problems!
2PL:
– Slight variant of strict 2PL
– transactions can release locks before the end (commit or
abort)
But after releasing any lock it can acquire no new locks
– Guarantees serializability
Talent Transformation Basic RDBMS ver 2.0 Page 131
Handling a Lock Request
Mode==X Mode==S
Yes No Yes
Currently X-locked?
No Yes
Put on Queue
No
Grant Lock
Talent Transformation Basic RDBMS ver 2.0 Page 132
Talent Transformation Basic RDBMS ver 2.0 Page 133
Recovery
NoSteal Steal
Force Trivial
NoForce Desired
Talent Transformation Basic RDBMS ver 2.0 Page 138
Write- Ahead Logging (WAL)