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_idinstead ofcustomer_id) can cause confusion and bugs. - Business terminology shift – A field once called
pricemay need to becomeunit_priceafter 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
- Verify the current definition
SHOW COLUMNS FROM your_table LIKE 'old_name'; - Check the MySQL version (to decide between
RENAME COLUMNandCHANGE COLUMN):SELECT VERSION(); - If version ≥ 8.0 – use the straightforward syntax:
ALTER TABLE your_table RENAME COLUMN old_name TO new_name; - If version < 8.0 – you must restate the data type and any attributes:
Example:ALTER TABLE your_table CHANGE COLUMN old_name new_name DATA_TYPE [NULL|NOT NULL] [DEFAULT ...] [EXTRA ...];ALTER TABLE employees CHANGE COLUMN emp_id employee_id INT NOT NULL AUTO_INCREMENT; - Validate – run
SHOW COLUMNS FROM your_table LIKE 'new_name';to confirm the change.
PostgreSQL
- Inspect the column (optional):
SELECT column_name, data_type FROM information_schema.columns WHERE table_name = 'your_table' AND column_name = 'old_name'; - Execute the rename:
ALTER TABLE your_table RENAME COLUMN old_name TO new_name; - 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; - Commit – if you are inside a transaction, issue
COMMIT;orROLLBACK;as needed.
SQL Server
- Backup – although
sp_renameis metadata‑only, a backup is prudent. - 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 withNfor Unicode. - The third parameter
'COLUMN'tells the procedure that we are renaming a column, not an object like an index.
- The first parameter must be a fully qualified name (
- Verify – query
sys.columns:SELECT name FROM sys.columns WHERE object_id = OBJECT_ID('your_schema.your_table') AND name = 'new_name'; - Check dependencies – SQL Server does not automatically fix references in stored procedures or views; you may need to refresh them:
For stored procedures, consider usingEXEC sp_refreshview 'your_schema.your_view';sys.sql_expression_dependenciesto locate impacted code.
Oracle
- Confirm privilege – you need
ALTERon the table. - Run the rename:
ALTER TABLE your_table RENAME COLUMN old_name TO new_name; - Validate – query
USER_TAB_COLUMNS:SELECT column_name FROM user_tab_columns WHERE table_name = 'YOUR_TABLE' AND column_name = 'NEW_NAME'; - Recompile dependent objects – Oracle automatically marks dependent PL/SQL objects as invalid; recompile them with:
Or useALTER PROCEDURE your_procedure COMPILE;
ALTER TABLE your_table RENAME COLUMN old_name TO new_name;
- Validate – query
USER_TAB_COLUMNS:SELECT column_name FROM user_tab_columns WHERE table_name = 'YOUR_TABLE' AND column_name = 'NEW_NAME'; - Recompile dependent objects – Oracle automatically marks dependent PL/SQL objects as invalid; recompile them with:
Or useALTER PROCEDURE your_procedure COMPILE;UTL_RECOMPto recompile all invalid objects at once:EXEC UTL_RECOMP.recomp_serial('YOUR_SCHEMA');
SQLite
- Check your SQLite version – native column renaming was introduced in SQLite 3.25.0 (2018-09-15).
SELECT sqlite_version(); - If your version supports it, run:
ALTER TABLE your_table RENAME COLUMN old_name TO new_name; - 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; - 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
ALTERstatement 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.