Answer:
Note: - A regular .NET programmer working on projects often stumbles on this question, which is but obvious. The bad part is sometimes the interviewer can take this as a very basic question to be answered and it can be a turning point for the interview. So let's cram it.
It is set of rules that have been established to aid in the design of tables that are meant to be connected through relationships. This set of rules is known as Normalization.
Benefits of Normalizing your database include:
The three normal forms as follows:
In the above example,
In the above table of
That takes our database to a second normal form.
So now the
Note: - A regular .NET programmer working on projects often stumbles on this question, which is but obvious. The bad part is sometimes the interviewer can take this as a very basic question to be answered and it can be a turning point for the interview. So let's cram it.
It is set of rules that have been established to aid in the design of tables that are meant to be connected through relationships. This set of rules is known as Normalization.
Benefits of Normalizing your database include:
- Avoiding repetitive entries
- Reducing required storage space
- Preventing the need to restructure existing tables to accommodate new data
- Increased speed and flexibility of queries, sorts, and summaries
The three normal forms as follows:
First Normal Form
For a table to be in first normal form, data must be broken up into the smallest units possible. In addition to breaking data up into the smallest meaningful values, tables in first normal form should not contain repetitions groups of fields.city1
and city2
are repeating. In order for these tables to be in First normal form, you have to modify the table structure as follows. Also note that the Customer Name is now broken down to first name and last name (First normal form data should be broken down to the smallest unit).
Customer table normalized to first normal form
Second Normal Form
The second normal form states that each field in a multiple field primary key table must be directly related to the entire primary key. In other words, each non-key field should be a fact about all the fields in the primary key.In the above table of
customer
, city
is not linked to any primary field.That takes our database to a second normal form.
Third Normal Form
A non-key field should not depend on another Non-key field. The fieldTotal
is dependent on Unit price
and qty
.Total
field is removed and is the multiplication of Unit price * Qty
.Fourth Normal Form
Note: - Whenever the interviewer is trying to go above the third normal form, there can be two reasons, ego or to fail you. Three normal forms are really enough, practically anything more than that is an overdose.
In fourth normal form, it should not contain two or more independent multi-valued facts about an entity and it should satisfy “Third Normal form”.
So let us try to see what multi-valued facts are. If there are two or more many-to-many relationship in one entity and they tend to come to one place, it is termed as “multi-valued facts”.
Multi-valued facts
Supplier
/ Product
and “Supplier
/ Location
(or in short multi-valued facts). In order for the above example to satisfy the fourth normal form, both the many-to-many relationships should go in different tables.Fifth Normal Form
Note: - UUUHHH if you get this question after joining the company, do ask him if he himself really uses it?
Fifth normal form deals with reconstructing information from smaller pieces of information. These smaller pieces of information can be maintained with less redundancy.
Example:
Dealers
sell Product
which can be manufactured by various Companies
. Dealers
in order to sell the Product
should be registered with the Company
. So these three entities have a mutual relationship within them.JM Associate
can sell sweets under the following two conditions:JM Associate
should be an authorized dealer ofCadbury
Sweets
should be manufactured byCadbury
company
No comments:
Post a Comment