Database Reference
In-Depth Information
Figure 8.8
The two new columns in the visitorbook table.
You may notice from the above that the format to add a table follows the same format as
when we were creating a table. We can add other parameters to the command, should they
be needed, that allow the column to become a foreign key, or allow nulls. For our examples
we do not need to specify any additional parameters. Have a look at the chapter on creating
databases to remind you of these extra parameters if you need to. Describe the webpage
table again and you will see the results shown in Figure 8.8.
You will see from Figure 8.8 that the visitorbook table now contains the two new rows.
The ADD keyword can also be used to add other things to the table, such as primary
keys, as well as indexes. To add a primary key to a table that does not already have one, use:
ALTER TABLE tablename
ADD
PRIMARY KEY columnname
Of course, the column that you are setting the primary key for must have unique data in
each field for the column to be specified as such. To add an index to a column use:
ALTER TABLE tablename
ADD
INDEX indexname (columnname)
ALTER TABLE RENAME
The ALTER TABLE RENAME query allows you to change the name of a table. It has the fol-
lowing basic format:
ALTER TABLE tablename
RENAME
newtablename
Search WWH ::




Custom Search