Rename column in Snowflake table
The simplest possible syntax for renaming a column in Snowflake is:
alter table table_name rename column old_column_name to new_column_name
Rename column if the table already exists
We can build upon the simple example we showed previously by adding an
if exists constraint.
This first checks if the table exists before renaming the column in the table. This is helpful as it stops potential errors from being returned.
alter table if exists table_name rename column old_column_name to new_column_name
Common issues when renaming a column in Snowflake
When renaming a column, there are three things to keep in mind:
- The new column name must not be currently used in the table
- Renaming the column does not update references to that table in other objects (such as view definitions), so this must be updated to the new name manually
- Columns that are part of the clustering key cannot be renamed