0% found this document useful (0 votes)
286 views43 pages

Chapter: 5 Normalization of Database Tables: in This Chapter, You Will Learn

This document discusses database normalization. It covers: 1) The goals and benefits of normalization including eliminating data redundancies and anomalies. Normalization involves converting tables to higher normal forms like 1NF, 2NF, 3NF. 2) An example of an initial database structure that suffers from data issues and how normalization can address them. 3) The normalization process which involves identifying dependencies and converting tables through steps to eliminate issues and get to higher normal forms. Higher normal forms like BCNF and 4NF are also introduced to further optimize tables in certain cases. Overall normalization is presented as an important technique in database design.

Uploaded by

jay desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
286 views43 pages

Chapter: 5 Normalization of Database Tables: in This Chapter, You Will Learn

This document discusses database normalization. It covers: 1) The goals and benefits of normalization including eliminating data redundancies and anomalies. Normalization involves converting tables to higher normal forms like 1NF, 2NF, 3NF. 2) An example of an initial database structure that suffers from data issues and how normalization can address them. 3) The normalization process which involves identifying dependencies and converting tables through steps to eliminate issues and get to higher normal forms. Higher normal forms like BCNF and 4NF are also introduced to further optimize tables in certain cases. Overall normalization is presented as an important technique in database design.

Uploaded by

jay desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Mithil 9510374124 http://tybca.110mb.

com

Chapter: 5 Normalization of Database Tables

In this chapter, you will learn

• What normalization is and what role it plays in the database design


process
• About the normal forms 1NF, 2NF, 3NF, BCNF,
and 4NF
• How normal forms can be transformed from lower normal forms to
higher normal forms
• That normalization and ER modeling are used concurrently to
produce a good database design
• That some situations require denormalization to generate
information efficiently

5.1 Database Tables and Normalization

• Normalization
– Process for evaluating and correcting table structures to
minimize data redundancies
• helps eliminate data anomalies
– Works through a series of stages called normal forms:
• Normal form (1NF)
• Second normal form (2NF)
• Third normal form (3NF)
– 2NF is better than 1NF; 3NF is better than 2NF
– For most business database design purposes, 3NF is highest
we need to go in the normalization process
– Highest level of normalization is not always most desirable

5.2 The Need for Normalization

• Example: company that manages building projects


– Charges its clients by billing hours spent on each contract
– Hourly billing rate is dependent on employee’s position
– Periodically, a report is generated that contains
information displayed in Table 5.1

• Structure of data set in Figure 5.1 does not handle data very well

• The table structure appears to work; report is generated with ease

• Unfortunately, the report may yield different results, depending on


what data anomaly has occurred

Created By: Mithil Makwana (TYBCA) Page 1 of 43


Mithil 9510374124 http://tybca.110mb.com
5.3 The Normalization Process

5.3.1 Conversion to First Normal Form

• Repeating group
– Derives its name from the fact that a group of multiple
(related) entries can exist for any single key attribute
occurrence
• Relational table must not contain repeating groups
• Normalizing the table structure will reduce these data
redundancies
• Normalization is three-step procedure

Step 1: Eliminate the Repeating Groups

• Present data in a tabular format, where each cell has a single


value and there are no repeating groups
• Eliminate repeating groups by eliminating nulls, making sure
that each repeating group attribute contains an appropriate
data value

Step 2: Identify the Primary Key

• Primary key must uniquely identify attribute value


• New key must be composed

Step 3: Identify all Dependencies

• Dependencies can be depicted with the help of a diagram


• Dependency diagram:
– Depicts all dependencies found within a given table
structure
– Helpful in getting bird’s-eye view of all relationships
among a table’s attributes
– Use makes it much less likely that an important
dependency will be overlooked

A Dependency Diagram: First Normal Form (1NF)

First Normal Form

Created By: Mithil Makwana (TYBCA) Page 2 of 43


Mithil 9510374124 http://tybca.110mb.com

• Tabular format in which:


– All key attributes are defined
– There are no repeating groups in the table
– All attributes are dependent on primary key
• All relational tables satisfy 1NF requirements
• Some tables contain partial dependencies
– Dependencies based on only part of the primary key
– Sometimes used for performance reasons, but should be
used with caution
– Still subject to data redundancies

5.3.2 Conversion to Second Normal Form

• Relational database design can be improved by converting the


database into second normal form (2NF)
• Two steps

Step 1: Identify All Key Components

• Write each key component on separate line, and then write


the original (composite) key on the last line
• Each component will become the key in a new table

Step 2: Identify the Dependent Attributes

• Determine which attributes are dependent on which other


attributes
• At this point, most anomalies have been eliminated

Second Normal Form (2NF) Conversion Results

Second Normal Form

Created By: Mithil Makwana (TYBCA) Page 3 of 43


Mithil 9510374124 http://tybca.110mb.com
• Table is in second normal form (2NF) if:
– It is in 1NF and
– It includes no partial dependencies:
• No attribute is dependent on only a portion of the
primary key

5.3.3 Conversion to Third Normal Form

• Data anomalies created are easily eliminated by completing


three steps

Step 1: Identify Each New Determinant

• For every transitive dependency, write its determinant as a PK


for a new table
– Determinant
• Any attribute whose value determines other
values within a row

Step 2: Identify the Dependent Attributes

• Identify the attributes dependent on each determinant


identified in Step 1 and identify the dependency
• Name the table to reflect its contents and function

Step 3: Remove the Dependent Attributes from Transitive Dependencies

• Eliminate all dependent attributes in transitive relationship(s)


from each table that has such a transitive relationship
• Draw a new dependency diagram to show all tables defined in
Steps 1–3
• Check new tables and modified tables from Step 3 to make
sure that each has a determinant and does not contain
inappropriate dependencies

Third Normal Form (3NF) Conversion Results

Third Normal Form

• A table is in third normal form (3NF) if:

Created By: Mithil Makwana (TYBCA) Page 4 of 43


Mithil 9510374124 http://tybca.110mb.com
– It is in 2NF and
– It contains no transitive dependencies

5.4 Improving the Design

• Table structures are cleaned up to eliminate the troublesome


initial partial and transitive dependencies
• Normalization cannot, by itself, be relied on to make good
designs
• It is valuable because its use helps eliminate data
redundancies
• The following changes were made:
• PK assignment
• Naming conventions
• Attribute atomicity
• Adding attributes
• Adding relationships
• Refining PKs
• Maintaining historical accuracy
• Using derived attributes

The Completed Database

5.5 Surrogate Key Considerations

Limitations on System-Assigned Keys


Created By: Mithil Makwana (TYBCA) Page 5 of 43
Mithil 9510374124 http://tybca.110mb.com

• System-assigned primary key may not prevent confusing


entries
• Data entries in Table 5.2 are inappropriate because they
duplicate existing records
– Yet there has been no violation of either entity integrity
or referential integrity

Duplicate Entries in the JOB Table

5.6 Higher-Level Normal Forms

• In some databases, multiple multivalued attributes exist

5.6.1 The Boyce-Codd Normal Form (BCNF)

• Every determinant in the table is a candidate key


– Has same characteristics as primary key, but for some reason,
not chosen to be primary key
• If a table contains only one candidate key, the 3NF and the BCNF
are equivalent
• BCNF can be violated only if the table contains more than one
candidate key
• Most designers consider the Boyce-Codd normal form (BCNF) as a
special case of 3NF
• A table is in 3NF if it is in 2NF and there are no transitive
dependencies
• A table can be in 3NF and not be in BCNF
– A transitive dependency exists when one nonprime attribute is
dependent on another nonprime attribute
– A nonkey attribute is the determinant of a key attribute

A Table That is in 3NF but not in BCNF

Created By: Mithil Makwana (TYBCA) Page 6 of 43


Mithil 9510374124 http://tybca.110mb.com

Decomposition to BCNF

Sample Data for a BCNF Conversion

Another BCNF Decomposition

5.6.2 Fourth Normal Form

• Table is in fourth normal form (4NF) if


Created By: Mithil Makwana (TYBCA) Page 7 of 43
Mithil 9510374124 http://tybca.110mb.com
– It is in 3NF
– Has no multiple sets of multivalued dependencies
• 4NF is largely academic if tables conform to the following two rules:
– All attributes are dependent on primary key but independent
of each other
– No row contains two or more multivalued facts about an entity

A Set of Tables in 4NF

5.7 Normalization and Database Design

• Normalization should be part of design process


• Make sure that proposed entities meet required normal form before
table structures are created
• Many real-world databases have been improperly designed or
burdened with anomalies if improperly modified during course of
time
• You may be asked to redesign and modify existing databases
• ER diagram
• Provides the big picture, or macro view, of an organization’s
data requirements and operations
• Created through an iterative process
• Identifying relevant entities, their attributes and their
relationship
• Use results to identify additional entities and attributes
• Normalization procedures
• Focus on the characteristics of specific entities
• A micro view of the entities within the ER diagram

Created By: Mithil Makwana (TYBCA) Page 8 of 43


Mithil 9510374124 http://tybca.110mb.com
• Difficult to separate normalization process from ER modeling
process
• Two techniques should be used concurrently

The Initial ERD for a Contracting Company

The Modified ERD for a Contracting Company

The Incorrect Representation of a M: N Relationship

The Final (Implementable) ERD for a Contracting Company

Created By: Mithil Makwana (TYBCA) Page 9 of 43


Mithil 9510374124 http://tybca.110mb.com

Tables with Multivalued Dependencies

5.8 Denormalization

• Creation of normalized relations is important database design goal


Created By: Mithil Makwana (TYBCA) Page 10 of 43
Mithil 9510374124 http://tybca.110mb.com
• Processing requirements should also be a goal
• If tables decomposed to conform to normalization requirements
– Number of database tables expands
• Joining larger number of tables takes additional disk input/output
(I/O) operations and processing logic
– Reduces system speed
• Conflicts among design efficiency, information requirements, and
processing speed are often resolved through compromises that may
include denormalization
• Unnormalized tables in a production database tend to have these
defects:
– Data updates are less efficient because programs that read
and update tables must deal with larger tables
– Indexing is much more cumbersome
– Unnormalized tables yield no simple strategies for creating
virtual tables known as views
• Use denormalization cautiously
• Understand why—under some circumstances—unnormalized tables
are a better choice

Chapter: 7 Introductions to Structured Query Language


(SQL)

In this chapter, you will learn:

Created By: Mithil Makwana (TYBCA) Page 11 of 43


Mithil 9510374124 http://tybca.110mb.com
• The basic commands and functions of SQL
• How to use SQL for data administration (to create tables, indexes,
and views)
• How to use SQL for data manipulation (to add, modify, delete, and
retrieve data)
• How to use SQL to query a database to extract useful information

7.1 Introduction to SQL

• SQL functions fit into two broad categories:


• Data definition language
– SQL includes commands to create
• Database objects such as tables, indexes, and views
• Commands to define access rights to those database
objects
• Data manipulation language
– Includes commands to insert, update, delete, and retrieve
data within the database tables
• SQL is relatively easy to learn
• Basic command set has a vocabulary of less than 100 words
• Nonprocedural language
• American National Standards Institute (ANSI) prescribes a standard
SQL
• Several SQL dialects exist

7.2 Data Definition Commands

• Examine the simple database model and the database tables that
will form the basis for the many SQL examples
• Understand the data environment

7.2.1 The Database Model

Created By: Mithil Makwana (TYBCA) Page 12 of 43


Mithil 9510374124 http://tybca.110mb.com

7.2.3 The Database Schema

• Authentication
– Process through which the DBMS verifies that only registered
users are able to access the database
– Log on to the RDBMS using a user ID and a password created
by the database administrator
• Schema
– Group of database objects—such as tables and indexes—that
are related to each other

7.2.4 Data Types

• Data type selection is usually dictated by the nature of the data and
by the intended use
• Pay close attention to the expected use of attributes for sorting and
data retrieval purposes

• Some Common SQL Data Types

Created By: Mithil Makwana (TYBCA) Page 13 of 43


Mithil 9510374124 http://tybca.110mb.com

7.2.5 Creating Table Structures

• Use one line per column (attribute) definition


• Use spaces to line up the attribute characteristics and constraints
• Table and attribute names are capitalized
• NOT NULL specification
• UNIQUE specification
• Primary key attributes contain both a NOT NULL and a UNIQUE
specification
• RDBMS will automatically enforce referential integrity for foreign
keys
• Command sequence ends with a semicolon

7.2.6 Other SQL Constraints

• NOT NULL constraint


– Ensures that a column does not accept nulls
• UNIQUE constraint
– Ensures that all values in a column are unique
• DEFAULT constraint
– Assigns a value to an attribute when a new row is added to a
table
• CHECK constraint
– Validates data when an attribute value is entered

7.2.7 SQL Indexes

Created By: Mithil Makwana (TYBCA) Page 14 of 43


Mithil 9510374124 http://tybca.110mb.com
• When a primary key is declared, DBMS automatically creates a
unique index
• Often need additional indexes
• Using the CREATE INDEX command, SQL indexes can be created on
the basis of any selected attribute
• Composite index
– Index based on two or more attributes
– Often used to prevent data duplication

7.3 Data Manipulation Commands

• Adding table rows


• Saving table changes
• Listing table rows
• Updating table rows
• Restoring table contents
• Deleting table rows
• Inserting table rows with a select subquery
Common SQL Data Manipulation Commands

Created By: Mithil Makwana (TYBCA) Page 15 of 43


Mithil 9510374124 http://tybca.110mb.com

7.3.1 Adding a table Rows

7.3.2 Saving Table Changes

• Changes made to table contents are not physically saved on disk


until
– Database is closed
– Program is closed
– COMMIT command is used
• Syntax
– COMMIT [WORK]
• Will permanently save any changes made to any table in the
database
7.3.3 Listing Table Rows

• SELECT
– Used to list contents of table
Created By: Mithil Makwana (TYBCA) Page 16 of 43
Mithil 9510374124 http://tybca.110mb.com
• Syntax
– SELECT column list
FROM table name
• Column list represents one or more attributes, separated by
commas
• Asterisk can be used as wildcard character to list all attributes

7.3.4 Updating Table Rows

• UPDATE
– Modify data in a table
• Syntax
– UPDATE table name
SET column name = expression [, column name =
expression]
[WHERE condition list];
• If more than one attribute is to be updated in the row, separate
corrections with commas

7.3.5 Restoring Table Contents

• ROLLBACK
– Used restore the database to its previous condition
– Only applicable if COMMIT command has not been used to
permanently store the changes in the database
• Syntax
– ROLLBACK;
• COMMIT and ROLLBACK only work with data manipulation
commands that are used to add, modify, or delete table rows

7.3.6 Deleting Table Rows

• DELETE
– Deletes a table row
• Syntax
– DELETE FROM table name
[WHERE condition list ];
• WHERE condition is optional
• If WHERE condition is not specified, all rows from the specified table
will be deleted

7.3.7 Inserting Table Rows with a Select Sub query

• INSERT
– Inserts multiple rows from another table (source)
– Uses SELECT sub query

Created By: Mithil Makwana (TYBCA) Page 17 of 43


Mithil 9510374124 http://tybca.110mb.com
• Query that is embedded (or nested) inside another
query
• Executed first
• Syntax
– INSERT INTO table name SELECT column list FROM table
name

7.4 Select Queries

7.4.1 Selecting Rows with Conditional Restrictions

• Select partial table contents by placing restrictions on rows to be


included in output
– Add conditional restrictions to the SELECT statement, using
WHERE clause
• Syntax
– SELECT column list
FROM table list
[ WHERE condition list ] ;
Example: Selected PRODUCT Table Attributes for VENDOR Code
21344
Comparison Operators

Example:
 Selected PRODUCT Table Attributes for VENDOR Codes
Other than 21344
 Selected PRODUCT Table Attributes with a P_PRICE
Restriction
 Selected PRODUCT Table Attributes: The ASCII Code Effect
 Selected PRODUCT Table Attributes: Date Restriction
 SELECT Statement with a Computed Column
 SELECT Statement with a Computed Column and an Alias
7.4.2 Arithmetic Operators: The Rule of Precedence

• Perform operations within parentheses


• Perform power operations
• Perform multiplications and divisions
• Perform additions and subtractions

Created By: Mithil Makwana (TYBCA) Page 18 of 43


Mithil 9510374124 http://tybca.110mb.com
• Example:
Selected PRODUCT Table Attributes: The Logical OR
Selected PRODUCT Table Attributes: The Logical AND
Selected PRODUCT Table Attributes: The Logical AND
and OR

7.4.4 Special Operators

• BETWEEN
– Used to check whether attribute value is within a range
• IS NULL
– Used to check whether attribute value is null
• LIKE
– Used to check whether attribute value matches a given string
pattern
• IN
– Used to check whether attribute value matches any value
within a value list
• EXISTS
– Used to check if a sub query returns any rows

7.5 Advanced Data Definition Commands

• All changes in the table structure are made by using the ALTER
command
– Followed by a keyword that produces specific change
– Three options are available
• ADD
• MODIFY
• DROP

7.5.1 Changing a Column’s Data Type

• ALTER can be used to change data type


• Some RDBMS (such as Oracle) do not permit changes to data types
unless the column to be changed is empty

7.5.2 Changing a Column’s Data Characteristics

• Use ALTER to change data characteristics


• If the column to be changed already contains data, changes in the
column’s characteristics are permitted if those changes do not alter
the data type

Created By: Mithil Makwana (TYBCA) Page 19 of 43


Mithil 9510374124 http://tybca.110mb.com
7.5.3 Adding or Dropping a Column

• Use ALTER to add a column


– Do not include the NOT NULL clause for new column
• Use ALTER to drop a column
– Some RDBMS impose restrictions on the deletion of an
attribute
• Example:
The Effect of Data Entry into the New P_SALECODE
Column
Update of the P_SALECODE Column in Multiple Data
Rows
The Effect of Multiple Data Updates in the PRODUCT
Table (MS Access)

7.5.6 Copying Parts of Tables

• SQL permits copying contents of selected table columns so that the


data need not be reentered manually into newly created table(s)
• First create the PART table structure
• Next add rows to new PART table using PRODUCT table rows
• Example:
PART Attributes Copied from the PRODUCT Table

7.6 Advanced Select Queries

• SQL provides useful functions


– Count
– Find minimum and maximum values
– Calculate averages
• SQL allows the user to limit queries to only those entries having no
duplicates or entries whose duplicates may be grouped

• Example:
1) Selected PRODUCT Table Attributes: Ordered by
(Ascending) P_PRICE
2) Partial Listing of EMPLOYEE Table Contents
Telephone List Query Results
3) A Query Based on Multiple Restrictions
4) A Listing of Distinct (Different) V_CODE Values in the
PRODUCT Table

7.6.3 Some Basic SQL Aggregate Functions

Created By: Mithil Makwana (TYBCA) Page 20 of 43


Mithil 9510374124 http://tybca.110mb.com

1) COUNT Function Output Examples

2) MAX and MIN Function Output Examples

3) The Total Value of All Items in the PRODUCT Table

Created By: Mithil Makwana (TYBCA) Page 21 of 43


Mithil 9510374124 http://tybca.110mb.com

4) AVG Function Output Examples

5) GROUP BY Clause Output Examples

6) Incorrect and Correct Use of the GROUP BY Clause

Created By: Mithil Makwana (TYBCA) Page 22 of 43


Mithil 9510374124 http://tybca.110mb.com

7) An Application of the HAVING Clause

7.7 Virtual Tables: Creating a View

Created By: Mithil Makwana (TYBCA) Page 23 of 43


Mithil 9510374124 http://tybca.110mb.com
• View is a virtual table based on a SELECT query
– Can contain columns, computed columns, aliases, and
aggregate functions from one or more tables
• Base tables are tables on which the view is based
• Create a view by using the CREATE VIEW command

Creating a Virtual Table with the CREATE VIEW Command

7.8 Joining Database Tables

• Ability to combine (join) tables on common attributes is most


important distinction between a relational database and other
databases
• Join is performed when data are retrieved from more than one table
at a time
• Join is generally composed of an equality comparison between the
foreign key and the primary key of related tables

Chapter: 8 Advanced SQL

Created By: Mithil Makwana (TYBCA) Page 24 of 43


Mithil 9510374124 http://tybca.110mb.com
In this chapter, you will learn

• About the relational set operators UNION, UNION ALL, INTERSECT,


and MINUS
• How to use the advanced SQL JOIN operator syntax
• About the different types of subqueries and correlated queries
• How to use SQL functions to manipulate dates, strings, and other
data
• How to create and use updatable views
• How to create and use triggers and stored procedures
• How to create embedded SQL

8.1 Relational Set Operators

. UNION
. UNIONALL
. INTERSECT
. MINUS
. Syntax Alternatives

8.2 SQL Join Expression Styles

8.3 Subqueries and Correlated Queries

. SELECT Subquery Examples


. WHERE Sub query

Created By: Mithil Makwana (TYBCA) Page 25 of 43


Mithil 9510374124 http://tybca.110mb.com
. IN Sub query
. HAVING Sub query
. Multirow Sub query Operator
. FROM Sub query
. Inline Sub query
. Correlated Sub query
. EXISTS Correlated Sub query

8.4 SQL Functions

. 8.4.1 Date And Time Functions

Created By: Mithil Makwana (TYBCA) Page 26 of 43


Mithil 9510374124 http://tybca.110mb.com

. 8.4.2 Numeric Functions

Created By: Mithil Makwana (TYBCA) Page 27 of 43


Mithil 9510374124 http://tybca.110mb.com
. 8.4.3 String Functions

. 8.4.4 Conversion Functions

Created By: Mithil Makwana (TYBCA) Page 28 of 43


Mithil 9510374124 http://tybca.110mb.com

Chapter: 10 Transaction Mgmt & Concurrency Control

Created By: Mithil Makwana (TYBCA) Page 29 of 43


Mithil 9510374124 http://tybca.110mb.com

In this chapter, you will learn

• What a database transaction is and what its properties are


• How database transactions are managed
• What concurrency control is and what role it plays in maintaining
the database’s integrity
• What locking methods are and how they work
• How database recovery management is used to maintain database
integrity

10.1 What is a Transaction?

• Any action that reads from and/or writes to a database may consist
of
– Simple SELECT statement to generate a list of table contents
– A series of related UPDATE statements to change the values
of attributes in various tables
– A series of INSERT statements to add rows to one or more
tables
– A combination of SELECT, UPDATE, and INSERT statements.
• A logical unit of work that must be either entirely completed or
aborted
• Successful transaction changes the database from one consistent
state to another
– One in which all data integrity constraints are satisfied
• Most real-world database transactions are formed by two or more
database requests
– The equivalent of a single SQL statement in an application
program or transaction

10.1.1 Evaluating Transaction Results

• Not all transactions update the database


• SQL code represents a transaction because database was accessed
• Improper or incomplete transactions can have a devastating effect
on database integrity
– Some DBMSs provide means by which user can define
enforceable constraints based on business rules
– Other integrity rules are enforced automatically by the DBMS
when table structures are properly defined, thereby letting the
DBMS validate some transactions

10.1.2 Transaction Properties

Created By: Mithil Makwana (TYBCA) Page 30 of 43


Mithil 9510374124 http://tybca.110mb.com

• Atomicity
– Requires that all operations (SQL requests) of a transaction be
completed
• Durability
– Indicates permanence of database’s consistent state
• Serializability
– Ensures that the concurrent execution of several transactions
yields consistent results
• Isolation
– Data used during execution of a transaction cannot be used
by second transaction until first one is completed

10.1.3 Transaction Management With SQL

• ANSI has defined standards that govern SQL database transactions


• Transaction support is provided by two SQL statements: COMMIT
and ROLLBACK
• ANSI standards require that, when a transaction sequence is
initiated by a user or an application program,
- it must continue through all succeeding SQL statements
until one of four events occurs

10.1.4 The Transaction Log

• Stores
– A record for the beginning of transaction
– For each transaction component (SQL statement)
• Type of operation being performed (update, delete, insert)
• Names of objects affected by the transaction (the name of
the table)
• “Before” and “after” values for updated fields
• Pointers to previous and next transaction log entries for the
same transaction
– The ending (COMMIT) of the transaction

10.2 Concurrency Control


Created By: Mithil Makwana (TYBCA) Page 31 of 43
Mithil 9510374124 http://tybca.110mb.com

– Important  simultaneous execution of transactions over a


shared database can create several data integrity and
consistency problems
• lost updates









• uncommitted data











• inconsistent retrievals

• The Scheduler

• Special DBMS program: establishes order of operations


within which concurrent transactions are executed
Created By: Mithil Makwana (TYBCA) Page 32 of 43
Mithil 9510374124 http://tybca.110mb.com
• Interleaves the execution of database operations to ensure
serializability and isolation of transactions
• Bases its actions on concurrency control algorithms
• Ensures computer’s central processing unit (CPU) is used
efficiently
• Facilitates data isolation to ensure that two transactions do
not update the same data element at the same time

10.3 Concurrency Control with Locking Methods

• Lock
– Guarantees exclusive use of a data item to a current
transaction
– Required to prevent another transaction from reading
inconsistent data
• Lock manager
– Responsible for assigning and policing the locks used by the
transactions

10.3.1 Lock Granularity

• Indicates the level of lock use


• Locking can take place at the following levels:
– Database
– Table
– Page
– Row
– Field (attribute)
• Database-level lock
– Entire database is locked
• Table-level lock
– Entire table is locked
• Page-level lock
– Entire diskpage is locked
• Row-level lock
– Allows concurrent transactions to access different rows of the
same table, even if the rows are located on the same page
• Field-level lock
– Allows concurrent transactions to access the same row, as
long as they require the use of different fields (attributes)
within that row

• A Database-Level Locking Sequence

Created By: Mithil Makwana (TYBCA) Page 33 of 43


Mithil 9510374124 http://tybca.110mb.com

• An Example of a Table-Level Lock

• An Example of a Page-Level Lock

• Example of Row-Level Lock

Created By: Mithil Makwana (TYBCA) Page 34 of 43


Mithil 9510374124 http://tybca.110mb.com

F
f
g
h

10.3.2 Lock Types

• Binary lock
– Has only two states: locked (1) or unlocked (0)
• Exclusive lock
– Access is specifically reserved for the transaction that locked
the object
– Must be used when the potential for conflict exists
• Shared lock
– Concurrent transactions are granted Read access on the basis
of a common lock

10.3.3 Two-Phase Locking to Ensure Serializability

Created By: Mithil Makwana (TYBCA) Page 35 of 43


Mithil 9510374124 http://tybca.110mb.com
• Defines how transactions acquire and relinquish locks
• Guarantees serializability, but it does not prevent deadlocks
– Growing phase, in which a transaction acquires all the
required locks without unlocking any data
– Shrinking phase, in which a transaction releases all locks and
cannot obtain any new lock
• Governed by the following rules:
– Two transactions cannot have conflicting locks
– No unlock operation can precede a lock operation in the same
transaction
– No data are affected until all locks are obtained—that is, until
the transaction is in its locked point

10.3.4 Deadlocks

• Condition that occurs when two transactions wait for each other to
unlock data
• Possible only if one of the transactions wants to obtain an exclusive
lock on a data item
– No deadlock condition can exist among shared locks
• Control through
– Prevention
– Detection
– Avoidance

Created By: Mithil Makwana (TYBCA) Page 36 of 43


Mithil 9510374124 http://tybca.110mb.com

10.4 Concurrency Control with Time Stamping Methods

• Assigns a global unique time stamp to each transaction


• Produces an explicit order in which transactions are submitted to
the DBMS
• Uniqueness
– Ensures that no equal time stamp values can exist
• Monotonicity
– Ensures that time stamp values always increase

10.4.1 Wait/Die and Wound/Wait Schemes

• Wait/die
– Older transaction waits and the younger is rolled back and
rescheduled
• Wound/wait
– Older transaction rolls back the younger transaction and
reschedules it

10.5 Concurrency Control with Optimistic Methods

• Optimistic approach

Created By: Mithil Makwana (TYBCA) Page 37 of 43


Mithil 9510374124 http://tybca.110mb.com
– Based on the assumption that the majority of database
operations do not conflict
– Does not require locking or time stamping techniques
– Transaction is executed without restrictions until it is
committed
– Phases are read, validation, and write

10.6 Database Recovery Management

• Database recovery
– Restores database from a given state, usually inconsistent, to
a previously consistent state
– Based on the atomic transaction property
• All portions of the transaction must be treated as a
single logical unit of work, in which all operations must
be applied and completed to produce a consistent
database
– If transaction operation cannot be completed, transaction
must be aborted, and any changes to the database must be
rolled back (undone)

10.6.1 Transaction Recovery

• Makes use of deferred-write and write-through


• Deferred write
– Transaction operations do not immediately update the
physical database
– Only the transaction log is updated
– Database is physically updated only after the transaction
reaches its commit point using the transaction log information
• Write-through
– Database is immediately updated by transaction operations
during the transaction’s execution, even before the
transaction reaches its commit point

Created By: Mithil Makwana (TYBCA) Page 38 of 43


Mithil 9510374124 http://tybca.110mb.com

Created By: Mithil Makwana (TYBCA) Page 39 of 43


Mithil 9510374124 http://tybca.110mb.com
Chapter: 12 Distributed Database Management Systems

In this chapter, you will learn

• What a distributed database management system (DDBMS) is and


what its components are
• How database implementation is affected by different levels of data
and process distribution
• How transactions are managed in a distributed database
environment
• How database design is affected by the distributed database
environment

12.1 The Evolution of Distributed Database Management Systems

• Distributed database management system (DDBMS)


– Governs storage and processing of logically related data over
interconnected computer systems in which both data and
processing functions are distributed among several sites
• Centralized database required that corporate data be stored in a
single central site
• Dynamic business environment and centralized database’s
shortcomings spawned a demand for applications based on data
access from different sources at multiple locations

12.2 DDBMS Advantages and Disadvantages


Created By: Mithil Makwana (TYBCA) Page 40 of 43
Mithil 9510374124 http://tybca.110mb.com

Advantages

• Data are located near “greatest demand” site


• Faster data access
• Faster data processing
• Growth facilitation
• Improved communications
• Reduced operating costs
• User-friendly interface
• Less danger of a single-point failure
• Processor independence

Disadvantages

• Complexity of management and control


• Security
• Lack of standards
• Increased storage requirements
• Greater difficulty in managing the data environment
• Increased training cost

12.3 Distributed Processing and Distributed Database

Created By: Mithil Makwana (TYBCA) Page 41 of 43


Mithil 9510374124 http://tybca.110mb.com
12.4 Characteristics of Distributed Management Systems

• Application interface
• Validation
• Transformation
• Query optimization
• Mapping
• I/O interface
• Formatting
• Security
• Backup and recovery
• DB administration
• Concurrency control
• Transaction management
• Must perform all the functions of a centralized DBMS
• Must handle all necessary functions imposed by the distribution of
data and processing
• Must perform these additional functions transparently to the end
user

12.4 DDBMS Components

• Mustinclude (at least) the following components:


– Computer workstations
– Network hardware and software
– Communications media
– Transaction processor (or, application processor, or
transaction manager)
• Software component found in each computer that
requests data
– Data processor or data manager

Created By: Mithil Makwana (TYBCA) Page 42 of 43


Mithil 9510374124 http://tybca.110mb.com
• Software component residing on each computer that
stores and retrieves data located at the site
• May be a centralized DBMS

Created By: Mithil Makwana (TYBCA) Page 43 of 43

You might also like