The MySQL mode of OceanBase Database allows you to add a STORED column, modify a STORED column, drop a STORED column, add a VIRTUAL column, and drop a VIRTUAL column.
Add a STORED column
The syntax for adding a STORED column is as follows:
ALTER TABLE table_name ADD COLUMN (column_name INT GENERATED ALWAYS AS
(column_expression) STORED);
Here is an example:
obclient> CREATE TABLE t1(c1 INT,c2 VARCHAR(50));
Query OK, 0 rows affected
obclient> ALTER TABLE t1 ADD COLUMN (c3 INT GENERATED ALWAYS AS (c1 + 1) STORED);
Query OK, 0 rows affected
Drop a STORED column
The syntax for dropping a STORED column is as follows:
ALTER TABLE table_name DROP COLUMN column_name;
Here is an example:
obclient> ALTER TABLE t1 DROP COLUMN c3;
Query OK, 0 rows affected
Add a VIRTUAL column
The syntax for adding a VIRTUAL column is as follows:
ALTER TABLE table_name ADD COLUMN column_name INT GENERATED ALWAYS AS
(column_expression) VIRTUAL;
Here is an example:
obclient> ALTER TABLE t1 ADD COLUMN (c3 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL);
Query OK, 0 rows affected
Drop a VIRTUAL column
The syntax for dropping a VIRTUAL column is as follows:
ALTER TABLE table_name DROP COLUMN column_name;
Here is an example:
obclient> ALTER TABLE t1 DROP COLUMN c3;
Query OK, 0 rows affected