How to Rename a Column in SQL

What you’ll build or solve

You’ll modify an existing table by changing the name of one column.

When this approach works best

Renaming a column works best when you:

  • Fix unclear or inconsistent naming
  • Align database fields with updated business terminology
  • Standardize column names across multiple tables

For example, you might rename usr_name to username, change cust_id to customer_id, or update created to created_at.

This is a bad idea if application code, views, or reports still depend on the old column name and you cannot update them immediately.

Prerequisites

  • Access to the database
  • Permission to alter tables
  • Basic SQL knowledge
  • A backup if working in production

Step-by-step instructions

Step 1: Rename the column

Use the correct syntax for your database system.

MySQL

ALTERTABLE users
RENAMECOLUMN usr_nameTO username;

For older MySQL versions, use CHANGE and repeat the column definition:

ALTERTABLE users
CHANGE usr_name usernameVARCHAR(100);

PostgreSQL

ALTERTABLE users
RENAMECOLUMN usr_nameTO username;

SQL Server

EXEC sp_rename'users.usr_name','username','COLUMN';

Each command changes only the column name. The data remains unchanged.

What to look for

  • The table name must be correct
  • The new column name must not already exist
  • Views, triggers, and stored procedures may still reference the old name
  • Application code must be updated

Examples you can copy

Example 1: Improve readability

You created a table with short names:

CREATETABLE users (
  idINTPRIMARYKEY,
  usr_nameVARCHAR(100)
);

Rename the column:

ALTERTABLE users
RENAMECOLUMN usr_nameTO username;

The table structure is clearer.

Example 2: Standardize naming conventions

You want all foreign keys to end with _id.

ALTERTABLE orders
RENAMECOLUMN custTO customer_id;

Now the column matches your naming rules.

Example 3: Update a timestamp field

You originally used a vague name:

ALTERTABLE posts
RENAMECOLUMN createdTO created_at;

The new name makes the column’s purpose clearer.

Common mistakes and how to fix them

Mistake 1: Using the wrong syntax for your database

What you might do:

ALTERTABLE users
RENAME usr_nameTO username;

Why it fails: Most systems require RENAME COLUMN.

Correct approach:

ALTERTABLE users
RENAMECOLUMN usr_nameTO username;

Or use sp_rename in SQL Server.

Mistake 2: Forgetting to update dependent objects

What you might do: Rename the column but leave views or procedures unchanged.

Why it breaks: Queries referencing the old column name will fail.

Correct approach: Search for the old name and update dependent database objects and application code.

Mistake 3: Renaming to an existing column name

What you might do:

ALTERTABLE users
RENAMECOLUMN emailTO username;

Why it fails: If username already exists, the database returns an error.

Correct approach: Check existing columns first:

DESCRIBE users;

Choose a name that does not conflict.

Troubleshooting

  • If you see “permission denied,” confirm you have ALTER privileges.
  • If you see “column does not exist,” verify the exact column name and case sensitivity.
  • If SQL Server reports an error with sp_rename, confirm you included the table name and 'COLUMN' parameter.
  • If queries fail after renaming, update all references to the old column name.

Quick recap

  • Use ALTER TABLE ... RENAME COLUMN in MySQL and PostgreSQL
  • Use sp_rename in SQL Server
  • Data remains intact after renaming
  • Update dependent objects and application code
  • Check for naming conflicts before running the command