Planning a relational database
A database differs from a list of data in that a database is made of inter related tables. The different tables are set up so that data is not duplicated.
If there is one list, it will hold all the data of the customers and the products that have been ordered by them with the prices they were sold. As customers order more than once, products are sold repeatedly and more than one item can be ordered on one order, this leads to duplicate data.
To prevent duplication the data needs to be split up into different tables: Customers, Products, Orders and Order Details.
When the data is stored in different tables – there needs to be some way of reconnecting the different tables. The key field is a way of making the connection.
For instance on the Customers table there is a Cust ID field, this uniquely identifies each customer so that on the Orders table it can be used to specify which customer has placed each order. On the customers table each order has a distinct order number, so that the details can be linked to an order.
1. On the table where it uniquely identifies the record the field that makes the connection is known as the primary key.
2. On the table where it makes the connection to, it is known as the foreign key (child).
No comments:
Post a Comment