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