O'Reilly logo

Sams Teach Yourself MySQL by Chris Newman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Altering Tables

You can use the ALTER TABLE command to change part of a table definition. You can ADD, MODIFY, or DROP a column on a live table, although, of course, you should take care to ensure that doing so will not cause errors in an application or query that relies on the existing table structure.

To add a new column, use the ADD keyword followed by a column definition. For example, the following statement adds a new column named fax to the customer_contacts table, which has a maximum length of 12 characters:

mysql> ALTER TABLE customer_contacts
    -> ADD fax VARCHAR(12);
Query OK, 11 rows affected (0.00 sec)
Records: 11  Duplicates: 0  Warnings: 0

To modify an existing column, use the MODIFY keyword followed by the existing column name, a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required