加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

sqlite--创建表,销毁表,修改表结构

发布时间:2020-12-12 19:51:44 所属栏目:百科 来源:网络整理
导读:创建表: creat table table_name(field type,field type..); 销毁表: drop table_name; 修改表结构: (添加列,专业一点说就是,往表中添加新字段) alter table table_name add column field; --------------------------------------------------------

创建表: 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,age from temp;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读