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

SQLite Expert表分离和解决SQLite Expert删除表后大小不变的问题

时间:2017-07-12 11:09:16      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:bsp   之间   div   java代码   select   java   没有   http   mod   

    最后要使用到号码归属地的查询,在网上找到一个数据库文件。大小有12M多,压缩成zip也有1.9M,这样对于一个apk的大小非常不利,后来看了一下数据库的内容,发现有非常多冗余。特别是中文字符占用非常大的空间,在网上找了一种方法把一个表进行分离。分成两个表,两个表之间能够使用外键的形式进行关联。这里用到的几个表名:tb_city、mob_location、tb_mobile,终于是要把表mob_location分离成tb_city、tb_mobile在SQLite Expert上能够使用sql语句,这里仅仅讲一些我觉得关键的部分,如创建表、新建字段打开数据库、设置主键、外键这些都不讲,对于SQLite Expert一点都不懂的朋友能够先百度下怎样使用。把查询到的数据插入到指定表中。去掉反复的

insert into tb_city(location, areacode) select location, areacode from mob_location group by location

同一时候查询两个表
select * from tb_city, mob_location where tb_city.[location] = mob_location.[location]

select * from tb_city, tb_mobile where tb_city.[_id] = tb_mobile.[foreign_id] and tb_mobile.[number] = 1342797
以上语句在java代码中也是适用的,如代码中使用:
String sql = "select * from tb_city, tb_mobile where tb_city.[_id] = tb_mobile.[foreign_id] and tb_mobile.[number] = " + num;

把两个表查询得到的数据插入到一个表中
insert into tb_mobile(foreign_id, number) select tb_city.[_id], mob_location.[_id] from tb_city, mob_location where tb_city.[location] = mob_location.[location]

到这里就把表mob_location分离成tb_city、tb_mobile了,此时看下数据库大小为16M,就把表mob_location右键删除,但发现数据库的大小没有不论什么改变。后来查出来删除仅仅是把它放到缓存。并没有清空,须要在数据库上右键->vacuum,点击清空,再去看下大小就仅仅有3M多一点,这样容量少了非常多,再做下zip压缩,但压缩的效果不是非常理想。

数据库和代码能够到下面链接下载:

http://pan.baidu.com/s/1sjFWJRv


SQLite Expert表分离和解决SQLite Expert删除表后大小不变的问题

标签:bsp   之间   div   java代码   select   java   没有   http   mod   

原文地址:http://www.cnblogs.com/yxysuanfa/p/7154291.html

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