欢迎投稿

今日深度:

Sqlite数据库的字段添加或改名,sqlite数据库字段

Sqlite数据库的字段添加或改名,sqlite数据库字段


在sqlite中alter table 是可以对字段的添加的,但是无法删除字段,sqlite中alter table只实现部分的标准alter table功能。这也是轻量级的数据库实现目录吧。

如:ALTER TABLE table_name drop column_name这个语句在sqlite中无效

对于这问题,sqlite官方给出这样的解答,基本就是只能通过创建一张临时表,来修改字段

(11) How do I add or delete columns from an existing table in SQLite.

SQLite has limited ALTER TABLE support that you can use to add a column to the end of a table or to change the name of a table. If you want to make more complex changes in the structure of a table, you will have to recreate the table. You can save existing data to a temporary table, drop the old table, create the new table, then copy the data back in from the temporary table.

For example, suppose you have a table named "t1" with columns names "a", "b", and "c" and that you want to delete column "c" from this table. The following steps illustrate how this could be done:

BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t1_backup(a,b);
INSERT INTO t1_backup SELECT a,b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(a,b);
INSERT INTO t1 SELECT a,b FROM t1_backup;
DROP TABLE t1_backup;
COMMIT;

www.htsjk.Com true http://www.htsjk.com/SQLite/28882.html NewsArticle Sqlite数据库的字段添加或改名,sqlite数据库字段 在sqlite中alter table 是可以对字段的添加的,但是无法删除字段,sqlite中alter table只实现部分的标准alter table功能。这也是轻量级的数据库...
相关文章
    暂无相关文章
评论暂时关闭