How to rename a column in Snowflake
Learn how to rename a column in Snowflake by using the alter table SQL command.
1. Rename column in Snowflake table
2. Rename column if the table already exists
3. Common issues when renaming a column in Snowflake
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
Related articles
Editing tables
Rename a Snowflake table
Add column to Snowflake table
Add multiple columns to Snowflake table
Drop column from a table
Creating tables
Create or replace table in Snowflake
Create table as select in Snowflake
Snowflake functions
Select all columns except one or multiple in Snowflake