Sie sind auf Seite 1von 9

Normalization

In this blog I will Explain what are the different forms of normalizations, Rather than knowing what is normalization , we start with how we come upto the concept of Normalization .How practical scenario make E.F.CODD to think and in the process of solving the issue ,how he comes with the concept of normalization .We assume now that we dont know anything about normalization . Suppose I own a shop name ABC ELECTRONIC SHOP ,I want a webpage that is linked with database ,so I hired a front end designer and E.F.CODD for backend designing. I ask my front end designer for a page with my specifications that I need a page having Order Number ,Order date ,Customer Name ,Customer Address ,Customer Phone Number ,Items (to be selected from drop down list ),and the Amount and he gives me the design as below .

I am satisfied with the design ,so I called E.F CODD and asked him to create database for the same ,so he comes with the database table order_customer having all the columns as shown in the above screenshot. The screenshot for the database is given below. ORDER_CUSTOMER

Things are working perfectly for me whenever a customer came and buy any item, then the record get inserted into the table . One day a customer came and asked me for Refrigerator & TV ,so I have no other choice and I created two orders for him one for refrigerator and other for TV and different amount for both items ,so I manually did addition for the items because I have no other choice. But one thing stuck me that customer may have more than one item to be placed in particular order,then I called E.F.CODD to cater my situation ,he tells me I will add two more column in order_customer table i.e item2 and amount 2 and rename the above Item to Item1 and Amount to Amount1.

And the same changes be done on database table order_customer,and I am very happy with it whenever the customer came if it ask for one item I simply fill the Item1 and Amount1 column and this will cater my situation. Then one day a newly married couple came to my shop and asked me for various items since they are settling there house. They want lot more things rather than just two items like refrigerator ,AC,TVetc,So I was confused how many orders should I create. I am confused that everytime I have to call E.F.CODD and asked him to create new column in the table.I called CODD and discuss my situation to him ,he tell me that he need to change certain database design to cater this and need some time to think. The solution that E.F.CODD came with is like that He said he will keep all the things together that are not repeating in one table and repeating things in another table confused ,please see the below screenshot

So ,whenever an order has been placed one entry for that order is been created into orders_masters table ,see the screenshot below ORDERS_MASTERS

And its corresponding entries for that order_no are inserted into another table called ORDER_details ORDER_DETAILS

This table is not limited by the number of items,we can put as many records as we want under same order_no . This Removing the repeating groups(the group enclosed with green border in above screenshot) and presenting in a more atomic into another table(order_details in our case) is called FIRST NORMAL FORM. This is how E.F.CODD solved my problem and discovered FIRST NORMAL FORM. Now According to that I have changed my screen, now I select an item and the items got populated in the list below and when I am finished selecting all the items that the customer wants ,I press submit button , one entry for order_no ,order_date,customer_name,customer_address and customer_phone goes to order_masters table and for that order no the items purchased is been picked from the below table into order_details table and this caters my problem, see the screenshot below:

One day again another customer came to me and asked me for 2 refrigerator and 3 TV ,now again what I need to do ,For the same order_no I select refrigerator twice and TV thrice, then I thought of putting another field in my screen i.e Quantity. And since quantity field is repeating ,so I have added one more column to the order_details table.

Since my store is becoming large and large and my business is expanding, thats why variety of items increasing at my store , initially it was 5 and then 100 and one time I have 1000 of product and thats why I figured out that I cant remember all of this ,I added another field to my screen Item_no and its item_name,and if the customer is valuable I can offer him discount .So another field called discount is added to the screen as well as the order details table Eg: Suppose item no 1 is having item name whirpool washing machine .

Since Item No ,Item_name ,discount is also repeating item ,so another new column is also added to the table order_details Order_details

Now ,what I need to do ,is to implement a logic so that I need not to put the amount(unit amount) for every product manually . As soon as I select item ,the system will automatically takes out the amount for me for that product . So what I did I put dummy data into the order_masters and order_details table .In order to distinguish the dummy data from the original data in the tables ,I put negative order number for each product, since I know that order_no for my product can never be negative. I put an option of creating a dummy data into the table from the screen as given below:

So ,the order_master and order_details will be populated as below screenshot: ORDER_MASTERS

ORDER_DETAILS

So,for every new product I create a dummy record from the front end having negative order_no ,and hence I am able to fetch the amount for the item when I am creating order for the customer. So In this what will happen suppose when a customer need a refrigerator ,I wont need to put the item amount manually ,it will first look to the dummy data into the order_details table for item_no

and item_name having negative order_no and the amount will be fetched automatically from the database into the front end ,this lessen my overhead to manually put the data into amount field. Now, because of that I need to tell my developer esp not to consider negative orders when calculating sales tax or any other calculation for generating Reports .And this thing is creating overhead and performance of the database get degraded because of that .So, I again called E.F.CODD and I explain what I did to cater my need here. E.F.CODD said you showed some skills over here but what your effectively doing is that you want a piece of information that is not dependent on order_no and its hidden somewhere inside order_no inside your database,So for that you are inserting dummy data into tables . You are trying to store value that is not fully dependent on order_no and its a fundamental mistake , so for that create another table called item_master. Here Item_no will be the first column ,Item_name ..why Item_name its because it is not fully dependent on order_no and item_no combination, it is only dependent on item_no ,no matter what my order_no is ? whenever I chose item_no 1 it comes with refrigerator ,so item name is fully dependent on item_no. Unit Amount aka Amount is also not dependent on order_no and item_no ,whenever I chose item_no it fetches me its amount regardless of the order_no. Whats gona change is the quantity which depends on the order_no and the item_no and the discount also dependent on order_no which depends on the customer goodwill. Here in this diagram below ,the new table Item_masters is been created and the columns that are not fully dependent on order_no and item_no is removed from the order_details table

So ,no garbage data present here now no hiding data in form of dummy data, In order to put database into second Normal database ,when we have formed an entity from the first normal form which had a concatened key(Order_no,item_no) just check all the element on that entity is fully dependent on that concatenated key ,and if they are not fully dependent then segregate them from that entity into another entity (Item_masters).This is what we called as Second Nornal Form.

Now, In order to save confusion where two customer having the same name ,I create another field in GUI Customer_no .Now since it is static part ,so I added the same column in the order_masters table . Now what I learnt from my business is that customer came to enquire about items and all of the them cannot be converted into orders. There may be various reason like that I am out of stock , may be the prices are too high for the customer to buy. But for me to really grow I should always be ready to track of the customer who enquire about items , and thats how I will become more closer to the customer wherever something positive come in the market ,like the price become less ,discount scheme came to the market .So for that I will keep a track of the customers who enquire about my items .So,where possible I send promotion to them in order to have a long term relationship with the customers . So again an idea came to my mind how can I use my database to keep track of the customers details like customer name, customer address, customer phone number. So Again thought came to my mind create dummy orders ,suppose a customer is not buying ,but he enquire about the product ,so I utilize my application to create dummy orders for a customer ,if I tried this application to convert the information into wrappers that can fit into this schema(current database objects) but later I realize from E.F.CODDs discussion that I must not try to create wrappers into my schema . So again thought came into my mind that remove customer_name,customer_details and customer_phone_no that are dependent on customer number into separate table customer_masters Customer_masters

Order_masters

So now the screen will be changed and I ll put only customer_no and a searchable buttom which looks into the customer_masters table for customer_name,customer_address,customer_phone_no and a new screen is made which is used to insert customers details into customer_masters table.

So, this is how I convert my system into 3rd Normal form which states that if there any non key attribute (customer_name,customer_address,customer_phone_no) fully dependent on another non key attribute (customer_no) ,then you should create new entity (customer_master) to store them and we link customer_masters to order_masters with common key (customer_no) which is a foreign key in the order_masters which means that order_masters will only have those customers which are specified in the customer_masters.

Das könnte Ihnen auch gefallen