您的位置:首页 > 数据库

SQLITE3 常用操作

2010-09-11 16:14 239 查看
<!--
@page { margin: 0.79in }
PRE.western { font-family: "Liberation Serif" }
PRE.cjk { font-family: "Liberation Serif" }
P { margin-bottom: 0.08in }
-->

SQLITE3 常用操作 收藏
1.建立数据库

在sqlite安装的目录/usr/bin下,(其实在任何目录都可以输入下面语句)

sqlite3 sensordata.db

该语句新建一个名为sensordata的 数据库,并进入该数据库,在该目录下生成sensordata.db文件,即为数据库文件

2.建立表

create table sensortable1(one varchar(10), two smallint);

CREATE TABLE sensortable1(ID smallint primary key,Source smallint,Dest smallint,Accel_x smallint,Accel_y smallint,Accel_z smallint,Temperature smallint,Humidity smallint,BrdLight smallint,InfraLight smallint);

CREATE TABLE sensortable1(ID INTEGER PRIMARY KEY AUTOINCREMENT,Source smallint,Dest smallint,Accel_x smallint,Accel_y smallint,Accel_z smallint,Temperature smallint,Humidity smallint,BrdLight smallint,InfraLight smallint);

3.插入数据

insert into sensortable1 values('hello!',10);

insert into sensortable1 values(null,0,0,2048,2048,2048,37500,34000,100,100);

insert into sensortable1 values(1,0,0,2048,2048,2048,37500,34000,100,100);

4.显示表的各列名称

.header on

5.显示数据

select * from sensortable1;
select * from sensortable1 where ID >5;

6.显示当前数据库中的表

.tables

7.删除数据表中的数据

删除所有

delete from sensortable1;

条件删除

delete from sensortable1 where name <20;

8.删除数据表

drop table sensortable1;

9.退出sqlite3

.exit

10.强制退出

control+D

更多详细操作参考http://www.sqlite.org/sqlite.html

11.对齐显示

.mode column

select * from sensortable1;

12.显示创建表的语句
.schema		Show the CREATE statements
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: