Abbey Workshop

MySQL: Updating a MySQL Table Structure

The structure of table can be changed with the alter keyword. Examples in various situations follow.

Adding Columns/Fields

The syntax for adding a column follows.

alter table tablename add columnname datatype
		

Tablename, columnname, and datatype are supplied by you. For example:

alter table lists add title varchar(30);
		

The above command adds the title field/column to the table lists, and sets the datatype to varchar(30). Modifiers can also be used. The following example requires the column contains data.

alter table lists add title varchar(30);
		

Deleting Columns/Fields

The syntax for dropping a column or field from a table is pretty straightforward.

alter table tablename drop columnname;
		

You supply tablename and columnname. For example, to delete the column just added above, the syntax would be:

alter table lists drop title;
		

This drops the title field from the table lists.