In a relational database, data is stored in tables. Each table contains data about a particular type of entity (either physical or conceptual).
For instance, our sample database is the inventory and sales system for Acme Widget Co. It has tables containing data for the following entities:
Table 2-1. Acme Widget Co Tables
Table | Description |
---|---|
stock_item | Inventory items |
customer | Customer account details |
saleperson | Sales people working for Acme Widget Co. |
sales | Sales events which occur |
Tables in a database contain fields and records. Each record describes one entity. Each field describes a single item of data for that entity. You can think of it like a spreadsheet, with the rows being the records and the columns being the fields, thus:
Table 2-2. Sample table
ID number | Description | Price | Quantity in stock |
---|---|---|---|
1 | widget | $9.95 | 12 |
2 | gadget | $3.27 | 20 |
Every table must have a \emph{primary key}, which is a field which uniquely identifies the record. In the example above, the Stock ID number is the primary key.
The following figures show the tables used in our database, along with their field names and primary keys (in bold type).
Table 2-3. the stock_item table
stock_item |
---|
id |
description |
price |
quantity |
Table 2-4. the customer table
customer |
---|
id |
name |
address |
suburb |
state |
postcode |
Table 2-5. the salesperson table
salesperson |
---|
id |
name |
Table 2-6. the sales table
sales |
---|
id |
sale_date |
salesperson_id |
customer_id |
stock_item_id |
quantity |
price |