Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alter table drop column syntax error using sqlite

This is the schema of my table:

create table LPCG(ID integer primary key, PCG text, Desc text, test text);

I wish to drop the column "test", and hence use the command:

alter table LPCG drop column test;

This is the error message I get:

Error: near "drop": syntax error

Can someone please help me correct my error?

An additional question is: I understand that ID is the primary key attribute. Would I be able to drop that column? If not, is there a workaround which anyone has used?

Thanks in advance for any help.

like image 755
leba-lev Avatar asked Jun 07 '11 15:06

leba-lev


People also ask

How do I drop a column in SQLite?

You can not use the ALTER TABLE statement to drop a column in a table. Instead you will need to rename the table, create a new table, and copy the data into the new table.

Does SQLite support drop column?

SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows these alterations of an existing table: it can be renamed; a column can be renamed; a column can be added to it; or a column can be dropped from it.

How do I drop a column in SQLite 3?

DB Browser for SQLite allows you to add or drop columns. In the main view, tab Database Structure , click on the table name. A button Modify Table gets enabled, which opens a new window where you can select the column/field and remove it.


1 Answers

Up to version 3.35, SQLite did not support ALTER TABLE DROP COLUMN statements. You could only rename table, or add columns.

If you want to drop a column, your best option was to create a new table without the column, and to drop the old table in order to rename the new one.

As of now, ALTER TABLE support is still limited but includes dropping a column, under conditions.

like image 105
Benoit Avatar answered Sep 19 '22 11:09

Benoit