The tables used throughout this book are part of an order entry system used by an imaginary distributor of paraphernalia that might be needed by your favorite cartoon characters (yes, cartoon characters; no one said that learning MySQL needed to be boring). The tables are used to perform several tasks:
Making this all work requires six tables that are closely interconnected as part of a relational database design. A description of each of the tables appears in the following sections. Note Simplified Examples The tables used here are by no means complete. A real-world order entry system would have to keep track of lots of other data that has not been included here (for example, payment and accounting information, shipment tracking, and more). However, these tables do demonstrate the kinds of data organization and relationships you will encounter in most real installations. You can apply these techniques and technologies to your own databases. Table DescriptionsWhat follows is a description of each of the six tables, along with the name of the columns within each table and their descriptions. Note Why Out of Order? If you are wondering why the six tables are listed in the order they are, it is due to their dependencies. As the products tables is dependent on the vendors table, vendors is listed first, and so on. The vendors TableThe vendors table stores the vendors whose products are sold. Every vendor has a record in this table, and that vendor ID (the vend_id) column is used to match products with vendors.
The products TableThe products table contains the product catalog, one product per row. Each product has a unique ID (the prod_id column) and is related to its vendor by vend_id (the vendor's unique ID).
The customers TableThe customers table stores all customer information. Each customer has a unique ID (the cust_id column).
The orders TableThe orders table stores customer orders (but not order details). Each order is uniquely numbered (the order_num column). Orders are associated with the appropriate customers by the cust_id column (which relates to the customer's unique ID in the customers table).
The orderitems TableThe orderitems table stores the actual items in each order, one row per item per order. For every row in orders there are one or more rows in orderitems. Each order item is uniquely identified by the order number plus the order item (first item in order, second item in order, and so on). Order items are associated with their appropriate order by the order_num column (which relates to the order's unique ID in orders). In addition, each order item contains the product ID of the item orders (which relates the item back to the products table).
The productnotes TableThe productnotes table stores notes associated with specific products. Not all products may have associated notes, and some products might have many associated notes.
|