How to rename a table in Snowflake

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

Stephen Allwright
Stephen Allwright

Rename a Snowflake table

Renaming a table in Snowflake is a common and easy task to undertake by using the alter table command.

Here is the simplest possible example of how to do so:

alter table old_name rename to new_name;

Rename a table if it already exists

We can build upon the simple example we showed previously by adding an if exists constraint, which checks first if the table exists before renaming the table.

alter table if exists old_name rename to new_name;

Common issues when renaming a table

When renaming a table, there are two things to keep in mind:

  • The new table name must not be currently in use by another table in the same schema, but having the same table name across different schemas is fine
  • Renaming the table does not update references to that table in other objects (such as view definitions), so this must be updated to the new name manually

Editing tables

Rename Snowflake column
Swap Snowflake tables
Drop table in Snowflake
Delete table in Snowflake

Creating tables

Create table in Snowflake
Create or replace table in Snowflake
Create table as select 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.