<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://sqlzoo.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://sqlzoo.net/w/index.php?title=Dressmaker&amp;feed=atom&amp;action=history</id>
		<title>Dressmaker - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://sqlzoo.net/w/index.php?title=Dressmaker&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Dressmaker&amp;action=history"/>
		<updated>2013-05-22T20:56:48Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.4</generator>

	<entry>
		<id>http://sqlzoo.net/w/index.php?title=Dressmaker&amp;diff=1918&amp;oldid=prev</id>
		<title>Connor: Created page with &quot;&lt;h1&gt;Dressmaker database&lt;/h1&gt; &lt;p&gt;Graduated questions&lt;/p&gt; &lt;ul&gt;  &lt;li&gt;Easy questions 1..5&lt;/li&gt;  &lt;li&gt;Medium questions 6..10&lt;/li&gt;  &lt;li&gt;[[...&quot;</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Dressmaker&amp;diff=1918&amp;oldid=prev"/>
				<updated>2012-07-19T14:23:38Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;h1&amp;gt;Dressmaker database&amp;lt;/h1&amp;gt; &amp;lt;p&amp;gt;Graduated questions&amp;lt;/p&amp;gt; &amp;lt;ul&amp;gt;  &amp;lt;li&amp;gt;&lt;a href=&quot;/wiki/Dressmaker_easy&quot; title=&quot;Dressmaker easy&quot;&gt;Easy questions 1..5&lt;/a&gt;&amp;lt;/li&amp;gt;  &amp;lt;li&amp;gt;&lt;a href=&quot;/wiki/Dressmaker_medium&quot; title=&quot;Dressmaker medium&quot;&gt;Medium questions 6..10&lt;/a&gt;&amp;lt;/li&amp;gt;  &amp;lt;li&amp;gt;[[...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;h1&amp;gt;Dressmaker database&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Graduated questions&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;[[Dressmaker easy |Easy questions 1..5]]&amp;lt;/li&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;[[Dressmaker medium |Medium questions 6..10]]&amp;lt;/li&amp;gt;&lt;br /&gt;
 &amp;lt;li&amp;gt;[[Dressmaker hard |Hard questions 11..15]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
ER diagram for the dressmaker database:&lt;br /&gt;
[[Image]]&lt;br /&gt;
&amp;lt;p&amp;gt;[[SQL Source for the database]]&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h2&amp;gt;Some sample queries&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
The &amp;quot;central&amp;quot; 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:&lt;br /&gt;
order_ref&lt;br /&gt;
    &amp;lt;p&amp;gt;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.&amp;lt;/p&amp;gt;&lt;br /&gt;
line_no&lt;br /&gt;
    &amp;lt;p&amp;gt;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.&amp;lt;/p&amp;gt;&lt;br /&gt;
ol_style&lt;br /&gt;
    &amp;lt;p&amp;gt;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.&amp;lt;/p&amp;gt; &lt;br /&gt;
ol_size&lt;br /&gt;
    &amp;lt;p&amp;gt;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.&amp;lt;/p&amp;gt;&lt;br /&gt;
ol_material&lt;br /&gt;
    &amp;lt;p&amp;gt;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.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT order_ref, line_no, ol_style, ol_size, ol_material&lt;br /&gt;
 FROM order_line&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
A sample join:&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To achieve the join we include the table material on the FROM line and the join condition as a WHERE clause.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
 CREATE TABLE order_line (&lt;br /&gt;
   order_ref	INTEGER	NOT NULL REFERENCES dress_order&lt;br /&gt;
  ,line_no	INTEGER	NOT NULL&lt;br /&gt;
  ,ol_style	INTEGER	REFERENCES garment&lt;br /&gt;
  ,ol_size	INTEGER	NOT NULL&lt;br /&gt;
  ,ol_material	INTEGER	REFERENCES material&lt;br /&gt;
  ,PRIMARY KEY (order_ref, line_no)&lt;br /&gt;
  ,FOREIGN KEY (ol_style, ol_size) REFERENCES quantities&lt;br /&gt;
  );&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT order_ref, line_no, fabric, colour, pattern, cost&lt;br /&gt;
  FROM order_line, material&lt;br /&gt;
 WHERE ol_material = material_no&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
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. &lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT order_ref, line_no, description&lt;br /&gt;
  FROM order_line, garment&lt;br /&gt;
 WHERE ol_style = style_no&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
If we need both the description and the fabric we can join both material and garment to the order_line table. &lt;br /&gt;
The join conditions are combined with &amp;quot;AND&amp;quot;  &lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT order_ref, line_no, fabric, description&lt;br /&gt;
  FROM order_line, material, garment&lt;br /&gt;
 WHERE ol_style = style_no&lt;br /&gt;
   AND ol_material = material_no&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
The quantities table tells us how much material is required for every garment for every size available. &lt;br /&gt;
The join between the order_line and quantities is unusual in that it involves two fields. &lt;br /&gt;
This can be seen by the fact that quantities has a composite key. &lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT order_ref, line_no, quantity&lt;br /&gt;
  FROM order_line, quantities&lt;br /&gt;
 WHERE ol_style = style_q&lt;br /&gt;
   AND ol_size  = size_q&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
Customers place orders - each order contains many lines - each line of the order grefers to a garment:&lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT c_name, order_date, order_no, line_no&lt;br /&gt;
   FROM jmcust, dress_order, order_line&lt;br /&gt;
  WHERE          jmcust.c_no = dress_order.cust_no&lt;br /&gt;
  AND   dress_order.order_no = order_line.order_ref&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Connor</name></author>	</entry>

	</feed>