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

ALTER TABLE users
RENAME COLUMN usr_name TO username;

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

ALTER TABLE users
CHANGE usr_name username VARCHAR(100);

PostgreSQL

ALTER TABLE users
RENAME COLUMN usr_name TO 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:

CREATE TABLE users (
  id INT PRIMARY KEY,
  usr_name VARCHAR(100)
);

Rename the column:

ALTER TABLE users
RENAME COLUMN usr_name TO username;

The table structure is clearer.

Example 2: Standardize naming conventions

You want all foreign keys to end with _id.

ALTER TABLE orders
RENAME COLUMN cust TO customer_id;

Now the column matches your naming rules.

Example 3: Update a timestamp field

You originally used a vague name:

ALTER TABLE posts
RENAME COLUMN created TO 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:

ALTER TABLE users
RENAME usr_name TO username;

Why it fails: Most systems require RENAME COLUMN.

Correct approach:

ALTER TABLE users
RENAME COLUMN usr_name TO 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:

ALTER TABLE users
RENAME COLUMN email TO 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