Database Management System Module 5 DeSiaMore.

33
Database Management System Module 5 DeSiaMore www.desiamore.com/ifm 1

Transcript of Database Management System Module 5 DeSiaMore.

Page 1: Database Management System Module 5 DeSiaMore.

Database Management System

Module 5

DeSiaMore www.desiamore.com/ifm 1

Page 2: Database Management System Module 5 DeSiaMore.

Boyce-Codd Normal Form

BCNF was designed to cover anomalies that arise when there is more than one candidate key in some set of data requirements.

DeSiaMore www.desiamore.com/ifm 2

Page 3: Database Management System Module 5 DeSiaMore.

Example BCNF

Suppose we have introduced a scheme of majors into degree scheme at a unveristy. The business rules relevant to that prt of this domain covering majors are: Each student may major several areas A student has one tutor for each area

DeSiaMore www.desiamore.com/ifm 3

Page 4: Database Management System Module 5 DeSiaMore.

Example BCNF Each area has several tutors but a

tutor advise in only one area. Each tutor advises several students in

an area. On the grounds of these rules, a

schema produced in third normal form represented below

Majors(studentNo, area, staffNo)

DeSiaMore www.desiamore.com/ifm 4

Page 5: Database Management System Module 5 DeSiaMore.

Example BCNF

A set of sample data is provided in the table below.

DeSiaMore www.desiamore.com/ifm 5

Page 6: Database Management System Module 5 DeSiaMore.

Example BCNF

The schema has the following anomalies: Suppose student 123456 changes one

of his or her majors from computer science to information systems. Doing this means that we lose information about staffNo 234 tutoring on computer science. This is an update anomaly.

DeSiaMore www.desiamore.com/ifm 6

Page 7: Database Management System Module 5 DeSiaMore.

Example BCNF Suppose we wish to insert a new row

to establish the fact that staffNo 789 tutors on computer science. We cannot do this until at least one student takes this area as his or her major. This is an insertion anomaly

These anomalies occur because there are two overlapping candidate keys. R.F. Boyce and E.F. Codd came with the solution.

DeSiaMore www.desiamore.com/ifm 7

Page 8: Database Management System Module 5 DeSiaMore.

BCNF A relation is in BCNF if every

determinant is a candidate key. The schema above can be converted into BCNF in one of two ways: Schema 1:StudentTutorial(studentNo, staffNo)TutorAreas(staffNo, area) Schema 2:StudentTutorials(studentNo, area)TutorAreas(staffNo, area)

DeSiaMore www.desiamore.com/ifm 8

Page 9: Database Management System Module 5 DeSiaMore.

Concurrency control and recovery

DeSiaMore www.desiamore.com/ifm 9

Page 10: Database Management System Module 5 DeSiaMore.

Transactions

In multi-user database system the procedures that cause changes to a database or retrieve data from the database are called transactions.

A transaction may be defined as a logical unit of work.

Include activities performed by an individual, group, organisation or software process on database.DeSiaMore www.desiamore.com/ifm 10

Page 11: Database Management System Module 5 DeSiaMore.

ACID

To remain an accurate reflection of its real-world domain, any transaction such as the one above should demonstrate the properties of atomicity, consistency, isolation and durability (ACID)

DeSiaMore www.desiamore.com/ifm 11

Page 12: Database Management System Module 5 DeSiaMore.

Atomicity – Since a transaction consists of a collection of actions, the DBMS should ensure that either all the transaction is performed or none of is performed.

Consistence – all transactions must preserve the consistency and integrity of the database. Operations performed by an updating transaction, for instance, should not leave the database in an inconsistent state

DeSiaMore www.desiamore.com/ifm 12

Page 13: Database Management System Module 5 DeSiaMore.

Isolation – While a transaction is updating shared data, that data may be temporarily inconsistent. Such data not be made available to other transactions until the transaction in question has finished using it.

DeSiaMore www.desiamore.com/ifm 13

Page 14: Database Management System Module 5 DeSiaMore.

Durability – When a transaction completes, the changes made by the transaction should be durable. That is, they should preserved in the case of hardware or software failure.

DeSiaMore www.desiamore.com/ifm 14

Page 15: Database Management System Module 5 DeSiaMore.

Transaction in SQL-Based System.

In most SQL-Based products, a transaction is simply a sequence of SQL-statement that is packaged as a single entity.

Relational DBMS maintain consistency by ensuring either that all the SQL statements in a transaction complete successifully or that none do.

DeSiaMore www.desiamore.com/ifm 15

Page 16: Database Management System Module 5 DeSiaMore.

Transaction in SQL-Based System

In SQL the statements COMMIT and ROLLBACK are used to delineate transactions.

COMMIT makes permanent changes to a database.

ROLLBACK undoes all changes made in an unsuccessful transaction.

DeSiaMore www.desiamore.com/ifm 16

Page 17: Database Management System Module 5 DeSiaMore.

Example SQL-Transaction

INSERT INTO registration(studentNo, moduleName) VALUES (34698, ‘Relational Database Systems’)

UPDATE Modules SET roll = roll + 1COMMIT

DeSiaMore www.desiamore.com/ifm 17

Page 18: Database Management System Module 5 DeSiaMore.

CONCURRENCY Data in the database systems can be

accessed by many users; multiple data sharing. E.g. Airline reservation system

There must be mechanism of controlling shared or concurrent access.

When there are several transactions executed on parallel on a shared database, their execution must be synchronised.

DeSiaMore www.desiamore.com/ifm 18

Page 19: Database Management System Module 5 DeSiaMore.

Concurrency Control

The primary objective of concurrency control is to prevent interference between transactions to occur.

A major control strategy used for concurrency control is locking.

DeSiaMore www.desiamore.com/ifm 19

Page 20: Database Management System Module 5 DeSiaMore.

Locking

It is the most approach in contemporary DB.

When a transaction locks a data-item it is saying to other transactions ‘Hey I am doing something with this data-item, wait until I have completed may task’.

Importance of this to serialise access to limited resources.DeSiaMore www.desiamore.com/ifm 20

Page 21: Database Management System Module 5 DeSiaMore.

Two types of Locks

Read locks – A read lock gives only read access to data and prevents any other transaction from updating the locked data. A transaction applies this type of lock

when it wishes to query a file but does not want to change it.

Also it does not want other transactions to change it while it is looking at it.DeSiaMore www.desiamore.com/ifm 21

Page 22: Database Management System Module 5 DeSiaMore.

Two types of Locks

Write locks; this gives both read and write access to a data-item. It also prevents any other transaction from reading from or writing to a data.

DeSiaMore www.desiamore.com/ifm 22

Page 23: Database Management System Module 5 DeSiaMore.

Transaction Manager and Transaction Log

Transaction manager is a module within the kernel of a DBMS that handles the throughput of transactions against a database.

It ensures that transaction either completes successfully or fails.

DeSiaMore www.desiamore.com/ifm 23

Page 24: Database Management System Module 5 DeSiaMore.

Transaction Log

The transaction log is a file that contains data about the updates affecting a database.

Such data may comprise transaction records.

DeSiaMore www.desiamore.com/ifm 24

Page 25: Database Management System Module 5 DeSiaMore.

Recovery Recovery is the process of ensuring that

the database can achieve a consistent state in the event of failure.

Failure can occur either when writing the data to buffers or while flushing the buffers.

Flushing is the process of transferring data from buffers in main memory to secondary memory.

DeSiaMore www.desiamore.com/ifm 25

Page 26: Database Management System Module 5 DeSiaMore.

Recovery

If a transaction issued a commit but failure occurred before flushing completes, then the changes to the database will not be made permanent.

In this case the recovery module will need to redo the transaction.

DeSiaMore www.desiamore.com/ifm 26

Page 27: Database Management System Module 5 DeSiaMore.

Distributed Database System

A distributed database system is a database system which is fragmented or replicated on the various configurations of hardware and software, located usually at different geographical sites within an organisation.

DeSiaMore www.desiamore.com/ifm 27

Page 28: Database Management System Module 5 DeSiaMore.

Distributed Database System

Distribution is solely said of fragmentation and replication of data.

A data fragment constitutes some subset of the original database.

A data replicate is constitutes of some copy of the whole or part of the original database.

DeSiaMore www.desiamore.com/ifm 28

Page 29: Database Management System Module 5 DeSiaMore.

Distributing Data

DeSiaMore www.desiamore.com/ifm 29

Page 30: Database Management System Module 5 DeSiaMore.

Distributing Data

DeSiaMore www.desiamore.com/ifm 30

Page 31: Database Management System Module 5 DeSiaMore.

Distributed Database System An example of distributed database system

DeSiaMore www.desiamore.com/ifm 31

Page 32: Database Management System Module 5 DeSiaMore.

Advantage

DeSiaMore www.desiamore.com/ifm 32

Page 33: Database Management System Module 5 DeSiaMore.

Advantage

DeSiaMore www.desiamore.com/ifm 33