3.2. Quick Start GuideThis section is a quick start guide to loading the sample winestore database and understanding the design of the winestore database that is used in examples throughout this book. 3.2.1. Loading the Winestore DatabaseA local copy of the winestore database is required to test the examples in this and later chapters. MySQL must be installed and configured before the winestore database can be loaded. MySQL installation instructions can be found in Appendix A. The steps to load the winestore database are as follows:
The winestore database has now been loaded and tested. 3.2.2. The Winestore DatabaseTo complete the introduction to the winestore database, we include in this section a summary of the entity-relationship model of the winestore and the SQL statements that create the winestore using the MySQL DBMS. This section is included for easy reference. 3.2.2.1. The winestore entity-relationship modelFigure 3-3 shows the completed entity-relationship model for the online winestore derived from the system requirements listed in Chapter 1. Appendix C includes a description of the meaning of each shape and line type used in the figure. Figure 3-3. The winestore ER modelThe winestore model can be summarized as follows:
3.2.2.2. Creating the winestore with SQLThe CREATE TABLE SQL statements that build the winestore database are shown for reference in Example 3-1. The statements in Example 3-1 are derived from the entity-relationship model in Figure 3-1, and the process of converting this model to CREATE TABLE statements is described in Appendix C. An electronic copy of the statements can be found in the winestore.database file used to create the winestore database earlier in this section. Example 3-1. The complete winestore DDL statementsCREATE TABLE wine ( wine_id int(5) DEFAULT '0' NOT NULL auto_increment, wine_name varchar(50) DEFAULT '' NOT NULL, winery_id int(4), type varchar(10) DEFAULT '' NOT NULL, year int(4) DEFAULT '0' NOT NULL, description blob, PRIMARY KEY (wine_id), KEY name (wine_name) KEY winery (winery_id) ); CREATE TABLE winery ( winery_id int(4) DEFAULT '0' NOT NULL auto_increment, winery_name varchar(100) DEFAULT '' NOT NULL, region_id int(4), description blob, phone varchar(15), fax varchar(15), PRIMARY KEY (winery_id), KEY name (winery_name) KEY region (region_id) ); CREATE TABLE region ( region_id int(4) DEFAULT '0' NOT NULL auto_increment, region_name varchar(100) DEFAULT '' NOT NULL, description blob, map mediumblob, PRIMARY KEY (region_id), KEY region (region_name) ); CREATE TABLE customer ( cust_id int(5) NOT NULL auto_increment, surname varchar(50) NOT NULL, firstname varchar(50) NOT NULL, initial char(1), title varchar(10), addressline1 varchar(50) NOT NULL, addressline2 varchar(50), addressline3 varchar(50), city varchar(20) NOT NULL, state varchar(20), zipcode varchar(5), country varchar(20), phone varchar(15), fax varchar(15), email varchar(30) NOT NULL, birth_date date( ), salary int(7), PRIMARY KEY (cust_id), KEY names (surname,firstname) ); CREATE TABLE users ( cust_id int(4) DEFAULT '0' NOT NULL, user_name varchar(50) DEFAULT '' NOT NULL, password varchar(15) DEFAULT '' NOT NULL, PRIMARY KEY (user_name), KEY password (password) ); CREATE TABLE grape_variety ( variety_id int(3), variety_name varchar(20), PRIMARY KEY (variety_id), KEY var (variety) ); CREATE TABLE inventory ( wine_id int(5) DEFAULT '0' NOT NULL, inventory_id int(3) NOT NULL, on_hand int(5) NOT NULL, cost float(5,2) NOT NULL, case_cost float(5,2) NOT NULL, dateadded timestamp(12) DEFAULT NULL, PRIMARY KEY (wine_id,inventory_id) ); CREATE TABLE orders ( cust_id int(5) DEFAULT '0' NOT NULL, order_id int(5) DEFAULT '0' NOT NULL, date timestamp(12), discount float(3,1) DEFAULT '0.0', delivery float(4,2) DEFAULT '0.00', note varchar(120), PRIMARY KEY (cust_id,order_no) ); CREATE TABLE items ( cust_id int(5) DEFAULT '0' NOT NULL, order_id int(5) DEFAULT '0' NOT NULL, item_id int(3) DEFAULT '1' NOT NULL, wine_id int(4) DEFAULT '0' NOT NULL qty int(3), price float(5,2), date timestamp(12), PRIMARY KEY (cust_id,order_no,item_id) ); CREATE TABLE wine_variety ( wine_id int(5) DEFAULT '0' NOT NULL, variety_id int(3) DEFAULT '0' NOT NULL, id int(1) DEFAULT '0' NOT NULL, PRIMARY KEY (wine_id, variety_id) ); Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|