Accessibility

Table of Contents

Displaying database data on a web page

What is a relational database?

Databases provide an efficient way of storing and retrieving information. Databases store groups of similar information in tables. In this example, the table name is "Product." Each column in the table contains a type of data. The columns are "Name," "Description," and "Price." The table consists of rows of data, or values, which populate the columns. The first row in this example contains information about a Baseball Wall Shelf. In the "Product" table below, product information is stored together as a catalog of products for sale.

Product
Name Description Price
Baseball Wall Shelf Wall shelf. Handcrafted solid wood construction with painted green field background. Melamine-covered shelves. 30"x8"x24" USA. 20.7 lbs. 69.99
Sports Ball Bean Bag 100% vinyl shell filled with polyethylene/polystyrene pellets. 80" round. USA. 12.7 lbs. 39.99
Triple Play Table Lamp Table lamp. Three mini bats and an attached baseball on a wood base; shirred linen-over-styrene shade. Uses 100 Watt bulb, max. 21" high. 8.2 lbs. 79.99

Any bit of data in the table above could be the same for more than one product. This would make it difficult to specify and retrieve information on a particular product in the database. Therefore, relational databases are designed to provide each row in every table with a unique identifier called a primary key. The primary key might be a column or set of columns in the table that contains unique data for each row. If there is no such identifier defined, you can add a column to hold a unique numerical identifier for the row. In the example below, we have added the ProductID column as the primary key column.

Product
ProductID Name Description Price
100 Baseball Wall Shelf Wall shelf. Handcrafted solid wood construction with painted green field background. Melamine-covered shelves. 30"x8"x24" USA. 20.7 lbs. 69.99
101 Sports Ball Bean Bag 100% vinyl shell filled with polyethylene/polystyrene pellets. 80" round. USA. 12.7 lbs. 39.99
102 Triple Play Table Lamp Table lamp. Three mini bats and an attached baseball on a wood base; shirred linen-over-styrene shade. Uses 100 Watt bulb, max. 21" high. 8.2 lbs. 79.99

It would be inefficient to store all of a product's information when a customer places an order, because it would mean storing redundant information in both the Product table and an Order table. The "relational" in relational databases addresses this problem by organizing data into related tables. In the example shown in Figure 1, you would store only the ProductID and OrderID in the Item table. ProductID is a pointer to the appropriate product in the Product table, and OrderID is a pointer to the appropriate order information in the Order table. Figure 1 shows the order information separated into three tables: Order, Item, and Product table.

Organized order information

Figure 1. Organized order information