An Introduction to the Database Used in This Book

Team-Fly    

 
Sams Teach Yourself SQL in 24 Hours, Third Edition
By Ronald R. Plew, Ryan K. Stephens
Table of Contents
Hour  1.  Welcome to the World of SQL


Before continuing with your journey through SQL fundamentals, the next step is introducing the tables and data that you use throughout the course of instruction for the next 23 one-hour lessons. The next two sections provide an overview of the specific tables (the database) being used, their relationship to one another, their structure, and examples of the data contained.

Diagram of the Tables in This Book

Figure 1.4 reveals the relationship between the tables that you use for examples, quiz questions, and exercises in this book. Each table is identified by the table name as well as each residing field in the table. Follow the mapping lines to compare the specific tables' relationship through a common field, in most cases referred to as the primary key (discussed in Hour 3).

Figure 1.4. Table relationships for this book.

graphics/01fig04.gif

Table-Naming Standards

Table-naming standards, as well as any standard within a business, are critical to maintaining control. After studying the tables and data in the previous sections, you probably noticed that each table's suffix is _TBL. This is a naming standard selected for use, such as what's been used at various client sites. The _TBL simply tells you that the object is a table; there are many different types of objects in a relational database. For example, you will see that the suffix _INX is used to identify indexes on tables in later hours. Naming standards exist almost exclusively for overall organization and assist immensely in the administration of any relational database. Remember, the use of a suffix is not mandatory when naming database objects.

graphics/note_icon.gif

You should not only adhere to the object-naming syntax of any SQL implementation, but also follow local business rules and create names that are descriptive and related to the data groupings for the business.


A Look at the Data

This section offers a picture of the data contained in each one of the tables used in this book. Take a few minutes and study the data, the variations, and the relationships between the tables and the data itself. Notice that some fields may not require data, which is specified when each table is created in the database.

 EMPLOYEE_TBL  EMP_ID    LAST_NAM FIRST_NA M ADDRESS         CITY         ST ZIP   PHONE --------- -------- -------- - --------------- ------------ -- ----- ---------- 311549902 STEPHENS TINA     D RR 3 BOX 17A    GREENWOOD    IN 47890 3178784465 442346889 PLEW     LINDA    C 3301 BEACON     INDIANAPOLIS IN 46224 3172978990 213764555 GLASS    BRANDON  S 1710 MAIN ST    WHITELAND    IN 47885 3178984321 313782439 GLASS    JACOB      3789 RIVER BLVD INDIANAPOLIS IN 45734 3175457676 220984332 WALLACE  MARIAH     7889 KEYSTONE   INDIANAPOLIS IN 46741 3173325986 443679012 SPURGEON TIFFANY    5 GEORGE COURT  INDIANAPOLIS IN 46234 3175679007 EMPLOYEE_PAY_TBL EMP_ID    POSITION        DATE_HIRE   PAY_RATE DATE_LAST     SALARY      BONUS --------- --------------- ----------- -------- ------------- ----------- ------ 311549902 MARKETING       23-MAY-89            01-MAY-99      4000 442346889 TEAM LEADER     17-JUN-90      14.75 01-JUN-99 213764555 SALES MANAGER   14-AUG-94            01-AUG-99      3000       2000 313782439 SALESMAN        28-JUN-97                            2000       1000 220984332 SHIPPER         22-JUL-96         11 01-JUL-99 443679012 SHIPPER         14-JAN-91         15 01-JAN-99 CUSTOMER_TBL CUST_ID CUST_NAME       ADDRESS    CUST_CITY    ST ZIP   CUST_PHONE   CUST_FAX ------- --------------- ---------- ------------ -- ----- ------------ -------- 232     LESLIE GLEASON  798 HARDAW INDIANAPOLIS IN 47856 3175457690                         AY DR 109     NANCY BUNKER    APT A 4556 BROAD RIPPLE IN 47950 3174262323                         WATERWAY 345     ANGELA DOBKO    RR3 BOX 76 LEBANON      IN 49967 7658970090 090     WENDY WOLF      3345 GATEW INDIANAPOLIS IN 46224 3172913421                         AY DR 12      MARYS GIFT SHOP 435 MAIN S DANVILLE     IL 47978 3178567221 3178523434                         T 432     SCOTTYS MARKET  RR2 BOX 17 BROWNSBURG   IN 45687 3178529835 3178529836                         3 333     JASONS AND DALL LAFAYETTE  INDIANAPOLIS IN 46222 3172978886 3172978887         AS GOODIES      SQ MALL 21      MORGANS CANDIES 5657 W     INDIANAPOLIS IN 46234 3172714398         AND TREATS      TENTH ST 43      SCHYLERS NOVELT 17 MAPLE   LEBANON      IN 48990 3174346758         IES             ST 287     GAVINS PLACE    9880 ROCKV INDIANAPOLIS IN 46244 3172719991 3172719992                         ILLE RD 288     HOLLYS GAMEARAMA 567 US 31  WHITELAND    IN 49980 3178879023 590     HEATHERS FEATHE 4090 N SHA INDIANAPOLIS IN 43278 3175456768         RS AND THINGS   DELAND AVE 610     REGANS HOBBIES  451 GREEN  PLAINFIELD   IN 46818 3178393441 3178399090 560     ANDYS CANDIES   RR 1       NASHVILLE    IN 48756 8123239871                         BOX 34 221     RYANS STUFF     2337 S     INDIANAPOLIS IN 47834 3175634402                         SHELBY ST 175        CAMERON'S PIES   178 N TIBBS AVON IN 46234 3174543390 290     CALEIGH'S KITTENS 244 WEST ST LEBANON IN 47890 3174867754 56 DANIELS SPANIELS 17 MAIN ST GREENWOOD IN 46578 3172319908 978        AUTUMN'S BASKETS 5648 CENTER ST SOUTHPORT IN 45631 3178887565 ORDERS_TBL ORD_NUM    CUST_ID PROD_ID           QTY ORD_DATE ---------- ------- ----------------- --- --------- 56A901     232     11235               1 22-OCT-99 56A917     12      907               100 30-SEP-99 32A132     43      222                25 10-OCT-99 16C17      090     222                 2 17-OCT-99 18D778     287     90                 10 17-OCT-99 23E934     432     13                 20 15-OCT-99 PRODUCTS_TBL PROD_ID    PROD_DESC                       COST ---------- ------------------------------ ------ 11235      WITCHES COSTUME                29.99 222        PLASTIC PUMPKIN 18 INCH         7.75 13         FALSE PARAFFIN TEETH            1.10 90         LIGHTED LANTERNS               14.50 15         ASSORTED COSTUMES              10.00 9          CANDY CORN                      1.35 6          PUMPKIN CANDY                   1.45 87         PLASTIC SPIDERS                 1.05 119        ASSORTED MASKS                  4.95 

A Closer Look at What Comprises a Table

The storage and maintenance of valuable data is the reason for any database's existence. You have just viewed the data that is used to explain SQL concepts in this book. The following sections take a closer look at the elements within a table. Remember, a table is the most common and simplest form of data storage.

A Field
graphics/newterm_icon.gif

Every table is broken up into smaller entities called fields. The fields in the PRODUCTS_TBL table consist of PROD_ID, PROD_DESC, and COST. These fields categorize the specific information that is maintained in a given table. A field is a column in a table that is designed to maintain specific information about every record in the table.

A Record, or Row, of Data
graphics/newterm_icon.gif

A record , also called a row of data, is each individual entry that exists in a table. Looking at the last table, PRODUCTS_TBL, consider the following first record in that table:

 11235      WITCHES COSTUME                29.99 

The record is obviously composed of a product identification, product description, and unit cost. For every distinct product, there should be a corresponding record in the PRODUCTS_TBL table. A record is a horizontal entity in a table.

graphics/newterm_icon.gif

A row of data is an entire record in a relational database table.

A Column
graphics/newterm_icon.gif

A column is a vertical entity in a table that contains all information associated with a specific field in a table. For example, a column in the PRODUCTS_TBL having to do with the product description would consist of the following:

 WITCHES COSTUME  PLASTIC PUMPKIN 18 INCH FALSE PARAFFIN TEETH LIGHTED LANTERNS ASSORTED COSTUMES CANDY CORN PUMPKIN CANDY PLASTIC SPIDERS ASSORTED MASKS 

This column is based on the field PROD_DESC, the product description. A column pulls information about a certain field from every record within a table.

The Primary Key

A primary key is a column that makes each row of data in the table unique in a relational database. The primary key in the PRODUCTS_TBL table is PROD_ID, which is typically initialized during the table creation process. The nature of the primary key is to ensure that all product identifications are unique, so that each record in the PRODUCTS_TBL table has its own PROD_ID. Primary keys alleviate the possibility of a duplicate record in a table and are used in other ways, which you read about in Hour 3.

A NULL Value
graphics/newterm_icon.gif

NULL is the term used to represent a missing value. A NULL value in a table is a value in a field that appears to be blank. A field with a NULL value is a field with no value. It is very important to understand that a NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation. Notice that in the EMPLOYEE_TBL table, not every employee has a middle initial. Those records for employees who do not have an entry for middle initial signify a NULL value.

Additional table elements are discussed in detail during the next two hours.

Examples and Exercises Used in This Book

As stated before, most of the examples used in this book were generated using Oracle. This was done for several reasons: consistency, the popularity of the Oracle database, and Oracle's high compliance to the ANSI SQL-99 standard.

Many exercises in this book use Oracle examples. We have also included exercises for as much of the book as possible using MySQL. We decided to use MySQL in this edition for exercises because MySQL is open source and may be freely distributed, whereas Oracle is not. MySQL is popular, easy to download, and easy to install. MySQL is available for most operating system platforms, including Windows and Linux. Note that because MySQL is not as compliant to the SQL-99 standard as Oracle, MySQL exercises may be somewhat limited in some hours of instruction. Due to MySQL's lack of compliance to several parts of the SQL standard, we have opted to keep our Oracle examples.

graphics/note_icon.gif

Links to Oracle and MySQL Web sites can be found by looking up this book's Web page on http://www.samspublishing.com/.



Team-Fly    
Top
 


Sams Teach Yourself SQL in 24 Hours
Sams Teach Yourself SQL in 24 Hours (5th Edition) (Sams Teach Yourself -- Hours)
ISBN: 0672335417
EAN: 2147483647
Year: 2002
Pages: 275

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net