SQLite数据操作

前端之家收集整理的这篇文章主要介绍了SQLite数据操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一般数据采用的固定的静态数据类型,而sqlite采用的是动态数据类型,会根据存入值自动判断。sqlite具有以下五种数据类型

1.NULL :空值。
2.INTEGER :带符号的整型,具体取决有存入数字的范围大小。
3.REAL :浮点数字,存储为8-byte IEEE 浮点数。
4.TEXT :字符串文本。
5.BLOB :二进制对象
支持一些其它的常用数据类型,在使用时会转换为 sqlLite 内置的数据类型:
smallint 16 位元的整数。
interger 32 位元的整数。
decimal(p,s) p 精确值和s 大小的十进位整数,精确值p 是指全部有几个数(digits) 大小值,s 是指小数点後有几位数。如果没有特别指定,则系统会设为p=5; s=0
float 32 位元的实数。
double64 位元的实数。
char(n)n 长度的字串,n 不能超过254
varchar(n) 长度不固定且其最大长度为n 的字串,n 不能超过4000
graphic(n) char(n) 一样,不过其单位是两个字元double-bytes n 不能超过127 。这个形态是为了支援两个字元长度的字体,例如中文字。
vargraphic(n) 可变长度且其最大长度为n 的双字元字串,n 不能超过2000
date 包含了 年份、月份、日期。
time 包含了 小时、分钟、秒。
imestamp 包含了 年、月、日、时、分、秒、千分之一秒。
@H_404_138@ datetime 包含日期时间格式,必须写成'2010-08-05' 不能写为'2010-8-5' ,否则在读取时会产生错误
1.sqlLite数据库的操作语句( 基本sql 命令 )
建表:create table t_student(id INTEGER primary key autoincrement,name varchar(20));
增加insert into t_student (id,name) values(1,’happy’);
如果主键是int 类型的,并且没有使用autoincrement 自动增长,默认也是自动增长的
执行insert into t_student (id,name) values(’good’);id 自动增长
查询select id,name from t_student;
更新:update t_student set name=’verygood’ where id=2;
删除delete from t_student where id=2;
排序:select id,name from t_student order by id desc; ( 根据id 降序排)
分组:select id,name from t_student group by name; ( 有待研究)
分组后筛选:having
分页select id,name from t_student limit(0,2);-------------- 从第0 行开始,不包括0 行,取2 ( 取第1 2 )
select id,name from t_studentlimit(2,2);--------------- ( 取第3 4 )
注意:sqlLite数据库建议所有的表的主键列名应为_idandroid中也建议采用,如果不采用,在使用SimpleCursorAdapter适配器时会出错

本文出自 “IT之梦博客,请务必保留此出处http://www.jb51.cc/article/p-ntuqmolh-gz.html

原文链接:https://www.f2er.com/sqlite/201977.html

猜你在找的Sqlite相关文章