SQL Normalization

Normalization:
Normalization is a process that helps database designers  to design the table
structure for an application. The main concept of normalization is to reduce
redundant table data to the very minimum.
By normalization process, collection of data in a single table table is replaced,
by distributing the same data over multiple tables with a very specific relationship
between those tables.
Though it has disadvantage, when we apply the process of normalization to any
table, it takes much longer time to perform a query and retrive the data from
group of table. 


There are many forms of normalization, three of them are as follows: 
1. First Normal Form:
When table is decomposed into two-dimensional tables with all repeating
groups of data eliminated, the table is said to be in its first normal form.
Lets uderstand this by an example:
Table : EmpProj
Field
Key
Type
Project No.
- -

Project Name
- - 

Employee No.
- - 
1-n
Employee Name
- - 
1-n
Rate Catagory
- - 
1-n
Hourly Rate
- -
1-n
Data held in above table structure:
NO.
Project Name
ENO.
Name 
Rate 
Fee
P001
Using MsSQL
E001
Chaitanya
B
7500
P002
Using MsSQL
E002
Jayesh
C
7000
P003
Using Star Office
E003
Shubham
A
8000
P004
Using MsSQL
E004
Mayur
B
7500
P005
Using Star Office
E005
Aritro
C
7000


A table is in first normal form if:
There are no repeating groups.
All the key attributes are defined.
All attributes are dependent on a primary key.


To convert a table to its First Normal Form :
1. The unnormalized data in the first table is the entire table.
2. A key that will uniquely identify each record should be assigned to the table.
This key has to be unique because it shoule be capable of identifying any specific
row from table. This key is called Primary key.
Table: EmpPro
Field
Key
Project No.
Primary key
Project Name
- - 
Employee No.
Primary key
Employee Name
- -
Rate category
- - 
Hourly Rate
- - 
This table is now in first normal form.


2. Second Normal Form :

SQL
Introduction:
SQL is a language used to operate databases; it includes database creation,
deletion, modifying rows, etc.
SQL is Structured Query Language, which is a computer language for storing,
manipulating and retrieving data stored in database.
SQL is a ANSI (American National Standards Institute) standard language,
but there are many versions of the SQL language.
Systems like MySQL, Ms-Access, Oracle, Sybase and SQl Servers use SQL
as their standard database language.


Why SQL ?
  • Allows users to access data in the relational database management systems.
  • Allows users to describe the data.
  • Allows users to define the data in a database and manipulate that data.
  • Allows to embed within other languages using SQL modules,
libraries & pre-compilers.
  • Allows users to create and drop databases and tables.
  • Allows users to create view, stored procedure, functions in a database.
  • Allows users to set permissions on tables, procedures and views.
SQL Delimiters :
SQL delimiters are symbols, which have special meanig within SQL and
PL/SQL statements.

+
Addition
Quote identifier
-
Substraction
:
Host variable
*
Multiplication
**
Exponential
/
Division
<> != ^=
Ralational
()
Expression or list
:=
Assignment
;
terminator


%
Attribute indicator
||
Concatination
,
Item seperator
<<
Lebel
.
Component selector
>>
Lebel
@
Remote access indicator
--
Comment
Character string delimeter 
/* */
Comment (Multi line)

No comments:

Post a Comment