Change Name Of A Column In Sql

6 min read

Change name of a column in sql is a common task that database administrators and developers encounter when evolving a schema, correcting typos, or aligning naming conventions with new business requirements. Renaming a column without losing data or breaking dependent objects requires the correct syntax for the specific relational database management system (RDBMS) you are using, as well as an understanding of the impact on indexes, constraints, views, stored procedures, and application code. This guide walks you through the concepts, step‑by‑step procedures for the most popular platforms, and best‑practice tips to ensure a smooth transition.


Why Rename a Column?

Before diving into the technical details, it helps to clarify the motivations behind a column rename:

  • Typo correction – A misspelled name (e.g., custmer_id instead of customer_id) can cause confusion and bugs.
  • Business terminology shift – A field once called price may need to become unit_price after a pricing model change.
  • Standardization – Teams often adopt naming conventions (snake_case, camelCase, prefixes) and need to align existing columns.
  • Schema refactoring – During database normalization or denormalization, columns may be moved or merged, prompting a rename.
  • Compliance – Regulatory changes may require more descriptive or less ambiguous column names.

Regardless of the reason, the rename operation should be performed in a controlled environment, preferably with a backup and a rollback plan.


General Syntax Across RDBMS

Although the core idea—altering a table to change a column identifier—is universal, each RDBMS implements it differently. Below is a concise comparison:

RDBMS Basic Syntax Notes
MySQL (≥ 8.In practice, 0) ALTER TABLE table_name RENAME COLUMN old_name TO new_name; Prior to 8. 0, use CHANGE COLUMN old_name new_name datatype [options];
MariaDB Same as MySQL 8.0+ Also supports CHANGE syntax. Worth adding:
PostgreSQL ALTER TABLE table_name RENAME COLUMN old_name TO new_name; Requires the column to exist; no type change allowed in the same statement. On top of that,
SQL Server EXEC sp_rename 'table_name. old_name', 'new_name', 'COLUMN'; Uses a system stored procedure; the new name must follow identifier rules.
Oracle ALTER TABLE table_name RENAME COLUMN old_name TO new_name; Available from Oracle 11g onward; earlier versions need ALTER TABLE … RENAME. In practice,
SQLite ALTER TABLE table_name RENAME COLUMN old_name TO new_name; Supported since SQLite 3. That said, 25. 0 (2018); older versions require a table recreation workaround.

Bold terms above highlight the exact keywords you will type. Italic placeholders (table_name, old_name, new_name) should be replaced with your actual identifiers But it adds up..


Step‑by‑Step Guides

Below are detailed instructions for each major platform. Each section assumes you have the necessary privileges (ALTER on the table, and for SQL Server, EXECUTE on sp_rename).

MySQL and MariaDB

  1. Verify the current definition
    SHOW COLUMNS FROM your_table LIKE 'old_name';
    
  2. Check the MySQL version (to decide between RENAME COLUMN and CHANGE COLUMN):
    SELECT VERSION();
    
  3. If version ≥ 8.0 – use the straightforward syntax:
    ALTER TABLE your_table RENAME COLUMN old_name TO new_name;
    
  4. If version < 8.0 – you must restate the data type and any attributes:
    ALTER TABLE your_table
      CHANGE COLUMN old_name new_name DATA_TYPE [NULL|NOT NULL] [DEFAULT ...] [EXTRA ...];
    
    Example:
    ALTER TABLE employees
      CHANGE COLUMN emp_id employee_id INT NOT NULL AUTO_INCREMENT;
    
  5. Validate – run SHOW COLUMNS FROM your_table LIKE 'new_name'; to confirm the change.

PostgreSQL

  1. Inspect the column (optional):
    SELECT column_name, data_type
    FROM information_schema.columns
    WHERE table_name = 'your_table' AND column_name = 'old_name';
    
  2. Execute the rename:
    ALTER TABLE your_table RENAME COLUMN old_name TO new_name;
    
  3. Check for dependent objects – PostgreSQL will automatically update references in views, indexes, and foreign keys, but you should still run:
    SELECT * FROM pg_depend WHERE refobjid = 'your_table'::regclass;
    
  4. Commit – if you are inside a transaction, issue COMMIT; or ROLLBACK; as needed.

SQL Server

  1. Backup – although sp_rename is metadata‑only, a backup is prudent.
  2. Run the rename:
    EXEC sp_rename N'your_schema.your_table.old_name', N'new_name', N'COLUMN';
    
    • The first parameter must be a fully qualified name (schema.table.column) enclosed in single quotes and prefixed with N for Unicode.
    • The third parameter 'COLUMN' tells the procedure that we are renaming a column, not an object like an index.
  3. Verify – query sys.columns:
    SELECT name FROM sys.columns
    WHERE object_id = OBJECT_ID('your_schema.your_table')
      AND name = 'new_name';
    
  4. Check dependencies – SQL Server does not automatically fix references in stored procedures or views; you may need to refresh them:
    EXEC sp_refreshview 'your_schema.your_view';
    
    For stored procedures, consider using sys.sql_expression_dependencies to locate impacted code.

Oracle

  1. Confirm privilege – you need ALTER on the table.
  2. Run the rename:
    ALTER TABLE your_table RENAME COLUMN old_name TO new_name;
    
  3. Validate – query USER_TAB_COLUMNS:
    SELECT column_name FROM user_tab_columns
    WHERE table_name = 'YOUR_TABLE' AND column_name = 'NEW_NAME';
    
  4. Recompile dependent objects – Oracle automatically marks dependent PL/SQL objects as invalid; recompile them with:
    ALTER PROCEDURE your_procedure COMPILE;
    
    Or use
ALTER TABLE your_table RENAME COLUMN old_name TO new_name;
  1. Validate – query USER_TAB_COLUMNS:
    SELECT column_name FROM user_tab_columns
    WHERE table_name = 'YOUR_TABLE' AND column_name = 'NEW_NAME';
    
  2. Recompile dependent objects – Oracle automatically marks dependent PL/SQL objects as invalid; recompile them with:
    ALTER PROCEDURE your_procedure COMPILE;
    
    Or use UTL_RECOMP to recompile all invalid objects at once:
    EXEC UTL_RECOMP.recomp_serial('YOUR_SCHEMA');
    

SQLite

  1. Check your SQLite version – native column renaming was introduced in SQLite 3.25.0 (2018-09-15).
    SELECT sqlite_version();
    
  2. If your version supports it, run:
    ALTER TABLE your_table RENAME COLUMN old_name TO new_name;
    
  3. If you are on an older version, you must recreate the table:
    BEGIN TRANSACTION;
      CREATE TABLE your_table_new (
        new_name DATA_TYPE,
        other_column DATA_TYPE,
        ...
      );
      INSERT INTO your_table_new (new_name, other_column, ...)
        SELECT old_name, other_column, ... FROM your_table;
      DROP TABLE your_table;
      ALTER TABLE your_table_new RENAME TO your_table;
    COMMIT;
    
  4. Rebuild indexes and triggers – recreating the table drops all associated indexes, triggers, and foreign keys, so you must recreate them manually.

Best Practices Across All Platforms

  • Use version control for schema changes – treat every ALTER statement as code; store it in migration scripts tracked by tools such as Flyway, Liquibase, or Alembic.
  • Test in a non-production environment first – renaming a column can cascade into application code, ORM mappings, API contracts, and reporting queries.
  • Communicate with your team – update documentation, data dictionaries, and any shared knowledge bases so downstream consumers are aware of the change.
  • Schedule during low-traffic windows – although most renames are metadata-only operations, some databases (especially older SQLite workflows) may rewrite the entire table and hold locks.
  • Document the old name temporarily – adding a comment or a deprecated synonym helps future developers understand the history of the column.

Conclusion

Renaming a database column is a routine but consequential operation that varies significantly from one RDBMS to another. MySQL uses CHANGE COLUMN or MODIFY COLUMN, PostgreSQL and Oracle offer a straightforward RENAME COLUMN clause, SQL Server relies on the system procedure sp_rename, and SQLite provides native support only from version 3.25.0 onward. Regardless of the platform, the key steps remain consistent: inspect the current state, execute the rename, verify the change, and address any dependent objects such as views, stored procedures, indexes, and foreign keys. By following the database-specific steps outlined above and adhering to the best practices of version-controlled migrations, thorough testing, and clear communication, you can check that column renames are performed safely and with minimal disruption to your overall data ecosystem.

Just Went Live

What's New Today

People Also Read

Adjacent Reads

Thank you for reading about Change Name Of A Column In Sql. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home