[GIS] How to delete a column from the attribute table of a SpatiaLite layer

qgisspatialite

I want to delete a column from Attribute table but the function "Delete columns" isn't highlighted. (When I am adding new layers I use New SpatiaLite layer, not Shapefile layer).

So I have installed the plugin Table Manager but when I delete a column using this Table Manager the function "Save" isn't highlighted. Only "Save as" is possible. Is there any advise how I could delete a column?

Best Answer

As of QGIS 2.18, SpatiaLite layers have the "Delete Attributes" capability. (Check in Layer Properties | Metadata)


Previously:

It is not possible to directly delete a column in Sqlite and thus in SpatiaLite: http://www.sqlite.org/faq.html#q11. Therefore QGIS cannot offer this functionality. The alternative is to recreate the table.

BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t1_backup(a,b);
INSERT INTO t1_backup SELECT a,b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(a,b);
INSERT INTO t1 SELECT a,b FROM t1_backup;
DROP TABLE t1_backup;
COMMIT;