Database Reference
In-Depth Information
The fourth column,
Key
, indicates whether a field is a key field — an indexed column. It's
not an indexed column if the result is blank, as it is with
common_name
. If a column is
indexed, the display will say which kind of index. Because of the limited space permitted
in the display, it truncates the words. In the example shown, the
bird_id
column is a
primary key, shortened to
PRI
in this display. We set
scientific_name
to another
type of key or index, one called
UNIQUE
, which isabbreviated
UNI
here.
The next-to-last column in the display,
Default
, would contain any default value set for
each field. We didn't set any when creating the
birds
table, but we could have done so.
We can do that later.
The last column,
Extra
, provides any extra information the table maintains on each
column. In the example shown, we can see that the values for
bird_id
will be incre-
mented automatically. There's usually nothing else listed in this column.
If we don't like something within the structure of the table we created, we canuse the
ALTER TABLE
statement to change it (this SQL statement is covered in
Chapter5
). If
you made some mistakes and just want to start over, you can delete the table and try again
to create it. To delete a table completely (including its data), you can use the
DROP
TABLE
statement, followed by the table name. Be careful with this SQL statement, as it's
not reversible and it deletes any data in thetable.
NOTE
Incidentally, when using the
mysql
client, you can press the up arrow on your keyboard to get to the pre-
vious lines you entered. So if you create a table, then run the
DESCRIBE
statement and catch a mistake,
you can just drop the table, and use the up arrow to go back to your previous entry in which you created
the table. Use the left arrow to move the cursor over to the text you want to change and fix it. When
you've finished modifying the
CREATE TABLE
statement, press Enter. The modified
CREATE TABLE
statement will then be sent to the server.