Updating and Deleting MySQL Tables

From Techotopia
Revision as of 19:13, 2 October 2007 by Neil (Talk | contribs) (Altering a MySQL Table)

Jump to: navigation, search

Once a table has been created it is inadvisable to modify it once it contains data. Sometimes, however, it is necessary to make a change and such changes can be made using the SQL statements. It is also possible to delete an existing table from a database. In this chapter both of this topics will be covered.

Altering a MySQL Table

A pre-existing table in a database may be modified using the SQL ALTER TABLE statement. The ALTER TABLE statement allows changes to the structure of a table to be modified. Permitted changes include the addition or removal of columns, changing the data type of a column and renaming of the table or columns.

The CREATE TABLE syntax requires the name of the table to be altered, followed by the list of changes that are to made to the table:

ALTER TABLE table_name alteration_spec, alteration_spec, ....