Add or Remove a UUID column

An existing table can be altered and a new UUID column can be added. The existing records in the table will have a NULL value for the newly added UUID column. An existing UUID column can also be removed from a table.

Adding a UUID Column to an Existing Table

Use ALTER TABLE to add a UUID column to an existing table.

Create a table test_alter without a UUID column.

sql-> CREATE TABLE test_alter(id INTEGER,
                 name STRING, PRIMARY KEY(id));
Statement completed successfully

Use ALTER TABLE to add a UUID column to test_alter. You can specify the default clause, GENERATED BY DEFAULT.

sql-> ALTER TABLE test_alter 
           (ADD new_id STRING AS UUID GENERATED BY DEFAULT );
Statement completed successfully

Dropping a UUID Column

To remove a UUID column from a table, use ALTER TABLE with a DROP id clause.

Note:

You cannot drop a UUID column if it is the primary key, or if it participates in an index.
sql-> CREATE Table Test_alter ( name STRING ,
                 id STRING AS UUID GENERATED BY DEFAULT,
                 PRIMARY KEY (name));
Statement completed successfully

sql-> ALTER TABLE Test_alter (DROP id);
Statement completed successfully