Escolar Documentos
Profissional Documentos
Cultura Documentos
• Banking
• Travel ticket reservation
• Library catalog search
1.Defining the database: This includes defining the structures, data types,
constraints, indexes etc.
Database catalog/Data dictionary/ called as Meta-data
2.Constructing the database: This means storing data into the database
structures and storing on some storage medium.
What is DBMS?
What is a Database System?
Data independence
Efficient data access
Data integrity and security
Data Administration
Concurrent access and Crash recovery
Reduced application development time
Content
Semantic data models: More abstract high-level data models that make it easier
for a user to come up with a good initial description of the data in an enterprise.
Contain wide variety of constructs that help describe a real-world enterprise data.
Ex. ER model
Representational / Implementation data models:
These are DBMS specific data models and are built around just few basic constructs.
Ex. Relational data model, Object data model
A database design in terms of a semantic model serves as a useful starting point and
is subsequently translated into a database design in terms of the data model the
DBMS supports.
Three-Schema Architecture
A database can be described using three different levels of abstractions.
Description at each level can be defined by a schema. For each abstraction we
focus on one of the specific issues such as user views, concepts, storage etc.
External Level
Physical Schema
Physical/Internal
Level
Storage
Data Independence:
The three-level architecture which is the result of the three-level
abstraction on database, leads to data independence.
Transaction Management
A transaction is a collection of operations that perform a single logical
operation or function in a database application.
Concurrent Transactions
W e b fo r m A p p lic a t io n SQL
fr o n t e n d in te r fa c e
SQL
C om m and
Q u e r y E n g in e
T r a n s a c t io n
M anager
R e c o v e ry
B u ffe r / D is k / F ile M anager
L ock M anager
M anager
C o n c u rre n c y
c o n tro l m a n a g e r
DBMS
In d e x file s
/s y s te m
c a ta lo g /d a ta
b lo c k s
Database Implementers
End users
Application Programmers
Database administrator (DBA)
DBA’s role:
1. Design of physical & Conceptual schemas
2. Security and authorization
3. Data availability , recovery and backup
4. Database tuning- modifying the schemas to meet the
requirements
SSN, DNUMBER, and PNUMBER are the primary keys for the
relations EMPLOYEE, DEPARTMENT, and PROJECT as shown.
Se x (1, 1 ) (4, N ) N am e
L oca tio n
N am e Salar y
Em ploye e d ep artm ent
S U P ER V IS IO N
(0, N) W O R K S_O N
C on trolled
Em p loye e (1 , 1 )
(1 , N ) proje ct
P ro ject
D E PE N D E N T S_ OF
PR O JE C T
Nam e
D e pe nd ent N u m be r
(1, 1)
Lo ca tio n
D EP EN D EN T
R e la tio ns hi p
Nam e Se x B d ate
For each binary 1:1 relationship type R in the ER schema, identify the relations S
and T that correspond to the entity types participating in R.
Se x (1, 1 ) (4, N ) N am e
L oca tio n
N am e Salar y
Em ploye e d ep artm ent
S U P ER V IS IO N
(0, N) W O R K S_O N
C on trolled
Em p loye e (1 , 1 )
(1 , N ) proje ct
P ro ject
D E PE N D E N T S_ OF
PR O JE C T
Nam e
D e pe nd ent N u m be r
(1, 1)
Lo ca tio n
D EP EN D EN T
R e la tio ns hi p
Nam e Se x B d ate
EMPLOYEE
Ssn Fname Minit Lname Birthdatae Address jobtype Typing speed Tgrade EngType
EMPLOYEE
Mapping specialization.
Content
Requirement analysis
Understanding the domain
Identifying the data to be stored
Identifying the constraints
Conceptual Database design
E-R modeling/UML
Logical Database Design
Designing tables and relationships
Refinement of schema
Physical database design
Indexing
Clustering
Storage formats
Alternate keys: The candidate keys other than the PK, are known as
alternate keys.
Entity Type
Relationship Type
Attribute
Key Attribute
Multivalued Attribute
Composite Attribute
Derived Attribute
R Total Participation of E1 in R
E1 E2
Manages
Manager Employee
Degree of a Relationship
Manages
• If there are two entity types involved it is a binary relationship type Manager Employee
Employee
1 is married to 1
One to one (1:1) relationship Man Women
1 Manages m
Manager Employee
One to many (1:M) relationship
m 1
Studies
Many to one (M:1) relationship Student Course
m n
Teaches
Many to many (M:N) relationship Lecturer Student
If all the entities of an entity type are involved in the relationship then that entity type’s
involvement said to be total in that relationship. In the below relationship if each employee is
associated with at least one dept. Then the participation of EMP is total. Here, EMP works for
DEPT.
If, only few entities of the set are involved the participation is partial.
E1 R E2
* 1
Multiplicity
EMP DEPT
Name
Dependent Number
(1, 1)
Location
DEPENDENT
Relationship
Name Sex Bdate
Employee
IS A
No_Hrs Cid
Hourly_Emp Contract_Emp
Class diagrams can be used to describe the database at conceptual level, like ER
diagrams.
Content
Values that can appear in a column for any row is called the
domain of that attribute.
BITS Pilani, Hyderabad Campus
Relational Database Schema is denoted by
Ex: Student (name, age, branch). Here Student is the relation name.
Student.age - denotes age attribute of Student relation.
Characteristics of a Relation:
Values in a tuple under each column must be atomic (simple & single).
Dependencies –
Functional dependency : What attributes value defines the value of
another attribute is known as dependency.
c in R1 refers to p in R2
The FK attribute R1 has the same domain as the primary key attribute of R2.
Constraints can be specified while defining the structure & also as triggers.
Delete FK
c in R1 refers to p in R2
If insert a tuple in R1 where the value for c is not in p of R2, then don’t allow.
What if a tuple in R2 is deleted: Cascade, don’t allow, set to default, set to null.
EM PLO YE E N um ber of D EP A R T M EN T
Ssn
E m ployee
(0, 1) S tart D ate
Bdate M anager (1, 1)
C ontrolling (0, N )
(0, N ) departm ent
M A N A G ES
(0, 1)
S upervisor S upervisor H ours
C O N T R O LS
S U P E RV IS IO N (0, N ) W O RK S _O N
C ontrolled
E m ployee (1, 1)
(1, N ) project
P roject
D E P E N DE N T S _O F
PR O JEC T
N am e
D ependent N um ber
(1, 1)
Location
D EP EN D E N T
R e la tio nship
N am e Sex B date
Content
Query languages & Formal query languages for Relational data model
Introduction to Relational Algebra
Relational operators
Set operators
Join operators
Aggregate functions
Grouping operator
Relational Calculus concepts
o Union,
o Intersection,
o Difference,
o Cartesian product.
B. Relational Operations
o Select,
o Project,
o join,
o Division etc.
R1 dno=5 ( EMP )
R2 name,age ( R1 )
R1 & R2 are the names given to intermediate results(relations).
Intersection R1 R2
Difference R1 – R2
(rho)
Ex: S (b ,b ,b ) ( R)
1 2 3
S ( R)
Selects all values for B column in R which contains all values under A
in S.
Hence the no. column in T is only B.
Joins tuples from DEPT & EMP where Mgrssn in DEPT is equal to ssn
in EMP and stores the new tuples in relation D.
Equijoin is a special type of join where the join condition is ‘=’ (equals
operator) only.
Name EmpID Dept Name Dept Name Manager Name EmpID Dept Name Manager
Grouping:
The tuples of a relation are first grouped by the value of some attribute and
then aggregate functions are applied on individual groups.
Symbol use is – £
The above expression first group the tuples in EMP table based on Dno, and
then applies count function on individual groups this will output no. of
employees in each department.
Dno Count (SSn)
Result relation
It is equivalent to:
{ {set of all employees} - {set of employees with
Dependents} }
R1 Π ssn (Employee)
R2 Π essn (Dependent)
Result R1- R2
R1
essn Count_Dependent_name
101 3
102 1
R1 σ Dname=‘ACCOUNTS’ (Department)
A B B A
a1 b1 b1 a1
R1 Πessn, pno(Works_on) a1 b2 b2 a4
a1 b3 b3
R2 Πpnumber(Project) a2 b2
a2 b3
Result R1 ÷ R2 a3 b1
a3 b2
a3 b3
a4 b3
Any expression for data retrieval written in relational algebra can also
be written in relational calculus and vice-versa.
{t | condition (t)}
t – tuple variable
Selects all tuples from EMP such that for each tuple selected, the salary
value is > 50,000.
The expression EMP(t) specifies from where the tuple t must be chosen.
Note: The above query retrieves all the attributes of relation EMP.
Content
Introduction to SQL
Features of SQL
DDL Statements
DML commands
3. Embedded SQL: Allows users to call SQL code from host languages like
C, C++ & Java.
TO DROP A COLUMN
We can also give names to constraints and later use the names
to access those constraints and alter them.
Retrieves the birthdate & address of the employees whose first name
is ‘John’.
Ex. 2 Join operation
SELECT Fname, Lname, Address
FROM EMPLOYEE, DEPARTMENT
WHERE Dname = ‘Research” and Dnumber = Dno;
Retrieves first name, last name and address from joined truples from
employee and department. The joining condition is Dnumber in
department table is equal to Dno in employee table. We can also do
aliasing (renaming) of tables to avoid ambiguity.
This will retrieve ssn, Dname from the relation which is result of cross
product of employee and department tables.
Ex. 6: SELECT *
FROM EMPLOYEE
WHERE Dno = 5;
The above query will retrieve all the columns from employee table for
the tuples where Dno = 5.
SELECT fname
FROM EMPLOYEE
WHERE Address LIKE ‘% Houston, Texas %’;
Order By:
The default ordering of the result is ascending. We can specify the key
word DESC if we wish a descending order of values.
SELECT Fname, Dno, age
Ex. 12 FROM EMPLOYEE
WHERE salary > 30,0000
ORDER BY Dno;
Content
SELECT E.Fname
FROM EMPLOYEE AS E
WHERE E.ssn IN(SELECT ESSN FROM DEPENDENT
WHERE E.FNAME = DEPENDENT_NAME);
We can also use ‘EXISTS’ to check the existence of at least one tuple
in the result.
Ex. 6 Retrieve the name of employees who have two or more dependents
SELECT Fname
FROM EMPLOYEE
WHERE (SELECT COUNT (*) FROM DEPENDENT WHERE SSN
= ESSN) > = 2;
Updates tuples in Employee table for the tuples with ssn = 141, sets
the value of the attribute salary to 60,000
In fact when a view is updated, the corresponding base tables are the
structures which are to be updated.
View definitions are stored in database, not the result of the view.
From then onwards view can be seen as a table and queries can be
posed on it.
EMPLOYEE
FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY SUPERSSN DNO
DEPARTMENT
DNAME DNUMBER MGRSSN MGRSTARTDATE
DEPT_LOCATIONS
DNUMBER DLOCATION
PROJECT
WORKS_ON
DEPENDENT
select ssn
from Employee
where ssn NOT IN ( select essn
from Dependent
);
select essn
from Dependent
group by essn
having count(*) > 2;
Select essn
From Works_on
Group By essn
Having COUNT(*) = (select COUNT(*) from project);
select E.essn
from Works_on as E
where ((select pno from Works_on where essn=E.essn)
contsins
(select pnumber from Project));
BITS Pilani, Hyderabad Campus
5. Find the projects controlled by departments located in
Mumbai.
update Employee
set salary=20000
where dnum = (select dnumber
from Department
where Dname=‘HR’);
delete
from Employee
where salary < 5000;
delete
from Employee;
Content
All database applications have certain constraints that must hold for the
data.
These set of constraints help to make the system to accept correct and
valid data.
F covers E if every FD in E is in F+
F and E are equivalent if E+ = F+
key Attribute: An attribute which is part of some key (any Candidate key)
10 Engg HYD
CHENNAI
20 Mark HYD
MUMBAI
Condition for 2NF: All non-key attributes are fully functionally dependent on
key (or) no non-key attribute should be dependent on part of key(partial
dependency).
3 NF and BCNF
Decomposition requirements
Lossless join decomposition
Dependency preserving decomposition
Examples
10 Engg HYD
CHENNAI
20 Mark HYD
MUMBAI
Condition for 2NF: All non-key attributes are fully functionally dependent on
key (or) no non-key attribute should be dependent on part of key(partial
dependency).
i) X must be a superkey or
ii) A is key attribute
BITS Pilani, Hyderabad Campus
BCNF (Boyce Codd Normal Form)
It is a stricter form of 3NF
Condition
r R (r )
1
* R2
(r )………….= r
R1
(r ) = projection of r on R1
r – relation instance in R
F = FDs on R
R1 (F) R2 (F) ...., Rm (F) F
R1 ( f ) - is projection of F on R1.
Note:
•Not every BCNF is dependency preserving
•Limited amount of redundancy in 3NF in the form of
transitive dependency is better than losing FDs as result of
bringing 3NF to BCNF.
Content
1. Introduction to hashing
2. Internal hashing
3. Collision
4. External hashing
5. Static hashing
6. Dynamic hashing
In most cases the hash field is also a key field of the file, in which case it
is called as hash key.
Once the disk block is known, the actual search for the record within the
block is carried out in main memory buffer.
1
2
M-2
M-1
Disk
• What is hashing
• Internal hashing
• External hashing
• What is static external hashing
• What is dynamic hashing
• How Extendible and Linear hashing techniques work
Content
What is Indexing
Primary and Secondary indexes
Dense and Sparse Indexing
Multilevel Indexing
Designing Primary and Multilevel Indexes
Some times more than one indexing may be required for a file.
Hence, a file can have at most one primary index o one clustering
index, but not both.
Ordering field
Nonordering field
(secondary index)
Key
Non-key
(primary index) key Non-key
(Clustering index)
Value Pointer
Index file
Data file
(data records)
Sparse Index : Index records are created only for some data file
records. This occupies less space. Sparse index can be on primary or
secondary key.
Ind ex 2
Files/Blocks 5
6
Pointer to 9
Ke y block
2
15 15
25 17
18
30 19
38
45 25
27
60 29
30
35
6
9
24
24
32
32
36 24
36
40 40
40
50 54
50
54
54
56
56
60
60
Sparse index
Dense indexing File with data
records
45 45
28
39
45
45
Data records
Ind ex 2
Files/Blocks 5
6
Pointer to 9
Ke y block
2
15 15
25 17
18
30 19
38
45 25
27
60 29
30
35
6
9
First Level 5
6
Pointer to 9
Key block
2
Second Level
15 15
Pointer to 25 17
Key next level
18
2
30 19
30
38
60
45 25
27
60 29
30
35
6
9
No. of levels=t=3
No. of block accesses= No. index levels + 1= t+1=4
Content
Binary tree
Each node has max two children (left and right). Hence at ith level, no of
nodes present are 2(i-1) (root is at level 1).
Complete binary tree: All nodes except at last level are present.
Binary Search Trees: for each node in the tree, all values stored in its left
subtree are less than value stored in the node and all values stored in the
right subtree are greater than the value in the node.
No of children = (m) = 5
No of keys = (m -1) = (5-1) = 4
B+ Tree of Order p
It is a balanced tree, (all leaves are at same level).
Each internal node is of the form- 24 32 40 60
K1 K2 K3 K4
5 14 19 17 40
Leaf
level 3 4 10
Record
pointer
Construct a B+ tree with given specifications. The order of the tree, p=3
and pleaf =2. The tree should be such that all the keys in the subtree pointed
by a pointer which is preceding the key must be equal to or less than the
key value , and all the keys in the subtree pointed by a pointer which is
succeeding the key must be greater than the key.
Insert the following keys in same order- 56, 22, 78, 42, 102, 90, 96, 35.
Show how the tree will expand after each insertion, and the final tree.
Next, delete 56, 46, 22 in the same order and show the status of the tree
after each deletion.
Content
Transaction:
Storage Hierarchy
DB system resides on nonvolatile storage.
Input (X) – The physical block with data item X is brought from disk into
main memory.
Output (X) – Buffer block containing the data item X is sent to disk to
replace the appropriate physical block.
B
Disk
Output (B)
Main Memory
Note: Reading is must but transaction need not write every item. The modified
blocks can be written back onto the disk during page replacement in main
memory.
If the system crashed before the new value is written to the disk, then the
new value is lost forever and never written to the disk.
Hence, as a result of failure, state of the system will not reflect the state of
the real world that the database is supposed to capture.
Hence the state of the DB must be restored to the state it was in just
before the transaction started its execution.
Content
Concurrent Transactions
Transaction Schedule
Serial and Concurrent Schedules
Need for Concurrency Control
Conflicting Operations
Conflict Equivalent Schedule
Test for Conflict Serializability
View Equivalent Schedule
View Serializability
Read (A)
A = A + 50
Time
Read (A)
A = A + 100
Write (B)
Write (A)
W()
W()
Let S be a schedule.
W(A)
W(A)
R(B)
R(B)
W(B)
For each data item Q, if the transaction Ti reads the initial value of Q in S, then
transaction Ti must in schedule S, also read the initial value of Q.
For each data item Q, if transaction Ti executes read (Q) in S, and the value
produced by transaction Tj (if any) then transaction Ti must in schedule S also read
the value of Q that was produced by transaction Tj.
For each data item Q, the transaction if any that performs the final write(Q)
operation in schedule S must perform the final write(Q) operation in schedule S.
Note: Every conflict serializable schedule is view serializable. But not all view
serializable schedules are conflict serializable.
BITS Pilani, Hyderabad Campus
Summary
What are concurrent Transactions
What are Serial and Concurrent Schedules
Why Concurrency Control needed in DBMS
Conflict Equivalent Schedule and its importance
Test for Conflict Serializability
Contents
This is to make sure that when one transaction access a data item no other
transaction can modify that data item.
1. Lock-based protocols
2. Timestamp-based protocols
S True False
X False False
X(B)
X(C) – Transaction locks
W(B)
C in X-mode
S(B)
W(B) – transaction write B
S(C)
T4X(B) after
T2 X(B)
T4 T3
Timestamp based:
Wait-Die: If Ti is older than Tj it is allowed to wait otherwise
aborted.
Wound-wait: If Ti older than Tj allowed to run by aborting Tj
else Ti will wait.
Priority based
Wait-Die: If Ti has higher priority than Tj it is allowed to wait
otherwise aborted.
Wound-wait: If Ti lies higher priority it is allowed to run by
aborting Tj else Ti will wait.
BITS Pilani, Hyderabad Campus
Two-phase locking protocol:
According to this each transaction issues lock and unlock requests in two
phases.
i) Growing phase: In this phase, a transaction may obtain locks but
may not release any lock.
ii) Shrinking phase: In this phase, a transaction may release locks
but may not obtain any new locks.
Content
Introduction to Recovery
Recovery strategies
Log-based recovery
Check-pointing
Shadow paging
When such thing happens we must make sure that the database is
restored to its previous consistent which existed before the start of the
transaction (which has failed).
This process is known as recovery process.
BITS Pilani, Hyderabad Campus
Recovery Techniques
•Transaction name
•Data item name
•Old value
•New value
Output all log records currently in main memory onto stable storage
During the recovery process the redo / undo operations for the
transactions will be considered which occur after or just before
latest <check point> record on log.
In shadow paging technique, two page tables are used. The first is
current page table and the second is shadow page table. When a
transaction starts both page tables are identical. The shadow page
table is never changed during the execution of the transaction. The
current page table may be changed when a transaction performs a
write operation. All input and output operations use current page table.
When a block page is modified it is written onto different location on
the disk and the old block which contains older values exist and can be
accessed using the shadow page table.
This is sufficient to recover from the failure.
This technique doesn’t require a log and no redo/undo operations are
needed.
BITS Pilani, Hyderabad Campus
Shadow paging
6. SQL-99
DDL
DML
Views in SQL
10. Hashing
Internal Hashing
Collision resolution
Static and Dynamic eternal Hashing
Entity Types:
EMPLOYEE,
DEPARTMENT, PROJECT,
DEPENDENT
Relationship Types:
WORKS_FOR,
MANAGES,
WORKS_ON,
CONTROLS,
SUPERVISION,
DEPENDENTS_OF
Database State for BLOOD BANK
ER DIAGRAM – COMPANY DATABASE
COUNRIES
CODE
NAME
ER DIAGRAM – MERCHANT PAYMENT
PROCESSING
Thank You
Course No: SEWP ZC322
Course Title: Database
Management Systems
BIOMETRIC SYSTEM
A BioMetric system provides many benefits to organizations. It
enables an employer to have full control of all employees working
hours. It helps control labor costs by reducing over-payments,
which are often caused by transcription error, interpretation error
and intentional error. Manual processes are also eliminated as well
as the staff needed to maintain them.
It is often difficult to comply with labor regulation, but a time and
attendance system is invaluable for ensuring compliance with labor
regulations regarding proof of attendance.
Companies with large employee numbers might need to install
several time clock stations in order to speed up the process of
getting all employees to clock in or out quickly or to record activity
in dispersed locations. In the business world of today we all know
one simple truth…TIME IS MONEY! We work to keep the amount of
time it takes to complete even the simplest tasks down to the
minimum.
VEHICLE COMPARER FRAMEWORK
Vehicle comparison is one of the most
happening comparison when people opt
and choose a type of vehicle.
The Vehicle Comparer Framework allows
user to find the most economical models
available, or choose a specific vehicle and
decide on purchasing the vehicle.
Vehicle Comparer Framework also allows
you to compare the performance, Engine
Details and running costs.
Thank You