Advanced2026-11-097 min read

How to Rename a Column in SQL (PostgreSQL, MySQL, SQL Server, SQLite, Oracle)

To rename a column in SQL, use ALTER TABLE table_name RENAME COLUMN old_name TO new_name;. That exact statement works in PostgreSQL, MySQL 8.0 and later, MariaDB 10.5.2 and later, SQLite 3.25.0 and later, and Oracle. SQL Server is the exception: it uses the stored procedure EXEC sp_rename 'schema.table.old_name', 'new_name', 'COLUMN';.

Renaming the column is the easy part. The part that bites is everything that refers to it: views, stored procedures, triggers and application queries. This guide gives the syntax for each database, then covers what each one updates for you and what it leaves broken. The SQLite examples were run on SQLite 3.51; the others are taken from each vendor's current documentation.

Syntax by database

DatabaseStatement
PostgreSQLALTER TABLE t RENAME COLUMN old TO new;
MySQL 8.0+ALTER TABLE t RENAME COLUMN old TO new;
MySQL 5.7 and olderALTER TABLE t CHANGE old new <full column definition>;
MariaDB 10.5.2+ALTER TABLE t RENAME COLUMN old TO new;
SQLite 3.25.0+ALTER TABLE t RENAME COLUMN old TO new;
OracleALTER TABLE t RENAME COLUMN old TO new;
SQL Server / Azure SQLEXEC sp_rename 'dbo.t.old', 'new', 'COLUMN';

PostgreSQL

ALTER TABLE customers RENAME COLUMN fname TO first_name;

The COLUMN keyword is optional in PostgreSQL, so ALTER TABLE customers RENAME fname TO first_name; does the same. ALTER TABLE IF EXISTS skips the statement when the table is missing, but there is no IF EXISTS for the column itself. The rename is a catalog change only; PostgreSQL's documentation notes it has no effect on the stored data, so it is fast even on large tables.

MySQL 8.0 and later

ALTER TABLE customers RENAME COLUMN fname TO first_name;

RENAME COLUMN changes only the name and keeps the type, default, nullability and comment. You can rename several columns in one statement, and even swap two names:

ALTER TABLE t1 RENAME COLUMN a TO b,
               RENAME COLUMN b TO a;

MySQL 5.7 and older: CHANGE

Older MySQL versions have no RENAME COLUMN. Use CHANGE, which renames and redefines the column at the same time, so you must repeat the full definition:

ALTER TABLE customers CHANGE fname first_name VARCHAR(100) NOT NULL DEFAULT '';

Anything you leave out of the definition is dropped: if the column was NOT NULL with a default and you write only VARCHAR(100), it becomes nullable with no default. Copy the current definition from SHOW CREATE TABLE customers; first.

SQL Server: sp_rename

SQL Server has no ALTER TABLE ... RENAME COLUMN. Use the system procedure:

EXEC sp_rename 'dbo.customers.fname', 'first_name', 'COLUMN';

Three details matter:

  1. The first argument is schema.table.column (or table.column), in quotes.
  2. The second argument is just the new column name. Don't write 'dbo.customers.first_name', or the column will literally be named that.
  3. The third argument 'COLUMN' tells SQL Server what kind of object it is renaming.

SQL Server prints a caution that changing any part of an object name can break scripts and stored procedures. That message is expected; the rename has still happened. The same procedure works in Azure SQL Database and Azure SQL Managed Instance. In Azure Synapse dedicated SQL pools, column rename through sp_rename is in preview, and in Microsoft Fabric's SQL analytics endpoint tables and columns can't be renamed at all.

In SQL Server Management Studio you can also rename a column by expanding the table in Object Explorer, opening the Columns folder and renaming the column there. It has the same effect on dependent objects as sp_rename.

SQLite 3.25.0 and later

ALTER TABLE customers RENAME COLUMN fname TO first_name;

As in PostgreSQL, the COLUMN keyword is optional. SQLite versions before 3.25.0 (released in 2018) can't rename columns; the workaround there is to create a new table with the right names, copy the data across, drop the old table and rename the new one. Check your version with SELECT sqlite_version();.

Oracle

ALTER TABLE customers RENAME COLUMN fname TO first_name;

Oracle doesn't allow combining a column rename with other column changes in the same statement, and you can't rename a column used to define a join index.

What happens to views, indexes and procedures

This is where databases differ the most.

DatabaseIndexes, constraintsViewsProcedures, triggers
PostgreSQLUpdatedKeep workingPL/pgSQL bodies are not rewritten
MySQLIndexes and foreign keys updatedNot updated, must be fixedNot updated, must be fixed
SQLiteUpdatedUpdatedTriggers updated
OracleFunction-based indexes and check constraints stay validInvalidated, revalidated on next useInvalidated, may need editing
SQL ServerUpdatedNot updatedNot updated

A few notes on that table:

  • PostgreSQL stores views by internal column reference, so a view on the table keeps working after the rename. The view's own output column keeps its old name until you recreate the view. PL/pgSQL functions store their body as text, so a function that mentions the old column name fails the next time it runs.
  • MySQL's manual says it automatically renames indexes and foreign keys that refer to the renamed column, but not views, stored programs, generated column expressions or partition expressions. Generated columns must be redefined in the same ALTER TABLE statement as the rename.
  • SQLite rewrites the schema text, so indexes, views and triggers that mention the column are updated in place. Running .schema after a rename shows the view now selecting first_name.
  • Oracle marks dependent views, triggers, functions, procedures and packages invalid. It tries to recompile them the next time they are used; if a body refers to the old name explicitly, recompilation fails and you must edit it. A column-level data grant on the renamed column also becomes invalid.
  • SQL Server's documentation is explicit that renaming a column doesn't rename references to it. Before renaming, list what depends on the table with sys.sql_expression_dependencies, and afterwards refresh non-schema-bound views that use SELECT * with sp_refreshview.

Whatever the database, the rename does not touch your application code, reports, ETL jobs or ORM models. Search your codebase for the old name before you run it.

Renaming a column in a query only: aliases

Often you don't want to change the table at all, only the column heading in a result. Use an alias with AS:

SELECT fname AS first_name,
       lname AS "Last Name"
FROM customers;

An alias exists only for that query. It renames the output column, not the stored one, so nothing else is affected. Use double quotes (or backticks in MySQL, square brackets in SQL Server) when the alias contains spaces or capitals you want to keep. AS is optional for column aliases in most databases, but writing it makes the intent obvious.

If many queries need the new name but the table can't change yet, a view can provide it:

CREATE VIEW customers_v AS
SELECT id, fname AS first_name, email
FROM customers;

Renaming a column safely in production

On a live system where code is deployed separately from the database, a rename breaks every running query that still uses the old name. The usual zero-downtime pattern is expand and contract:

  1. Add the new column, or create a view that exposes the new name.
  2. Change the application to write both and read the new one.
  3. Backfill the new column from the old one.
  4. Deploy code that uses only the new name.
  5. Drop the old column.

For smaller systems, a plain RENAME COLUMN inside a deploy that also ships the code change is fine. Test the migration on a copy of the database first, and keep the reverse statement ready (RENAME COLUMN new_name TO old_name).

Choosing the new name is worth a moment too. Lowercase snake_case without spaces avoids quoting forever; our naming conventions guide explains the trade-offs between snake_case, camelCase and kebab-case. If you are renaming columns in a DataFrame rather than a table, see rename columns in pandas or rename columns in R.

Frequently Asked Questions

What is the SQL command to rename a column?

ALTER TABLE table_name RENAME COLUMN old_name TO new_name; works in PostgreSQL, MySQL 8.0+, MariaDB 10.5.2+, SQLite 3.25.0+ and Oracle. In SQL Server, use EXEC sp_rename 'schema.table.old_name', 'new_name', 'COLUMN'; instead.

How do I rename a column in MySQL 5.7?

MySQL 5.7 doesn't support RENAME COLUMN. Use ALTER TABLE t CHANGE old_name new_name followed by the column's full definition, for example VARCHAR(100) NOT NULL. Copy the definition from SHOW CREATE TABLE first, because anything you omit, such as NOT NULL or a default, is removed.

Why doesn't ALTER TABLE RENAME COLUMN work in SQL Server?

SQL Server's T-SQL has no RENAME COLUMN clause. Column renames go through the sp_rename system procedure: EXEC sp_rename 'dbo.table.old_name', 'new_name', 'COLUMN'. Give only the bare new name as the second argument.

Does renaming a column lose data?

No. In every major database a rename changes only the column's name in the catalog; the stored values, type and constraints stay the same. The risk is in objects that refer to the column by name, such as views, procedures and application queries, which may stop working.

What is the difference between renaming a column and using an alias?

ALTER TABLE ... RENAME COLUMN permanently changes the column name in the table for everyone. An alias, written SELECT old_name AS new_name, only changes the heading in that one query's result and leaves the table untouched.

Will renaming a column break my views?

It depends on the database. SQLite updates views automatically and PostgreSQL views keep working. MySQL and SQL Server leave views referring to the old name, so they must be recreated. Oracle invalidates them and recompiles on next use, which fails if the view names the old column.

Ready to organize your files?

Try AI renaming right away. No sign-up needed until you download.

Try It Free