A-level Computing 2009/AQA/Problem Solving, Programming, Operating Systems, Databases and Networking/Databases/Entity relationship modelling





Databases will probably store data about a variety of things. For example, if we look at the tables required for an online store:
 * Staff
 * Products
 * Receipts
 * Customers

These tables could sit on their own, but when we start to describe each of them we notice that they are related to each other. For example:
 * The Receipt table records which product a customer has bought, and which date it was purchased on.

This describes the Receipt record, and looking at its structure we see that the primary keys from other tables are included in it. Receipt( CustomerID, ProductID , DateTime , Total, StaffID) In other words we could say: A receipt has one customer A customer can have many receipts A receipt has one product A product can be part of many receipts A receipt was created by one staff member A staff member can create many receipts We can then draw this diagram like so:

To link tables together and allow for us to query a database we use relationships. There are three types of relationship that you need to know. Each is shown below using 'crows foot notation' which is one of many ways to describe these relationships:

An animal has one genome

A genome describes only one animal

A student has many classes

A class has many students

A league has many teams

A team is only in one league


 * A player answers many questions
 * A question can be answered many times
 * Each answer is only applicable to one question
 * A player can give many answers
 * Each answer has only one player contributing

vehicle ---< wheel

Father >--< Child (unless we are talking about biological fathers: Father-----< Owner (even though an Owner may own more than one cat, a cat might have more than one owner)

car --- driver (a car can only be driven by one driver, a driver can only drive one car at one time)

wheel --- unicycle

House >--- Postcode (a house is assign one postcode, but that same postcode might be assigned to many houses)