21

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.

leba-lev
  • 2,788
  • 10
  • 33
  • 43

1 Answers1

48

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.

Benoit
  • 76,634
  • 23
  • 210
  • 236
  • 1
    `DROP COLUMN` is supported in recent releases of Sqlite - see [this answer](https://stackoverflow.com/a/66399224/5320906) – snakecharmerb May 22 '21 at 14:52