ALTER TABLE MODIFY Column - Oracle to MariaDB Migration

In Oracle, you can use the ALTER TABLE statement with the MODIFY clause to modify the definition of one or more columns.

In MariaDB, you can also use the MODIFY clause of ALTER TABLE, but the syntax is slightly different.

Oracle:

  CREATE TABLE t1 (c1 VARCHAR2(10), c2 NUMBER(5));
  /* Table created. */
 
  -- Modify single column
  ALTER TABLE t1 MODIFY (c1 VARCHAR2(30) NOT NULL);
  /* Table altered. */
 
  -- Modify multiple columns
  ALTER TABLE t1 MODIFY (c1 VARCHAR2(30) NULL, c2 NUMBER(10) NOT NULL);
  /* Table altered. */

MariaDB:

  CREATE TABLE t1 (c1 VARCHAR(10), c2 INT);   
  /* Query OK, 0 rows affected */
 
  -- Modify single column
  ALTER TABLE t1 MODIFY c1 VARCHAR(30) NOT NULL;
  /* Query OK, 0 rows affected */
 
  -- Modify multiple columns
  ALTER TABLE t1 MODIFY c1 VARCHAR(30) NULL, MODIFY c2 BIGINT NOT NULL;
  /* Query OK, 0 rows affected */

In Oracle, parentheses () are optional for modifying a single column, but required if you modify multiple columns.

In MariaDB, parentheses cannot be used, and you need to repeat the MODIFY keyword for each column.

For more information, see Oracle to MariaDB Migration.