Difference between revisions of "Updating and Deleting MySQL Tables"
(→Altering a MySQL Table) |
|||
Line 3: | Line 3: | ||
== Altering a MySQL Table == | == Altering a MySQL Table == | ||
− | A pre-existing table in a database may be modified using the SQL ''ALTER TABLE'' statement. | + | 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'', .... |
Revision as of 19:13, 2 October 2007
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, ....