Name
ALTER TABLE
Synopsis
ALTER [IGNORE] TABLEtablechanges[, . . . ]
Use this statement to change an
existing table's structure and other properties.
Alterations to a table can include adding a new column (see the
ADD clauses that follow), changing an existing
column (see the ALTER, CHANGE,
and MODIFY clauses), deleting a column or index
(see the DROP clauses), and miscellaneous other
tablewide settings. The IGNORE flag applies to all
clauses and instructs MySQL to ignore any error messages regarding
duplicate rows that may occur as a result of a column change. It will
keep the first unique row found and drop any duplicate rows.
Otherwise, the statement will be terminated and changes rolled back.
The following are the syntax and
explanations of each clause, with examples, grouped by type of
clause. Multiple alterations may be combined in a single
ALTER TABLE statement. They must be separated by
commas and each clause must include the minimally required elements.
ADD clauses for columns and indexes
ALTER [IGNORE] TABLEtableADD [COLUMN]columndefinition[FIRST|AFTERcolumn] ADD INDEX [index] [USINGtype] (column,...) ADD [FULLTEXT|SPATIAL] [index] (column,...)
These clauses add columns and indexes to
a table. The first syntax adds a new column to a table. The same
column definition that would be used in a CREATETABLE statement is used in this syntax and in
several others found with the ALTER
TABLE statement. Basically, the name of the column is given, followed by the column datatype ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access