问题描述
我需要重命名SQLite数据库中某些表中的几列。
我知道
示例:
创建表选项卡AS SELECT 1 AS c;
SELECT * FROM选项卡;
ALTER TABLE选项卡将列c重命名为c_new;
SELECT * FROM选项卡;
Android支持
撰写本文时, 。
基于Android使用的当前版本而且此更新即将在SQLite 3.25.0版中发布,我想您需要等待一段时间(大约API 33),然后才能将此支持添加到Android。
即使这样,如果您需要支持API 33之前的任何版本,您将无法使用它。
I would need to rename a few columns in some tables in a SQLite database.I know that a similar question has been asked on stackoverflow previously, but it was for SQL in general, and the case of SQLite was not mentioned.
From the SQLite documentation for ALTER TABLE, I gather that it's not possible to do such a thing "easily" (i.e. a single ALTER TABLE statement).
I was wondering someone knew of a generic SQL way of doing such a thing with SQLite.
This was just fixed with 2018-09-15 (3.25.0)
You can find the new syntax documented under ALTER TABLE
Example:
CREATE TABLE tab AS SELECT 1 AS c;
SELECT * FROM tab;
ALTER TABLE tab RENAME COLUMN c to c_new;
SELECT * FROM tab;
Android Support
As of writing, Android's API 27 is using SQLite package version 3.19.
Based on the current version that Android is using and that this update is coming in version 3.25.0 of SQLite, I would say you have bit of a wait (approximately API 33) before support for this is added to Android.
And, even then, if you need to support any versions older than the API 33, you will not be able to use this.
这篇关于如何重命名SQLite数据库表中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!