MySQL Chapter Three (SQL) MySQL Chapter Three (SQL) Documentation Version: 0.95 MySQL Version: 3.20.29 Overview The MySQL database system offers a subset of the ANSI Entry level SQL92 specification. The main goals of MySQL are speed and robustness. Adding transactions would incur a significant speed and complexity penalty. There is however currently work underway to give similar functionality in a different way. This will probably be done by allowing an atomic multi-table update. The base upon which MySQL is built is a set of routines that have been used in a highly demanding production environment for many years. While MySQL is currently still in development it already offers a rich and highly useful function set. ALTER TABLE SYNOPSIS: ALTER [IGNORE] TABLE table_name alter_specification [, alter_specification ...] alter_specification: ADD [COLUMN] create_definition or CHANGE [COLUMN] old_column_name create_definition or ALTER [COLUMN] column_name { SET default | DROP DEFAULT } or DROP [COLUMN] column_name or DROP PRIMARY KEY or DROP INDEX key_name DROP FOREIGN KEY key_name DESCRIPTION: The ALTER TABLE command can be used to modify a table definition. ALTER TABLE works by creating a temporary table and copying all information from the current table to the temporary one. When the copy is done, the old table is deleted and the new table is renamed. This is done in such a way that all updates are automatically redirected to the new table. While ALTER TABLE is working, the old table is available for other clients. Table updates/writes to the table are stalled and only executed after the new table is ready. If IGNORE isn't specified then the copy will be aborted and rolled back if there are any unique keys duplicated in the new table. CHANGE column_name, DROP column_name and DROP INDEX are MySQL extensions to ANSI SQL. [COLUMN] is optional and may be omitted. The ALTER [COLUMN] construct can be used to change or remove an old default. ADD and CHANGE take the same create_definition as CREATE TABLE. See the CREATE TABLE syntax. If you drop a column_name that is part of a composite key, the key part will be removed. If all key parts are removed then the key will be removed. DROP PRIMARY KEY drops the first UNIQUE key in a table. CHANGE will do its best to change existing information to the new format. The DROP FOREIGN KEY syntax is for planned functionality. Currently it does nothing. In fact, none of the FOREIGN KEY stuff does anything. You can use the C API function mysql_info(&MYSQL_RESULT) to find out how many records were copied and how many were deleted because of duplicated keys.
To use ALTER TABLE you must have select, insert, delete, update, create and drop privileges on the table.