Creating a MySQL Database
Page One: But First, a Database -->
Page Two: Data Types-->
Page Three: Using phpMyAdmin to create the
simple database-->
Page Four: Defining our Database Fields-->
Page Five: Inserting some Data into our Table-->
Data Types
It’s a good idea to understand a little about data types before we start. What kind of data are we going to store in our fields? There are three categories of data types in MySQL. Those are number, date and time, and string (for, in a word, words) data types. We are going to use the following types for our pet database.
String Types
We will use VARCHAR for
species, breed, name, and image name. We will use TEXT for the personality
description.
VARCHAR is any variable length string between 1 and 255. You must define
a length.
TEXT is a field for which the maximum number of characters
is 65535. You do not need to define the length. We might have a lot to
say about a particular animal’s personality, so the TEXT data type
will fit the bill here.
Number Types
We will use INT for the ID for each animal,
and we’ll
use TINYINT for the age.
INT stands for integer. This is a normal sized number
that can be signed or unsigned. A signed number can
include negative numbers while an unsigned number includes only positive
numbers.
The maximum number, if signed, is – 2147483648 to 2147483647. An
unsigned number can max out at 4294967295.
TINYINT is a very small integer that can range from –128
to 127, if signed. It can go to 255 if unsigned. Since most pets don’t
live past their 20’s, the TINYINT will work well.
Date and Time
Another useful data type is the DATE, which is entered as yyyy-mm-dd and the DATETIME type which is entered the same, but with the additon of time entered as hh-mm-ss. Since it would be nice to know when the animals have arrived at the center, we have a field for DATETIME. Next-->