A Gentle Introduction to


Pick an engine:

Dressmaker database

Graduated questions

ER diagram for the Dressmaker database:

Entity relation diagram er4

SQL Source for the database

Some sample queries

0a The "central" table in this database is order_line - every garment ordered takes one line in this table. Many of the fields in this table are references to other tables. The fields of this table have the following meaning:
This is a link to the dress_order table. We can join the dress_order table to find information such as the the date of the order and the customer number for a given garment order.
The line number is used to distinguish different items on the same order - for example order number 5 has three lines - 1, 2 and 3.
Indicates the article of clothing ordered. For example ol_style 1 indicates trousers - we can see this by joining to the garments table. Line 1 in the garment table is trousers.
The size of the item ordered is given here - this is particularly important when it comes to working out how much material is required to build the item. We can see from the quantities table that trousers (style 1) in size 8 takes 2.7 meters - whereas trousers in size 12 needs 2.8 meters.
Each order specifies the material to be used. We can join to the material table to find a description or cost per meter. Material 1 is Silk, Black, Plain costing £7 per meter.

0b A sample join:

In order to translate the numbers in order_line into meaningful values we need to join a related table. For example if we want to access the descriptions of the materials we need to join the material table.

To achieve the join we include the table material on the FROM line and the join condition as a WHERE clause.

For each pair of tables there is a join condition between them (if they are linked). To find the join condition between order_line and material we look at the order_line table CREATE statement and notice the line that specifies that ol_material references the material table. This link will always be to the primary key of material table.

CREATE TABLE order_line (
  order_ref	INTEGER	NOT NULL REFERENCES dress_order
 ,ol_style	INTEGER	REFERENCES garment
 ,ol_material	INTEGER	REFERENCES material
 ,PRIMARY KEY (order_ref, line_no)
 ,FOREIGN KEY (ol_style, ol_size) REFERENCES quantities

0c To get a description of the garment we need to join the garment table. The join condition is that the ol_style in order_line matches the style_no in garment.

0d If we need both the description and the fabric we can join both material and garment to the order_line table. The join conditions are combined with "AND"

0e The quantities table tells us how much material is required for every garment for every size available. The join between the order_line and quantities is unusual in that it involves two fields. This can be seen by the fact that quantities has a composite key.

0f Customers place orders - each order contains many lines - each line of the order grefers to a garment: