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.
CREATE TABLE test_alter(id INTEGER,
name STRING, PRIMARY KEY(id))
Output:Statement completed successfully
Use ALTER TABLE to add a UUID column to test_alter
. You can specify the
default clause, GENERATED BY DEFAULT.
ALTER TABLE test_alter
(ADD new_id STRING AS UUID GENERATED BY DEFAULT )
Output: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.CREATE Table Test_alter ( name STRING ,
id STRING AS UUID GENERATED BY DEFAULT,
PRIMARY KEY (name))
Output:Statement completed successfully
ALTER TABLE Test_alter (DROP id)
Output:Statement completed successfully