user8833244
user8833244

Reputation: 1

Sqlite Dropping Column from table

Why sqlite database has the limitation of "not to drop a column from a table" in a single command? Are there any chances it would be added in future versions?

Upvotes: 0

Views: 9371

Answers (4)

Matt Reimer
Matt Reimer

Reputation: 106

ALTER TABLE DROP COLUMN is now supported, as of 3.35.0 which was released 2021-03-12.

Upvotes: 4

Felix J
Felix J

Reputation: 101

http://www.sqlite.org/faq.html#q11

SQLite has limited ALTER TABLE support that you can use to add a column to the end of a table or to change the name of a table. If you want to make more complex changes in the structure of a table, you will have to recreate the table. You can save existing data to a temporary table, drop the old table, create the new table, then copy the data back in from the temporary table.

So you can't just delete the column

Upvotes: 0

CL.
CL.

Reputation: 180280

The ALTER TABLE statement supports exactly those operations that can be implemented easily without having to rewrite the entire table. (When adding a new column, that value is missing in all rows; it gets replaced with the column's default value when read.)

The ability to drop columns (or other things, like reordering columns) would add lots of complex code to the SQLite library. However, SQLite is designed as an embedded database, so it must take care to conserve resources. It is very unlikely that such a large amount of code will ever be added.

Upvotes: 0

gi097
gi097

Reputation: 7721

SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table. It is not possible to rename a column, remove a column, or add or remove constraints from a table.

https://sqlite.org/lang_altertable.html

No, you can't.

Are there any chances it would be added in future versions?

Well, we can't tell you that. And even if they will add it, there are still a lot of Android devices out there which have an older version of SQLite without that feature.

However, you can delete a column like this from this answer:

https://stackoverflow.com/a/5987838/5457878

Upvotes: 1

Related Questions