Database Reference
In-Depth Information
3
How Shall We Store it? - Datatypes
The Datatype
All databases store “chunks” of information. The most efficient way of storing those chunks
is to group them into similar chunks that can all be stored in a similar way.
This chapter will describe some of the ways that you can store data. You will need these
methods to define your tables so that you can begin to store data within them.
I will try to provide some examples in this chapter, but as you need information that you
will get later in the topic to fully understand what datatypes do, practical examples here are
difficult. If you do not understand some of this chapter come back to it after you have run
a few queries and created a few tables, and it should all make sense.
When you create a table, as well as deciding what you are going to call different groups
of data, you also need to define the type of data that you are going to store within that
group. The datatype (sometimes just called a type) is used to define the data that is being
stored within the group. It also determines the sort of actions that you can do with that type
of data.
There are many datatypes in programming languages, so if you have programmed
before you probably will only need a cursory examination of this chapter (or the tables
within) to familiarize yourself with MySQL datatypes. If you are new to programming and
MySQL, then give this chapter some thought, as storing the data in the correct way will save
you hours of re-design and coding later on in your database project.
This chapter will describe four sets of datatypes:
numeric
character
date and
other types.
The first three are the basic types that most data can be grouped into. MySQL breaks
these three types down into further datatypes. We will also describe some other types that
have special functions.
When you create a table to store data, when you name each column you also specify the
datatype for that column. You specify the datatype using the keywords that we are about to
describe. This chapter will just review these types; some examples of their use will be
shown when we actually create some tables in the following chapters.
19
Search WWH ::




Custom Search