Name
ALTER/MODIFY
Synopsis
ALTER [IGNORE] TABLEtable
ADD [COLUMN]create_clause
ALTER [IGNORE] TABLEtable
ADD INDEX [name
] (column
, . . .) ALTER [IGNORE] TABLEtable
ADD UNIQUE [name
] (column
, . . .) ALTER [IGNORE] TABLEtable
ALTER [COLUMN]column
SET DEFAULTvalue
ALTER [IGNORE] TABLEtable
ALTER [COLUMN]column
DROP DEFAULT ALTER [IGNORE] TABLEtable
CHANGE [COLUMN]column
create_clause
ALTER [IGNORE] TABLEtable
DROP [COLUMN]column
ALTER [IGNORE] TABLEtable
DROP FOREIGN KEYkey
ALTER [IGNORE] TABLEtable
DROP INDEXkey
ALTER [IGNORE] TABLEtable
DROP PRIMARY KEY ALTER [IGNORE] TABLE table MODIFY [COLUMN] create_clause ALTER [IGNORE] TABLE>table
RENAME [AS]new_name
The ALTER
statement covers a wide range of actions that modify the structure of
a table. This statement is used to add, change, or remove columns
from an existing table as well as to remove indexes. Multiple
ALTER
statements may be combined into one using
commas as in the following example:
ALTER TABLE mytable DROP myoldcolumn, ADD mynewcolumn INT
To perform modifications on the table, MySQL creates a copy of the
table and changes it, meanwhile queuing all table altering queries.
When the change is done, the old table is removed and the new table
put it its place. At this point the queued queries are performed. As
a safety precaution, if any of the queued queries create duplicate
keys that should be unique, the ALTER
statement is
rolled back and cancelled. If the
IGNORE
keyword is present in the statement, duplicate ...
Get MySQL and mSQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.