SQLite 命令

在shell下直接敲  

sqlite3        进入sqlite命令行模式下(CLP的shell模式,CLP是sqlite3的命令行程序)

sqlite3 -help    (注意有空格)显示命令行模式下,sqlite3中的用法

sqlite3 test.db    建立或打开名为test.db的数据库文件

在CLP下敲    (注意,在CLP模式下,CLP会将任何语句当成查询命令,以;结尾。除非以.开头,这些命令是为指定的CLP命令预留的。

.help                         显示在CLP模式下的,sqlite3中的命令,参数及用法

.exit  或  ctrl+D(linux)或ctrl+C(win)          退出CLP模式

create table test (id integer primary key, value text);    建立名为table的表,名为id的主键列,名为value的简单文本域。

insert into test (id, value) values(1,'eenle');        向表test中插入记录

insert into test(value) values ('minky');          向表中插入记录,注意主键是有默认的增量函数的,据上一记录值产生下一个值。

.mode column                    改善显示格式

.headers on                      改善显示格式

select * from test;                  返回表中全部内容

create index test_idx on test (value);            建立索引

create view schema as select * from sqlite_master;      建立视图

.tables                        返回所有的表和视图

.indices                        返回索引

.schema                         返回表,视图,索引,触发器等数据库对象的的定义语句

select * from sqlite_master;                返回系统目录(即:更详细的schema信息可由系统视图sqlite_master得到,即系统目录表)

.output file.sql                      将输出定位到文件

.output stdout                      将输出定位到输出流

.dump                         将数据库对象导出成SQL格式

.show                         显示用户Shell中定义的所有设置

drop table test;                     删除表

drop view schema;                   删除视图

.read file.sql                    导入.dump命令创建的文件。如果使用前面备份的文件导入,则先要移除已经存在的数据库对象

create table student(id integer primary key,name text);    建表

alter table table_name {rename to name | add column column_def}    修改表

原文地址:https://www.cnblogs.com/amdb/p/4071838.html