You are here: Reference Information > SQL Reference Information > SQL Statements > RENAME TABLE

RENAME TABLE

RENAME TABLE — rename a table

Syntax

RENAME TABLE [schema.]old_tablename TO [schema.]new_tablename 

Description

Use RENAME TABLE to rename an existing table. A table cannot be renamed if it is referenced by another database object, such as a view, stored procedure or function.

Parameters

Note: If provided, schema must be the same for old_tablename and new_tablename. Tables cannot be moved between schemas.

Example

RENAME TABLE table1 TO table2;
 
/* cannot rename table that is referenced in another database object */
USE SCHEMA1;
CREATE TABLE table_in_view (column1 string, column2 string);
CREATE VIEW vw_view AS SELECT column2 from table_in_view;
RENAME TABLE table_in_view TO no_table_rename;
/* ERROR: can't rename table SCHEMA1.TABLE_IN_VIEW -- referenced in view 
 * for SCHEMA1.VW_VIEW */