sqlite--创建表,销毁表,修改表结构,sqlite--销毁
创建表: creat table <table_name>(field type,field type..); 销毁表:
drop <table_name>; 修改表结构: (添加列,专业一点说就是,往表中添加新字段)
alter table <table_name> add column <field>;
------------------------------------------------------------- 注意:(来自网络) 今天在做数据库升级时,碰到要对原来数据库中一张表的一个字段名进行修改,但是用: alter table tablename rename column oldColumnName to newColumnName; 始终不成功,后面查阅相关信息: SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table. It is not possible to rename a column, remove a column, or add or remove constraints from a table. sqlite支持一个更改表内容的有限子集,就是说在sqlite更改表的命令中,只允许用户重命名表名或者增加多一个列到一个的表中。而重命名一个字段名和删除一个字段、或者增加和删除系统规定的参数这些操作是不可能的。
解决办法: 例如:在上面的操作过程中,我们在people表中新添加了一个字段addr,要删除这个字段,直接用sqlite的语句时无法完成的。 我们可以这样干: A.将people表重命名为temp; B.重新创建people表; C.将temp表中的相应字段内容复制到people表中。 D.删除temp表
操作如下: A.alter table people rename to temp; B.create table people(id,name,age); C.insert into people select id,name,age from temp;
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。