0% found this document useful (0 votes)
11 views

DBMS_module IV dup

Uploaded by

soumyaks81
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

DBMS_module IV dup

Uploaded by

soumyaks81
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 58

MODULE 4

NORMALIZATION TECHNIQUES AND


TRANSACTION PROCESSING
Functional Dependency
It is a special form of integrity constraints.
 Functional dependencies are relationships between
attributes in a database.
 They describe how one attribute is dependent on
another attribute.
For eg, if X and Y are attributes of a
table(relation )R. If each value of X is associated
with exactly one value of Y, it can be said X
functionally dependent of Y
Functional Dependency
 In a relational database management, functional
dependency is a concept that specifies the relationship
between two sets of attributes where one attribute
determines the value of another attribute. It is
denoted as X → Y, where the attribute set on the left
side of the arrow, X is called Determinant, and Y is
called the Dependent.
Eg. Functional Dependency
 Consider the relational schema
EMPLOYEE(Eid, ProjectNo, Hours, Ename, Pname, Plocation)
Eid ProjectNo Hours Ename Pname Plocation

 The following functional dependencies should hold


(a). Eid Ename
The value of Eid uniquely determines the EmployeeName
(b). ProjectNo {Pname,Plocation}
The value of a project number uniquely determine the name
and location of project.
(c). [Eid,Pnumber} Hours
The combination of Eid and ProjectNo values uniquely determines
the number of hours the employee works on the project per week.
Eg. Functional Dependency

Eid ProjectNo Hours Ename Pname Plocation


12345 1 32 Smith Product X Bangalore
12345 2 7.5 Smith Product Y Kochi
6668 3 40 Narayan Product Z Tvm
45345 1 20 Joyce Product X Bangalore

31/12/2024
Decomposition
 Decomposition refers to breaking down of one
table into multiple tables.

 While designing a relational database schema,


the problems due to redundancy and null values
can be resolved by decomposition.

 In decomposition, a relation R is replaced with a


collection of smaller relations Ri with specific
relationship between them
Decomposition
 A relation R contains attributes A1 ... An.
Decomposition of R can be considered
“GOOD” if it has the following characteristics.
1) Lossless- This confirms that information in the
original relation can be accurately
reconstructed based on the decomposed
relations.
2) Preserve functional dependencies
Decomposition Example
• Consider the relation Student-Examination.
Stud_Exam(RegNo, StdName, Subj_Name, Subj_Code, Marks)
RegNo StdName Subj_Name Subj_Code Marks

100 Arya DBMS S1 75

100 Arya OOPS S2 70

101 Kiran DBMS S1 73

101 Kiran OOPS S2 75

103 Minu CA S3 80

• It can be seen the data redundancy -duplicate data for


student name and subject name.
• To minimize the redundancy, decompose the table as
follows:-
1. Student(RegNo,StudName)
2. Subject(SubjCode,SubjName)
3. Exam(SubjCode, RegNo, Marks)

Unit IV
31/12/2024
1. SQL
Normalization
 The process of modifying a relation schema so that
it conform to certain rules is called normalization.
 It is a technique for organizing the data in the
database.
 Normalization is a systematic approach of
decomposing tables to eliminate data redundancy
and undesirable characteristics like Insertion,
Update and Deletion Anamolies.
 It is a multi-step process that puts data into tabular
form by removing duplicated data from the relation
tables.
Normalization

 Need of Normalisation
1. the main purpose is to eliminate reduntant(useless)
data.
2. Ensuring data dependencies make sense i.e data is
logically stored.
3. The normal forms are also used to ensure that
various types of anomalies and inconsistencies are
removed from the database.
Normalization-Normal Forms
 A relation is said to be in a particular normal form if it
satisfies certain specified constraints.
 Normalization rule are divided into following normal forms
• First Normal Form
• Second Normal Form
• Third Normal Form
• BCNF
• 4NF
 1NF, 2NF, 3NF and BCNF are based on functional
dependencies among the attributes of a relation
 4NF is proposed based on the concept of multi-valued
dependencies
First normal form
First Normal Form (1NF):
If a relation contains a composite or multi-valued attribute, it
violates the first normal form, or the relation is in first normal
form if it does not contain any composite or multi-valued
attribute. A relation is in first normal form if every attribute in
that relation is singled valued attribute.

A table is in 1 NF iff:

• There are only Single Valued Attributes.


• Attribute Domain does not change.
• There is a unique name for every Attribute/Column.
• The order in which data is stored does not matter.
Example 1NF
Second Example -1NF

In the above table, Course is a multi-valued


attribute so it is not in 1NF.

Below Table is in 1NF as there is no multi-


valued attribute:
Second Normal Form (2NF)

• In the 2NF, relational must be in 1NF.


• In the second normal form, all non-
key attributes are fully functional
dependent on the primary key. ie, A
relation is in 2NF if it has No Partial
Dependency
• Partial Dependency – If the proper subset of
candidate key determines non-prime
attribute, it is called partial dependency.
Example
Regno SubCode Name Mark
1001 3131 Vishnu 40
1002 3131 Hari 45
1001 3132 Vishnu 60
1003 3132 Remya 65
1003 3133 Remya 46

Schema : Marks (Regno, SubCode, Name, Mark)


 Here Primary Key is – {Regno, SubCode}
 The non-key attributes are Name and Mark
 Mark is fully dependent on both {Regno, SubCode}
 But Name is dependent only on Regno which is a proper
subset of primary key. So this table is not in 2NF
Regno SubCode Name Mark
Table Converted to 2NF 1001
1002
3131
3131
Vishnu
Hari
40
45
1001 3132 Vishnu 60
1003 3132 Remya 65
1003 3133 Remya 46

Regno SubCode Mark


1001 3131 40
1002 3131 45
1001 3132 60
1003 3132 65
1003 3133 46

Regno Name
1001 Vishnu
1002 Hari
1001 Vishnu
1003 Remya
1003 Remya
Third Normal Form (3NF)
• A relation is in third normal form, if there is no
transitive dependency for non-prime
attributes as well as it is in second normal
form.
• A relation is in 3NF if at least one of the
following condition holds in every non-trivial
function dependency X –> Y:
• X is a super key.
• Y is a prime attribute (each element of Y is
part of some candidate key).
Transitive Dependency
• In a table we have some column that acts as
the primary key and other columns depends
on this column.
• But what if a column that is not the primary
key depends on another column that is also
not a primary key or part of it? Then we have
Transitive dependency in our table.
Example

Consider a relation employee_details (emp_id, emp_name,


office_code, office_city, office_state)
EMP_ID EMP_NAME office_code office_city office_state

222 Harry 2201 Kochi Kerala


333 Stephan 2228 Chennai Tamilnadu
444 Keerthi 60007 Bangalore Karnataka
555 Remya 6389 Trivandrum Kerala
666 John 2201 Kochi Kerala

Candidate key: {EMP_ID}


Non – Prime attributes : emp_name, office_code,
office_city, office_state
EMP_ID EMP_NAME office_code office_city office_state

222 Harry 2201 Kochi Kerala

333 Stephan 2228 Chennai Tamilnadu

444 Keerthi 60007 Bangalore Karnataka

555 Remya 6389 Trivandrum Kerala

666 John 2201 Kochi Kerala

• Here, office_city & office_state dependent on


office_code and office_code dependent on
EMP_ID. The non-prime attributes (office_city
& office_state ) transitively dependent on
super key(EMP_ID). It violates the rule of third
normal form.
EMP_ID EMP_NAME OFFICE_CODE OFFICE_CITY OFFICE_STAT
E

222 Harry 2201 Kochi Kerala


333 Stephan 2228 Chennai Tamilnadu
444 Keerthi 60007 Bangalore Karnataka
555 Remya 6389 Trivandrum Kerala
666 John 2201 Kochi Kerala

EMP_ID EMP_NAME OFFICE_CODE OFFICE_ OFFICE_CITY OFFICE_STATE


CODE
222 Harry 2201 2201 Kochi Kerala
333 Stephan 2228 2228 Chennai Tamilnadu
444 Keerthi 60007 60007 Bangalore Karnataka
555 Remya 6389 6389 Trivandrum Kerala
666 John 2201 2201 Kochi Kerala
Boyce Codd normal form (BCNF)
• BCNF is the advance version of 3NF. It is
stricter than 3NF.
• A table is in BCNF if every functional
dependency X → Y, X is the super key of the
table.
• For BCNF, the table should be in 3NF, and for
every FD, LHS is super key.
Boyce Codd normal form (BCNF)

Example: Let's assume there is a company where


employees work in more than one department.
EMPLOYEE table:

EMP_ID EMP_CRY EMP_DEPT DEPT_TYPE DEPT_NO


264 India Designing D394
283
264 India Testing D394 300
364 UK Stores D283 232
364 UK Developing D283 549
Boyce Codd normal form (BCNF)
• In the above table Functional dependencies
are as follows:
• EMP_ID → EMP_COUNTRY
• EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
• Candidate key: {EMP-ID, EMP-DEPT}
The table is not in BCNF because neither
EMP_DEPT nor EMP_ID alone are keys.
• EMP_COUNTRY table:
EMP_COUNTRY table:

EMP_ID EMP_COUNTRY
264 India
364 UK
EMP_DEPT table:

EMP_DEPT DEPT_TYPE EMP_DEPT_NO


Designing D394 283
Testing D394 300
Stores D283 232
Developing D283 549
EMP_DEPT_MAPPING table:

EMP_ID EMP_DEPT
D394 283
D394 300
D283 232
D283 549
Functional dependencies:
EMP_ID → EMP_COUNTRY
EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate keys:
For the first table: EMP_ID
For the second table: EMP_DEPT
For the third table: {EMP_ID, EMP_DEPT}
Now, this is in BCNF because left side part of
both the functional dependencies is a key.
Fourth normal form (4NF)

• A relation will be in 4NF if it is in Boyce Codd


normal form and has no multi-valued
dependency.
• For a dependency A → B, if for a single value
of A, multiple values of B exists, then the
relation will be a multi-valued dependency.
STUDENT
STU_ID COURSE HOBBY
21 Computer Dancing
21 Maths Singing
34 Chemistry Dancing
74 Biology Cricket
59 PhysicsHockey
The given STUDENT table is in 3NF, but the COURSE and
HOBBY are two independent entity. Hence, there is no
relationship between COURSE and HOBBY.

In the STUDENT relation, a student with STU_ID, 21


contains two courses, Computer and Math and two
hobbies, Dancing and Singing. So there is a Multi-
valued dependency on STU_ID, which leads to
unnecessary repetition of data.

So to make the above table into 4NF, we can decompose


it into two tables:
STUDENT_COURSE
STU_ID COURSE
21 Computer
21 Math
34 Chemistry
74 Biology
59 Physics
STUDENT_HOBBY
STU_ID HOBBY
21 Dancing
21 Singing
34 Dancing
74 Cricket
59 Hockey
Mobile Database
• A mobile database can be connected to a mobile computing
device over a mobile network.
• Mobile Database Resided on mobile devices.
• Portable computing devices coupled with wireless
communications allow clients to access data from virtually
anywhere and at any time.

• Replicate data on centralized database server and mobile


device, synchronize data on centralized database server and
mobile device; capture data from various sources such as
Internet; manage/analyze data on the mobile device; create
customized mobile applications
• Provide relational database services but require little memory.
Handle local queries without connectivity.
Mobile Computing Architecture

• The general architecture of a mobile platform is illustrated in Fig

Slide 30- 37
Mobile Computing Architecture(2)
• It is distributed architecture where a number of computers,
generally referred to as Fixed Hosts and Base Stations are
interconnected through a high-speed wired network.
– Fixed hosts are general purpose computers configured to
manage mobile units. Performs the transaction and data
management functions.
– A base station is capable of connecting with a Mu and is
equipped with a wireless interface.
– It manages its own database with DBMS functionality. It also
locate the mobile units and manage the requirements of mobile
environments.
– Mobile Units are portable computers that move around a
geographical region.
– Base stations function as interface to the fixed network and the
Slide 30- 38
Mobile Units(MUs).
Mobile Computing Architecture
• Mobile units can move freely in a geographic
mobility domain, an area that is circumscribed by
wireless network coverage.
₋ To manage the mobility of units, entire mobility
domain is divided into one or more smaller
domains, called cells, each of which is
supported by at least one base station.
₋ The mobile unit attached to a fixed network, try
to be like a traditional client-server architecture.
₋ But Wireless communications, make use of
another architecture called MANET (mobile ad-
hoc network).
Slide 30- 39
Mobile Computing Architecture
In a MANET, co-located mobile units do not need to
communicate via a fixed network, but instead, form
their own using cost-effective technologies such as
Bluetooth.
MANET applications can be considered as peer-to-
peer, meaning that a mobile unit is simultaneously act
as a client and a server.
In a MANET, mobile units are responsible for routing
their own data.
Concurrency control
Concurrency Control is the management
procedure that is required for controlling
concurrent execution of the operations that
take place on a database.
Concurrent Execution in DBMS

• In a multi-user system, multiple users can access and use the


same database at one time, which is known as the concurrent
execution of the database. It means that the same database is
executed simultaneously on a multi-user system by different
users.
• While working on the database transactions, there occurs the
requirement of using the database by multiple users for
performing different operations, and in that case, concurrent
execution of the database is performed.
• The thing is that the simultaneous execution that is performed
should be done in an interleaved manner, and no operation
should affect the other executing operations, thus maintaining
the consistency of the database. Thus, on making the concurrent
execution of the transaction operations, there occur several
challenging problems that need to be solved.
Problems with Concurrent Execution
• Problem 1: Lost Update Problems (W - W
Conflict)
• The problem occurs when two different
database transactions perform the
read/write operations on the same
database items in an interleaved manner
(i.e., concurrent execution) that makes the
values of the items incorrect hence making
the database inconsistent

• At time t6, transaction TX writes the value


of account A that will be updated as $250
only, as TY didn't update the value yet.
• Similarly, at time t7, transaction TY writes
the values of account A, so it will write as
done at time t4 that will be $400. It means
the value written by TX is lost, i.e., $250 is
lost.
• Hence data becomes incorrect, and
database sets to inconsistent.
Dirty Read Problems (W-R Conflict)

• The dirty read problem occurs when one


transaction updates an item of the database,
and somehow the transaction fails, and before
the data gets rollback, the updated database
item is accessed by another transaction. There
comes the Read-Write Conflict between both
transactions.
• For example:
• Consider two transactions TX and TY in the
below diagram performing read/write
operations on account A where the available
balance in account A is $300:
• Then at time t5, transaction TX rollbacks due to
server problem, and the value changes back to
$300 (as initially).
• But the value for account A remains $350 for
transaction TY as committed, which is the dirty
read and therefore known as the Dirty Read
Problem.
Unrepeatable Read Problem (W-R Conflict)

Also known as Inconsistent Retrievals Problem


that occurs when in a transaction, two
different values are read for the same
database item.
Consider two transactions, TX and TY,
performing the read/write operations on
account A, having an available balance =
$300. The diagram is shown below:
• After that, at time t5, transaction TX reads
the available value of account A, and that
will be read as $400.
• It means that within the same transaction
TX, it reads two different values of account
A, i.e., $ 300 initially, and after updation
made by transaction TY, it reads $400. It is
an unrepeatable read and is therefore
known as the Unrepeatable read problem.
Concurrency Control Protocols

• The concurrency control protocols ensure the atomicity, consistency, isolation,


durability and serializability of the concurrent execution of the database
transactions. Therefore, these protocols are categorized as:
• Lock Based Concurrency Control Protocol-
It is a mechanism in which a transaction cannot read or write data
unless the appropriate lock is acquired. This helps in eliminating the
concurrency problem by locking a particular transaction to a particular user

• Time Stamp Concurrency Control Protocol


The Timestamp-based protocol ensures that every conflicting
read and write operations are executed in a timestamp order. The older
transaction is always given priority in this method. It uses system time to
determine the time stamp of the transaction. This is the most commonly used
concurrency protocol.
• Validation Based Concurrency Control Protocol
It is also known as the optimistic concurrency control
technique. The protocol associated with three phases for managing concurrent
transactions such as read phase, validation phase, and write phase.
Transaction
 Transaction is an atomic unit of work that is either completed in
its entirety or not done at all.
 The operations that make up a transaction typically consist of
requests to access existing data, update existing data, add new
data, or any combination of these requests.
 For eg, if we sell a product to a customer, the billing takes place.
 Here Transaction consists of two parts.
 1. update the inventory by subtracting the quantity of items sold.
 2. Update the account with amount received.
Transaction Concepts
Transaction operation can either be embedded
within an application program or specified
interactively via high-level query language
The statements of a transaction are enclosed
within the begin transaction and end transaction
statements.
For successful completion of a transaction and
database changes to be permanent, the
transaction must be completed in its entirety.
Transaction Concepts
The basic database access operations that a
transaction can include are : read_item(X) and
write_item(X)
read_item(X) – Reads a database item named X
Steps:
1.Find the address of disk block that contain X.
2.Copy that disk block into a buffer in main
memory.
3.Copy item X from the buffer to the program
variable X.
Transaction Concepts
write_item(X)- write the value of a program variable X into the
database item named X. steps include

1. Find the address of disk block that contain X.

2. Copy that disk block into a buffer in main memory.

3. Copy item X from the program variable named X into its


correct location in buffer.

4. Store the updated block from the buffer back to disk.


Eg. 1
• Consider a book store have 100 copies of a book in stock.
Suppose selling 10 books
• Transaction consists of:
• The data item representing no.of copies of books which can be
denoted as x must be read from permanent storage to primary
memory. (Read)
• The data value of x is then updated by subtracting 10.
• New value of x is then written back to permanent storage(write).
• As this transaction takes place, DBMS must ensure that no other
transaction accesses X.
Eg. 2.
Transfer Rs.5000 from account A to account B
Read(account A)
A:A-5000
Write(A)
Read (Account B)
B=B+5000
Write B.
For the above eg, if debit operation successful but credit fails, the data
is not in a stable state. Either both operation succeed or both fail.
So each transaction must succeed or fail as a complete unit, it cannot
remain in an intermediate state.
Transaction Properties

ACID Property
 Atomicity

 Consistency

 Isolation

 Durability

31/12/2024 Unit III 3. Transaction


Management
Transaction Properties
ATOMICITY
 Atomicity implies that either all of the operations
that make up a transaction should execute or none
of them should occur
The database system keeps track of the old values
of any data on which a transaction performs
If the transaction does not complete its
execution, the old values are restored to make it
appear as though the transaction never executed
Transaction Properties
CONSISTENCY
Consistency implies that if all the operations of
a transaction are executed completely, the
database is transformed from one consistent
state to another.
Ensuring consistency for an individual
transaction is the responsibility of the
application programmer.
Transaction Properties
ISOLATION

A transaction should appear as though it is being

executed in isolation from other transactions. That is

the executionof a transaction should not be

interfeared with any other transactions executing

concurrently.

31/12/2024
Transaction Properties
DURABILITY

 Durability (permanence) implies that once a transaction is

completed successfully, the changes made by the

transaction persist in the database, even if the system fails

 Recovery management component of the database

system is responsible for ensuring durability

You might also like