Chapter: 5 Normalization of Database Tables: in This Chapter, You Will Learn
Chapter: 5 Normalization of Database Tables: in This Chapter, You Will Learn
com
• 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
• Structure of data set in Figure 5.1 does not handle data very well
• 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
Decomposition to BCNF
5.8 Denormalization
• Examine the simple database model and the database tables that
will form the basis for the many SQL examples
• Understand the data environment
• 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
• 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
• 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
• 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
• 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
• 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
• INSERT
– Inserts multiple rows from another table (source)
– Uses SELECT sub query
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
• 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
• 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
• 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
. UNION
. UNIONALL
. INTERSECT
. MINUS
. Syntax Alternatives
• 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
• 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
• 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
•
•
•
•
•
•
•
•
• uncommitted data
•
•
•
•
•
•
•
•
•
•
• inconsistent retrievals
• The Scheduler
• 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
F
f
g
h
• 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.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
• 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
• Optimistic approach
• 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)
Advantages
Disadvantages
• 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