Why do database designers use relationships to construct a database instead of listing all the records in one location? It would seem easier to have all the information in one place, so why is this the standard?
Expert Answer
The differnt tables in the database are designed for different purposes, hence they are organised in different ways.. means each table will have different kind of primary keys..
Think of customer and orders table.. If Customer C1 has 2 orders in the system, as O1 and O2.. Then currenty they are organised in different tables.. Customer table has customerId as the primary key, while the order table has the primary key as Order Id.. The orders table will have customer Id as foriegn key for finding out to which customer the order belongs to….
1. Now in this situation, its easy to update the name of the customer, we need to go in customer table and update the name..
2. Suppose customer has 2 orders. For updating one particular order, we can go to orders table and find that order by OrderId, and update
=================
Now think in other way when all this data is clubbed into one table itself..
1. Now in a single row itself, the customer information and the order information both are present. So for a single customer’s 100 orders, there will be 100 rows in this table and all the 100 rows will be having duplicate data of customer name, address or phone number etc.. That is totally unacceptable as this increases the db size, as well as in case we need to update some customer name, we need to update it at 100 places instead of 1 place per customer.
2. As there can be only one primary key for the table, and that need to be unique.. as customer name will be duplicated in multiple rows, customer id can not be the primary key..
Morever, databases are used to represent the real life objects.. the real life objects always have some relationship with one another, that is also a major reason towads organising the data similarly.