Creating Databases Tables and Indexes
Creating Databases Tables and Indexes
numbers.
DOUBLE
15
DATE
TIME
DATETIME
TIMESTAMP
YEAR
DATE
23
Usually, you create all the indexes you need when you are creating
tables. Any column declared as PRIMARY KEY, KEY, UNIQUE, or INDEX
will be indexed.
Sometimes you will find that you are running many queries based on an
unindexed column, and in this situation, you can add an index using the
CREATE INDEX statement.
Interestingly enough, the CREATE INDEX statement is mapped to an
ALTER TABLE statement before being executed. The ALTER TABLE
statement can be used for this and many other purposes. We will look
at its use in the last section of this chapter.
We can, for example, add an index to the employee table as follows:
create index name on employee(name);
This creates an index called name based on the name field in the
employee table.
Deleting Databases, Tables, and
29
Indexes
Use the create table statement, which has this general form:
Column Types
42
Change table structure with ALTER TABLE. This is the general structure of the
ALTER TABLE command:
Exercises
45