Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1

one, one-to-many, and many-to-many. You learned what each one does and how to implement this
relationship inside the database. Also, today I introduced the Meet-A-Geek project. This project is based on
an actual site running MySQL. You practiced the techniques and concepts you learned today on this sample
project.


The concepts that were covered today can be applied to any database. They are in this book because,
from my experience, there is nothing more important to a database than its design. If you are going to
be a MySQL administrator or a programmer writing a program to access the data contained in a MySQL
database, it is essential that you know how to design a database.

Q&A


Q:

This design process seems like a waste of time. Why should I spend
all this time designing when I could spend it actually creating the
database?
A:
The time spent carefully designing a database will be recouped tenfold
when it come to the creating and maintaining of the database. If the
database is not well-thought-out or designed correctly, you will spend
countless hours adding fields and relationships you may have missed.
Extracting the information will also take longer because databases that are
hastily put together tend not to be normalized. This results in redundant
data, as well as wasted disk space. So the extra hours you spend designing
will pay off later.
Q: What purpose does modeling the database serve?
A:
Modeling the database serves several functions. First, it provides a visual
representation of the logic and flow of your design. This will allow you to
pinpoint exactly where the flaws or weaknesses exist in your design.
Second, it provides a good source of documentation for your database. The
model contains all of the tables, their relationships, the fields, and field
types. There is no better source of documentation than a good model.

Exercises



  1. In the Meet-A-Geek project, you defined several business objects. Can you define
    any more objects?

  2. Come up with the rest of the business rules for the Meet-A-Geek project.


Day 4: Creating Your First Database


Overview


Creating a database is probably one of the most important, yet least used, of all the MySQL functions. There
are many ways to accomplish this task in MySQL. Today, you will learn the following:
ƒ The CREATE and DROP commands
ƒ Using the mysqladmin utility
ƒ Adding users to your database
ƒ Creating the Meet-A-Geek database


The CREATE and DROP Commands


When you think of the CREATE and DROP commands, you should envision earthmoving equipment, dump
trucks, and cranes, because these are the tools you use to create your database. These commands, though
seldom used, are the most important. Hopefully, a lot of thought has gone into the decision making process
before either of these commands is issued.


The CREATE Command


There are many different ways to create databases in MySQL. When you create a database, you usually will
have the entire layout ready. Normally, you would add the tables immediately after creating the database,
but, because this book is a training guide, you will take it one step at a time.
The first way to create a database in MySQL is to enter the SQL (Structured Query Language)
command CREATE DATABASE>databasename in the MySQL monitor, where databasename is the
name of the database you are creating. Perform the following steps to create this sample database:

Free download pdf