Вы находитесь на странице: 1из 23

NORMALIZATIO

N
1 , 2 , and 3
st nd rd

BY
SYEDA RABIA KAZIM
Overview
◦ Database Normalization
◦ Data Anomalies Caused by:
◦ Update, Insertion, Deletion
◦ 1st Normal Form
◦ 2nd Normal Form
◦ 3rd Normal Form
◦ Conclusion
Database Normalization
The main goal of Database Normalization is to restructure the logical
data model of a database to:
Eliminate redundancy
Organize data efficiently
Reduce the potential for data anomalies.
Data Anomalies
Data anomalies are inconsistencies in the data stored
in a database as a result of an operation such as update,
insertion, and/or deletion.
Such inconsistencies may arise when have a particular
record stored in multiple locations and not all of the
copies are updated.
We can prevent such anomalies by implementing 7
different level of normalization called Normal Forms
(NF)
Brief History/Overview
Codd defined the first three Normal Forms, which
we’ll look into, of the 7 known Normal Forms.

In order to do normalization we must know what the


requirements are for each of the three Normal Forms
that we’ll go over.

One of the key requirements to remember is that


Normal Forms are progressive. That is, in order to have
3rd NF we must have 2nd NF and in order to have 2nd NF
we must have 1st NF.
1st Normal Form
The Requirements
The requirements to satisfy the 1st NF:
◦ Each table has a primary key: minimal set of attributes
which can uniquely identify a record
◦ The values in each column of a table are atomic (No
multi-value attributes allowed).
◦ There are no repeating groups: two columns do not store
similar information in the same table.
1st Normal Form
Example
Un-normalized Students table:
Student# AdvID AdvName AdvRoom Class1 Class2

123 123A James 555 102-8 104-9

124 123B Smith 467 209-0 102-8

Normalized Students table:


Student# AdvID AdvName AdvRoom Class#

123 123A James 555 102-8

123 123A James 555 104-9

124 123B Smith 467 209-0

124 123B Smith 467 102-8


2nd Normal Form
The Requirements
The requirements to satisfy the 2nd NF:
◦ All requirements for 1st NF must be met.
◦ Redundant data across multiple rows of a table must be
moved to a separate table.
◦ The resulting tables must be related to each other by
use of foreign key.
2nd Normal Form
Example
Students table

Student# AdvID AdvName AdvRoom


123 123A James 555
124 123B Smith 467
Student# Class#
Registration table 123 102-8
123 104-9
124 209-0
124 102-8
3rd Normal Form
The Requirements
The requirements to satisfy the 3rd NF:
◦ All requirements for 2nd NF must be met.
◦ Eliminate fields that do not depend on the primary key;
◦ That is, any field that is dependent not only on the
primary key but also on another field must be moved to
another table.
3rd Normal Form
Example
Students table:

Student# AdvID AdvName AdvRoom


123 123A James 555
124 123B Smith 467
Student table: Advisor table:
AdvID AdvName AdvRoom
Student# AdvID
123A James 555
123 123A
123B Smith 467
124 123B
3rd Normal Form
Example Cont.
Student# AdvID
123 123A
124 123B

Registration table: Advisor table:


Student# Class#
AdvID AdvName AdvRoom
123 102-8
123A James 555
123 104-9
123B Smith 467
124 209-0
124 102-8
Why SQL?
1. Allows users to access data in the relational database management systems.
2. Allows users to describe the data.
3. Allows users to define the data in a database and manipulate that data.
4. Allows to embed within other languages using SQL modules, libraries & pre-
compilers.
5. Allows users to create and drop databases and tables.
6. Allows users to create view, stored procedure, functions in a database.
7. Allows users to set permissions on tables, procedures and views.
SQL Process /SQL
Architecture
Parser: When an application issues
a SQL statement, the application
makes a parse call to Database.
During the parse call, Database
Checks the statement for syntactic
and semantic validity.
Optimizer: Query optimization is
the overall process of choosing the
most efficient means of executing
a SQL statement. SQL is a
nonprocedural language, so the
optimizer is free to merge,
reorganize, and process in any order.
SQL Commands
The standard SQL commands to interact with relational databases are
CREATE
SELECT
INSERT
UPDATE
DELETE
DROP.
These commands can be classified into the following groups based on their
nature :
DDL - Data Definition
Language
Command Description
CREATE Creates a new table, a view of a
table, or other object in the
database.

ALTER Modifies an existing database object,


such as a table.
Deletes an entire table, a view of a
DROP
table or other objects in the
database.
TRUNCATE Removes all rows from the table,
leaving the table empty and table
structure intact.
DML - Data Manipulation
Language
Commands Descriptions
SELECT Retrieves certain records from one
or more tables.

INSERT Creates a record.

UPDATE Modifies records.

DELETE Deletes records.

MERGE UPSERT operation (insert/update)


Update if rows exists, insert of they
don’t.
Truncate vs Delete
DCL - Data Control
Language
Commands Descriptions

GRANT Gives a privilege to user.

Takes back privileges


REVOKE granted from user.
Transaction Control
Commands Description

COMMIT All changes are permanently


recorded within the database.

ROLLBACK All changes are aborted and the


database is restored to a previous
consistent state.

SAVEPOINT Is a transaction marker.


What is a NULL value?

A NULL value in a table is a value in a field that appears to


be blank, which means a field with a NULL value is a field
with no value.

Difference between zero and Null value?


Writing SQL Statements

Using the following simple rules and guidelines, you can construct valid
statements that are both easy to read and easy to edit:
SQL statements are not case sensitive, unless indicated.
 SQL statements can be entered on one or many lines.
 Keywords cannot be split across lines or abbreviated.
 Clauses are usually placed on separate lines for readability and ease
of editing.
 Indents should be used to make code more readable.
 Keywords typically are entered in uppercase; all other words, such as
table names and columns, are entered in lowercase.
END

Вам также может понравиться