首页 > 数据库技术 > 详细

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

时间:2015-08-21 15:49:08      阅读:628      评论:0      收藏:0      [点我收藏+]

    最后要使用到号码归属地的查询,在网上找到一个数据库文件,大小有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删除表后大小不变的问题

原文:http://blog.csdn.net/deng0zhaotai/article/details/47833231

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!