|
Go to FLATMySQL.com
MySQL stores data in your table in columns. Each column usually contains
only a specific class of information. A database that has a table that
contains contact information might have the following columns: Name, Address,
City, State, Zip, Phone, FAX,Client_Number
Each column has a column type and most column types require that you specify
a size. For instance, varchar(60) would probably be a good column type
and size for the Name column, since it is hard to imagine someone having a name
longer than 60 characters. varchar is a somewhat generic column type that
can store most of the characters that appear on your keyboard.
Here are some common column types and some notes about using them:
| Column Name |
Maximum Size |
Notes |
| varchar |
255 characters |
Can store most of the characters that appear
on your keyboard. When in doubt, use this column type. |
| char |
255 characters |
Should be used only to store characters that
tend to have the same width. For instance, varchar(2) would
be a good choice for a field that will only contain US state
abbreviations, since no state abbreviation is longer than 2
characters. You could also use varchar in this example (and
MySQL may convert it to varchar anyway), but selecting char won't
necessarily hurt. For columns containing longer and variable
length content, don't use char, or MySQL will make your database
consume more disk space than is necessary. |
| int |
a whole number less than 2,140,000,000 (2.14
billion) |
Should be used to store whole numbers
only. A whole number is a number like 8876543 that contains no
decimal parts or spaces. Phone numbers like (740) 975-8891 and
prices like $4.24 can't be stored in int columns because they are
not whole numbers. |
| text |
65,000 characters |
Can store up to 65KB of text consisting of
most keyboard characters. Note: your browser may not be able to
send 65KB of text via an HTML form. |
| mediumtext |
mediumtext up to 16,000,000 characters |
Can store up to 16MB of keyboard character
type text. Note: there is no browser that will package and send
16MB via an HTML form, so mediumtext might be overkill for the great
majority of applications. |
| float |
floating point numbers |
Consists of two parts, a whole number and a
decimal number. It takes the form float(w,d) where w is the
max number of digits that the whole number can contain and d is the max
number of digits that the decimal can contain. For example, the
largest number that float(4,2) can hold is 9999.99 |
For other column types, see the following articles:
|