Changing a table definition

You can change the definition of a table by adding a new column, changing an existing column definition such as its length or default value, dropping an existing column, adding or removing constraints, changing partitioning for the table, or altering one of many other options.

To change a table definition, you can use the ALTER TABLE statement. You can add, change, or drop columns and add or remove constraints all with one ALTER TABLE statement. You can also include other options to define or change partitioning, add a materialized query table definition, or change your media preference for the table to use solid state disk storage media.

A second option for changing a table definition is to use the CREATE OR REPLACE TABLE statement. With CREATE OR REPLACE TABLE, all the changes to the table definition are made with the standard CREATE TABLE statement. If the table already exists, any changes between the new table definition and the existing table definition are recognized and applied to the existing table. For example, based on the content of the CREATE OR REPLACE TABLE statement, several new columns could be added, the data type of a column could be changed, and a primary key could be defined.