sqlite3.exe使用教程

1).open 打开数据库

例子:

sqlite> .open test.db

注意:>后面有点

2) .tables 查看数据库包含的表名

例子:

sqlite> .tables

注意:>后面有点

3) .schema 查看数据库中所有的表的结构

例子:

sqlite> .schema students

注意:>后面有点

4) 执行sql语句

例子:

sqlite> select * from students where StudentID = 3 ;

注意:调用sql之前,可以设置输出的结果格式

-显示SELECT结果集的列名。

--以列的形式显示各个字段。

--将其后输出的第一列显示宽度设置为10.

sqlite> .header on

sqlite> .mode column

sqlite> .width 10

5).exit 退出

6) .explain 准备显示SQL语句转换成VDBC机器码的语句

例子如下:

sqlite> .explain

sqlite> EXPLAIN select * from students ;

7)在上面的基础上,如果调用了.explain

可以查看简单的如下的细节,目前需要等到翻译了英文版本才能够理解

sqlite> .explain 

sqlite> EXPLAIN QUERY PLAN select * from students;


sele  order  from data

 0      0     0    SCAN TABLE students 


当然,我在下面的网站上看到了对students表创建索引,之后产生的不同:

摘自:http://blog.itpub.net/16900201/viewspace-1291550/

sqlite> create index student_index on students(StudentID);

sqlite> EXPLAIN QUERY PLAN select * from student where StudnetID = 1;

结果显示如下:

sele  order  from data

 0      0     0    SEARCH TABLE student USING INDEX student_index(StudentID= ?)

综上所述,该语句说明了数据是如何查询的,当然了只有建立索引的时候,才有效,这里我们可以大胆的断言:实际上,如果数据库不建立索引,其实就是扫描整一个数据库的表记录,如果建立了索引就会搜索索引,这个话题将会在以后的文章中,进行详细的分析说明,并且从源码角度如何正确建立索引,而且是在多个列上建立聚簇索引。

    如下是一些简单的探索:

1)数据库并没有保存student_index这张表,至于保存在什么地方等待探索!!

Error:no such table student_index;


2)索引是否记录了对应数据块的编号,来加快搜索,保存的结构是什么??





你可能感兴趣的:(sqlite,query,EXPLAIN,plan,sqite3.exe)