SQLite Rename Column: Syntax, Examples, and Limits

To rename a column in SQLite, use ALTER TABLE with RENAME COLUMN. The statement changes the column name in the table definition while preserving its stored values and updating references in dependent schema objects.

In this piece, I’ll walk through the rename and show how to check that the new name appears in the table definition.

TL;DR: Rename a Column with ALTER TABLE

Use ALTER TABLE table_name RENAME COLUMN old_name TO new_name to change a column’s name while keeping its data.

  • SQLite 3.25.0 and later support RENAME COLUMN.
  • SQLite updates references in indexes, triggers, and views.
  • Use a table rebuild for changes beyond renaming, such as changing a column’s type.

What Does SQLite Column Renaming Change?

A column rename changes the identifier in the table definition, not the stored values. SQLite also updates schema objects that refer to the column, including indexes, triggers, views, and foreign-key definitions.

SQLite stores schema definitions in sqlite_schema as SQL text. An ALTER TABLE rename changes that definition and reparses the schema, which lets SQLite update dependent objects within the same operation.

I tested the operation with a row, an index, a trigger, and a view. The database does not need to copy every row for a name-only change.

This differs from a type change, which requires rebuilding the table and copying its data. A rebuild takes more care because the replacement must preserve constraints and dependent objects. Verify the new schema and sample rows before committing the migration.

How to Rename a Column in SQLite Step by Step

Run ALTER TABLE with the table name, current column name, and replacement name. This in-memory Python example avoids changing a database file.

Step 1: Create a table and rename its column

Save this as rename_column_demo.py. It creates dependent objects, inserts a row, and renames old_name to display_name.

import sqlite3

connection = sqlite3.connect(":memory:")
connection.executescript("""
CREATE TABLE users (id INTEGER PRIMARY KEY, old_name TEXT);
CREATE INDEX idx_users_old_name ON users(old_name);
CREATE VIEW user_names AS SELECT old_name FROM users;
CREATE TRIGGER users_insert AFTER INSERT ON users
BEGIN SELECT NEW.old_name; END;
INSERT INTO users (old_name) VALUES ('Ada');
ALTER TABLE users RENAME COLUMN old_name TO display_name;
""")
print("columns:", [row[1] for row in connection.execute("PRAGMA table_info(users)")])
print("rows:", connection.execute("SELECT id, display_name FROM users").fetchall())
print("view:", connection.execute("SELECT * FROM user_names").fetchall())
for name in ("idx_users_old_name", "users_insert", "user_names"):
    print(name + ":", connection.execute("SELECT sql FROM sqlite_schema WHERE name = ?", (name,)).fetchone()[0])
python3 rename_column_demo.py
rows: [(1, 'Ada')]
view: [('Ada',)]
idx_users_old_name: CREATE INDEX idx_users_old_name ON users(display_name)
users_insert: CREATE TRIGGER users_insert AFTER INSERT ON users
BEGIN SELECT NEW.display_name; END
user_names: CREATE VIEW user_names AS SELECT display_name FROM users

The row and view still return Ada. The index keeps its object name, while its column reference and the trigger and view definitions now use display_name.

Step 2: Check the renamed column

Use PRAGMA table_info to confirm the new column name in the table definition. The same demo prints the column list before reading the row.

PRAGMA table_info(users);
columns: ['id', 'display_name']
rows: [(1, 'Ada')]

The schema check shows display_name in the second position, and the row still contains Ada. This check catches a migration that ran against an unexpected table or did not apply.

SQLite Rename Column Limits and Errors

SQLite 3.25.0 introduced column renaming. Check the SQLite library your application uses before running a migration. In Python, sqlite3.sqlite_version reports the linked library version.

import sqlite3
print(sqlite3.sqlite_version)

A rename can fail if updating a trigger or view would make a reference ambiguous. SQLite reports an error and applies no changes.

SQLite 3.24.x and earlier do not accept RENAME COLUMN. Upgrade the SQLite library where possible, then use the native statement. If an upgrade is not possible, treat the rename as a table rebuild rather than changing schema text directly.

  • Create the replacement table with its full constraints.
  • Copy rows with explicit source and destination columns.
  • Recreate indexes, triggers, and affected views.

Recreate the original indexes and triggers, then review views that depend on the table. Run PRAGMA foreign_key_check when foreign keys are involved.

Keep the migration in a transaction and test it on a copy first. Renaming the original table first can alter references in triggers, views, and foreign keys, so follow the documented order. See the separate guides to adding a column and dropping a column.

A name change also affects application code that refers to the old identifier. Search queries, migration scripts, and prepared statements, then update them alongside the database migration. Database schema updates cannot rewrite SQL stored outside the database.

For schema context, see the guides to SQLite views and index_list and index_info.

Conclusion: Use RENAME COLUMN for a Name Change

ALTER TABLE … RENAME COLUMN changes the name while preserving values and updating dependent schema references. Check the library version first, and plan a table rebuild when changing the structure beyond a name.

FAQ

Readers also ask about version support and dependent objects.

Which SQLite version supports renaming a column?

SQLite 3.25.0 and later support ALTER TABLE RENAME COLUMN.

Does renaming a column keep its data?

Yes. The rename changes the schema name and leaves stored values in place.

Does SQLite update indexes and views after a column rename?

SQLite updates references in indexes, triggers, and views. A rename fails without changes if it would make a trigger or view reference ambiguous.