ALTER TABLE in SQLite

前端之家收集整理的这篇文章主要介绍了ALTER TABLE in SQLite前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

ALTER TABLE in sqlite


SQLite不支持通过ALTER TABLE命令对表结构进行修改,例如添加删除字段,原始说明如下:

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

SQLite has limitedALTER TABLEsupport 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:

@H_403_28@
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;
原文链接:https://www.f2er.com/sqlite/200690.html

猜你在找的Sqlite相关文章