SQLite Rename Column

In this article we will show how to RENAME an existing column in a table created in the SQLite database.

The SQLite RENAME COLUMN TO keyword changes the name of the existing column with a new name. To rename a column, use the ALTER TABLE command followed by the RENAME COLUMN TO keyword. To better understand, follow the RENAME COLUMN TO syntax below.

Syntax

Here is the syntax of SQLite RENAME COLUMN TO:

ALTER TABLE table_name 
RENAME COLUMN old_column_name TO new_column_name;

The first step is to write the command ALTER TABLE, followed by the name of the table.

The second step, write the keyword RENAME COLUMN followed by the name of the column to be renamed.

The last step is to write the keyword TO followed by the new name of the column.

Example

The example below shows how to rename an existing column in an SQLite table.

CREATE TABLE courses
(
ID 	INTEGER PRIMARY KEY NOT NULL,
NAME 	VARCHAR(100) NOT NULL UNIQUE,
PRICE 	INTEGER NOT NULL,
DISCOUNT INTEGER NOT NULL DEFAULT 0,
COMMENTS TEXT
);

ALTER TABLE courses 
RENAME COLUMN COMMENTS TO DESCRIPTION;