|
|
Graduated questions
ER diagram for the Dressmaker database:
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:
|
---|
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 ,line_no INTEGER NOT NULL ,ol_style INTEGER REFERENCES garment ,ol_size INTEGER NOT NULL ,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: |
---|