How to rename a column in Snowflake

Learn how to rename a column in Snowflake by using the alter table SQL command.

Stephen Allwright
Stephen Allwright

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:

  1. The new column name must not be currently used in the table
  2. 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
  3. Columns that are part of the clustering key cannot be renamed

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

References

Snowflake alter table documentation

Snowflake

Stephen Allwright Twitter

I'm a Data Scientist currently working for Oda, an online grocery retailer, in Oslo, Norway. These posts are my way of sharing some of the tips and tricks I've picked up along the way.