Datasheet

Databases also fall into the category of complex files. When using Microsoft Access, you have an MDB
file – this is a database file, but from the file itself you can't tell anything about the data inside. You need
some way to get to the data, either using something such as Microsoft Access itself, or as we are going to
do, using the .NET data classes.
Before you can access the data, you need to know how it is stored internally.
Tables
Within a database, data is stored in tables – these are the key to all databases. A table is like a
spreadsheet, with rows and columns. You generally have multiple tables for multiple things – each
distinct type of data is stored separately, and tables are often linked together.
Let's look at an example to make it easier to visualize. Consider an ordering system, for example, where
you store details of customers and the goods they've ordered. The following table shows rows of
customer orders, with columns (or fields as they are sometimes called in database terms) for each piece of
order information:
Customer Address Order Date Order Item Quantity Item Cost
John 15 High Street 01/07/2003 Widget 10 3.50
Brumingham
England
John 15 High Street 01/07/2003 Doodad 5 2.95
Brumingham
England
John 15 High Street 01/08/2003 Thingy 1 15.98
Brumingham
England
Chris 25 Easterly Way 01/08/2003 Widget 1 3.50
Cradiff Wales
Dave 2 Middle Lane 01/09/2003 Doodad 2 2.95
Oxborough
England
Dave 3 Middle Lane 01/09/2003 Thingamajig 1 8.50
Oxborough
England
This is the sort of thing you'd see in a spreadsheet, but there are a couple of big problems with this. For a
start, we have repeated information. John, for example, has his address shown thrice. What happens if
he moves house? You'd have to change the address everywhere it occurs. Dave has two addresses, but
notice they are slightly different. Which one is correct? Are neither correct?
250
Chapter 8
57076_Ch 8 SAN.qxd 01/12/2003 6:43 PM Page 250