由于项目需求变更,我需要在sqlite的表中删除一个字段,通用的sql操作语句如下:

alter table task drop column custom_fields; 

结果数据库提示如下错误:

sqlite> ALTER TABLE task DROP COLUMN custom_fields; 
Error: near "DROP": syntax error

搜索得知,原来SQLite目前还不支持drop column,所以必须想出另外一种方法来进行表字段的删除。

如下sql语句会复制一个和record表一样表结构的temp表出来,但是我们想要的是去除某一个字段(例如去除record表中的name字段,就不要复制它就好了),所以sql语句如下:

create table temp as select id, name, type, trigger, state, next_run_time, description, failed_times, scheduler from task where 1 = 1;

这样复制出来的表就会缺少“custom_fields”字段,然后我们删除旧表并修改新表名即可。

drop table task;  
alter table temp rename to task;

 

相关文章:

  • 2021-12-21
  • 2021-11-30
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2022-12-23
  • 2021-12-31
  • 2021-06-16
  • 2022-01-24
  • 2022-02-07
  • 2022-02-14
  • 2022-12-23
相关资源
相似解决方案