因为项目需求变动,我须要在sqlite的表中删除一个字段,通用的sql操做语句以下:sql
alter table task drop column custom_fields;
结果数据库提示以下错误:数据库
sqlite> ALTER TABLE task DROP COLUMN custom_fields; Error: near "DROP": syntax error
搜索得知,原来SQLite目前还不支持drop column,因此必须想出另一种方法来进行表字段的删除。spa
以下sql语句会复制一个和record表同样表结构的temp表出来,可是咱们想要的是去除某一个字段(例如去除record表中的name字段,就不要复制它就行了),因此sql语句以下:code
create table temp as select id, name, type, trigger, state, next_run_time, description, failed_times, scheduler from task where 1 = 1;
这样复制出来的表就会缺乏“custom_fields”字段,而后咱们删除旧表并修改新表名便可。sqlite
drop table task; alter table temp rename to task;