SQL Keywords

SQL RENAME

What is SQL RENAME?

RENAME changes the name of an existing table, column, index, or other database object without recreating it.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL RENAME: PostgreSQL, MySQL, MariaDB, SQL Server (via sp_rename), Oracle, SQLite (3.25+).

SQL RENAME Full Explanation

RENAME is implemented in most databases through the ALTER statement, allowing you to change an object's identifier while preserving its data, constraints, permissions, and dependent objects. In PostgreSQL and many other systems the feature is exposed as ALTER TABLE ... RENAME, ALTER INDEX ... RENAME, and similar clauses. Some engines (MySQL) also offer a dedicated RENAME TABLE command, while SQL Server exposes the functionality through the stored procedure sp_rename. Renaming is metadata-only and completes instantly because no data pages are rewritten. However, objects that reference the old name (views, stored procedures, application code) are not updated automatically, so you must refactor them manually. In transactional databases the rename is atomic and can be rolled back inside a transaction block. Not every object type is renameable in every engine, and there can be restrictions (for example SQLite cannot rename a column before version 3.25).

SQL RENAME Syntax

-- Table
ALTER TABLE old_table_name RENAME TO new_table_name;

-- Column
ALTER TABLE table_name RENAME COLUMN old_column TO new_column;

-- Index
ALTER INDEX old_index_name RENAME TO new_index_name;

-- MySQL shortcut
RENAME TABLE old_table_name TO new_table_name;

SQL RENAME Parameters

  • old_table_name (identifier) - Current name of the table
  • new_table_name (identifier) - Desired new table name
  • old_column (identifier) - Current column name
  • new_column (identifier) - Desired new column name
  • old_index_name (identifier) - Current index name
  • new_index_name (identifier) - Desired new index name

Example Queries Using SQL RENAME

-- Rename a table
ALTER TABLE orders RENAME TO customer_orders;

-- Rename a column
ALTER TABLE customer_orders RENAME COLUMN total TO total_amount;

-- Rename an index
ALTER INDEX orders_created_at_idx RENAME TO customer_orders_created_at_idx;

-- MySQL syntax
RENAME TABLE temp_users TO users_archive;

Expected Output Using SQL RENAME

  • Each statement updates the system catalog
  • The object immediately appears under its new name, and the old name becomes invalid
  • No rows are touched and queries using the old name will fail unless updated

Use Cases with SQL RENAME

  • Refactor legacy schemas without data migration.
  • Align table and column names with new business terminology.
  • Eliminate naming typos discovered after deployment.
  • Prepare for deprecating objects while maintaining historical data.

Common Mistakes with SQL RENAME

  • Forgetting to update dependent views or code, leading to runtime errors.
  • Attempting to rename to a name that already exists, which raises an error.
  • Omitting the COLUMN keyword in PostgreSQL (required).
  • Assuming the operation rewrites data; it is metadata-only.
  • Expecting SQLite versions before 3.25 to support column rename.

Related Topics

ALTER TABLE, ALTER INDEX, DROP TABLE, CREATE TABLE, TRUNCATE

First Introduced In

PostgreSQL 7.3 (2002)

Frequently Asked Questions

How do I rename a column in SQL?

Use ALTER TABLE table_name RENAME COLUMN old_column TO new_column; in PostgreSQL, MySQL 8+, and SQLite 3.25+. In SQL Server call sp_rename 'table.old_column', 'new_column', 'COLUMN'.

Does renaming a table lock it?

The command changes only metadata. A short catalog lock is taken, but data is not rewritten. The statement completes almost instantly unless blocked by other DDL.

Can I roll back a RENAME operation?

In databases with transactional DDL (PostgreSQL, Oracle, SQL Server) you can wrap the rename in BEGIN ... ROLLBACK or COMMIT. Rolling back restores the original name.

Is RENAME standard SQL?

ALTER TABLE ... RENAME TO is defined in modern SQL standards, but vendor implementations vary. MySQL provides RENAME TABLE, while SQL Server offers sp_rename.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!