

The syntax is the same as in CREATE TABLE. ADD COLUMN (col_name column_definition.)Īdds a column to the table. See CREATE TABLE: Table Options for information about table options. See Setting Character Sets and Collations for details on setting the character sets and collations.

Character Sets and CollationsĬONVERT TO CHARACTER SET charset_name The CREATE INDEX and DROP INDEX statements can also be used to add or remove an index. See CREATE TABLE: Index Definitions for information about index definitions. See CREATE TABLE: Column Definitions for information about column definitions.

TABLE, one will not get an error if the table doesn't exist. If this is directive is used after ALTER. The same message text will be issued and the ALTER will move on to the nextĬlause in the statement (or end if finished). Report errors when the condition is triggered for that clause.

When IF EXISTS and IF NOT EXISTS are used in clauses, queries will not The IF EXISTS and IF NOT EXISTS clauses are available for the following: See the ALGORITHM alter specification for more information. This statement is equivalent to the following: ALTER TABLE. See the LOCK alter specification for more information. This statement has the following semantics: Online ALTER TABLE is available by executing the following: ALTER ONLINE TABLE. ALTER ONLINE TABLEĪLTER ONLINE TABLE also works for partitioned tables. See InnoDB Online DDL Overview for more information on online DDL with InnoDB. Online DDL is supported with the ALGORITHM and LOCK clauses. If you are renaming a table, then it also requires the DROP, CREATE and INSERT privileges for the table or the database as well. PrivilegesĮxecuting the ALTER TABLE statement generally requires at least the ALTER privilege for the table or the database. InnoDB allocates three buffers whose size is defined by innodb_sort_buffer_size. Aria and MyISAM allocate a buffer whose size is defined by aria_sort_buffer_size or myisam_sort_buffer_size, also used for REPAIR TABLE. Incrementing the buffer speeds up the index creation. When an index is created, the storage engine may use a configurable buffer in the process. This statement can also be used to rename a table. Also, note that IGNORE is accepted but ignored in ALTER TABLE. This can be useful if a column (or a set of columns) should be UNIQUE but it contains duplicate values however, this technique provides no control on which rows are preserved and which are deleted. To suppress the error and force the creation of UNIQUE indexes, discarding duplicates, the IGNORE option can be specified. When adding a UNIQUE index on a column (or a set of columns) which have duplicated values, an error will be produced and the statement will be stopped. This is also true for non-transactional tables. If another connection is using the table, a metadata lock is active, and this statement will wait until the lock is released. You can also change the comment for the table and the storage engine of the | EXCHANGE PARTITION partition_name WITH TABLE tbl_nameĪLTER TABLE enables you to change the structure of an existing table.įor example, you can add or delete columns, create or destroy indexes,Ĭhange the type of existing columns, or rename columns or the table | partition_options | CONVERT TABLE normal_table TO partition_definition | CONVERT PARTITION partition_name TO TABLE tbl_name
