Sqlite将列添加到表中的特定位置(Android) [英] Sqlite Add Column into table at a certain position (Android)

查看:596
本文介绍了Sqlite将列添加到表中的特定位置(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是用于添加列的代码.

This is the code that works for adding a column.

mDb.execSQL("ALTER TABLE " + table_name + 
            " ADD COLUMN " + column_name + " text");

我的问题是,该列是在表的最后一个位置创建的.

My problem the column is created at the last position of the table.

Column1|Column2|Column3|Column4|Column5|NewAddedColumn6

例如可以在Column3Column4 ???

E.g. Is is possible to add a column between Column3 and Column4???

Column1|Column2|Column3|NewAddedColumn6|Column4|Column5

推荐答案

根据文档

ADD COLUMN语法用于将新列添加到现有列 桌子.新列始终附加在列表的末尾 现有列.

The ADD COLUMN syntax is used to add a new column to an existing table. The new column is always appended to the end of the list of existing columns.

因此,您的问题的答案是 NO

Hence, answer to your question is NO

但是,有一种解决方法.
阅读此 SO上的答案 .

But, there is a work around way.
Read this answer on SO.

参考: SQLite:ALTER TABLE:添加列

这篇关于Sqlite将列添加到表中的特定位置(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆