This topic describes the supported DDL operations on columns in an ALTER TABLE statement during data migration from a MySQL database to a MySQL-compatible tenant of OceanBase Database.
Syntax
ALTER TABLE tbl_name
[alter_option [, alter_option] ...]
alter_option: {
ADD [COLUMN] col_name column_definition
[FIRST | AFTER col_name]
| ADD [COLUMN] (col_name column_definition,...)
| ALTER [COLUMN] col_name {
SET DEFAULT {literal | (expr)}
| SET {VISIBLE | INVISIBLE}
| DROP DEFAULT
}
| CHANGE [COLUMN] old_col_name new_col_name column_definition
[FIRST | AFTER col_name]
| DROP [COLUMN] col_name
| MODIFY [COLUMN] col_name column_definition
[FIRST | AFTER col_name]
| ORDER BY col_name [, col_name] ...
| RENAME COLUMN old_col_name TO new_col_name
}
Supported DDL operations
Use
ADD COLUMNto add one or more columns. For more information about how to define a column, see Create a column. You can also specify theFIRST | AFTERkeyword.Use
ALTER COLUMN SET DEFAULTto modify the default value of a column.Use
ALTER COLUMN DROP DEFAULTto drop the default value of a column.Use
CHANGE COLUMNorMODIFY COLUMNto change or modify a column.Use
DROP COLUMNto drop a column.
Unsupported DDL operations
Warning
If a DDL statement to be synchronized contains the following unsupported definitions, the conversion will fail and the output will be an empty string.
Use
ALTER COLUMN SET VISIBLE | INVISIBLEto modify the visibility of a column.Use
ORDER BY col_nameto sort a column.Use
RENAME COLUMNto rename a column.ALTER TABLE t RENAME COLUMN d TO g;
Ignored attributes
Warning
The following attributes will not be parsed or converted when they are specified in the synchronized DDL statements and will be ignored.
- If an
ALTER TABLEstatement contains theMODIFY COLUMNorCHANGE COLUMNclause, theFIRST | AFTERkeyword will be ignored.
Limitations
Notice
Due to the limitations of MySQL-compatible tenants of OceanBase Database, an error may be returned when the synchronized DDL statements are converted and executed in MySQL-compatible tenants of OceanBase Database in the following scenarios. For more information about DDL statements not supported in MySQL-compatible tenants of OceanBase Database, see the documentation for OceanBase Database.
Using the
MODIFY COLUMNorCHANGE COLUMNstatement to modify the column type may fail. This is because some column types are not supported in MySQL-compatible tenants of OceanBase Database.Using the
MODIFY COLUMNorCHANGE COLUMNstatement to modify the column length may fail.Using the
ALTER COLUMN SET DEFAULTstatement to set a default value may fail. This is because some functions and expressions are not supported in MySQL-compatible tenants of OceanBase Database.You cannot drop columns that are used as primary keys, unique keys, or general indexes, or columns with FOREIGN KEY constraints.