On 2 Aug 2011, at 12:03pm, Jack Hughes wrote:

> Is there a workaround for the lack of support for dropping fields? I have an 
> application and need to evolve the database schema as features are added and 
> removed. Leaving fields sitting inside the database that are no longer used 
> will lead to a schema that is difficult to understand. Especially so when the 
> field is marked as NOT NULL. Years from now I will need to supply a value for 
> a field when inserting a row that has long ago ceased to be used.
> 
> Any ideas how I can remove unused fields from the database would be 
> appreciated.

Only by doing it manually:

rename your old TABLE using ALTER TABLE ... RENAME TO ...
create a new TABLE with just the columns you want, in the order you want them
copy your data across using INSERT INTO myTable SELECT a,b,c,d FROM myOldTable
DROP the old TABLE
CREATE appropriate INDEXes for the new table

It's just four commands plus one for each index you want, though I know it's 
tedious to have to do it like that rather than all in one operation.

Note that having TRIGGERS or FOREIGN KEYS defined complicates this.  And always 
take a backup before starting anything like this !

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to