In this article we will show how to drop an existing column in a table created in the
DROP COLUMN keyword drops an existing column from an SQLite table. To drop a column, use the
ALTER TABLE command followed by the DROP COLUMN keyword. To understand better, follow the DROP COLUMN syntax below.
Dropping a column from an SQLite table using the DROP COLUMN command only works if the column is not a
PRIMARY KEY, the column is not used in a
FOREIGN KEY constraint, the column does not have a
Here is the syntax of SQLite DROP COLUMN:
ALTER TABLE table_name DROP COLUMN column_name;
The first step is to write the
ALTER TABLE command, followed by the table name.
In the second step, the keyword
DROP COLUMN is used, followed by the name of the column to be deleted from the table.
The example below shows how to delete an existing column from 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, DESCRIPTION TEXT ); ALTER TABLE courses DROP COLUMN DESCRIPTION;