How to rename a table in Snowflake
Learn how to rename a table in Snowflake using the alter table SQL command.
📋
This post will go through the following:
1. Rename a Snowflake table
2. Rename a table if it already exists
3. Common issues when renaming a table
1. Rename a Snowflake table
2. Rename a table if it already exists
3. Common issues when renaming a table
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
Related articles
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