码迷,mamicode.com
首页 > 数据库 > 详细

sqlite并不支持建表后修改主键,或删除列,如果要修改,请参考如下做法

时间:2016-07-08 01:34:35      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:

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;

http://sqlite.org/faq.html#q11

http://stackoverflow.com/questions/946011/sqlite-add-primary-key

 

sqlite并不支持建表后修改主键,或删除列,如果要修改,请参考如下做法

标签:

原文地址:http://www.cnblogs.com/David-Young/p/5162017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!