Sqlite学习之旅(一)
发布时间:2020-12-12 20:19:47 所属栏目:百科 来源:网络整理
导读:在Dos shell下 sqlite3 test.db .help create table test(id integer primary key,value text); insert into test(value) values('miny'); .mode [ column csv html insert line list tabs tcl] //设置查看模式 .headers on SELECT * FROM test; select last
在Dos shell下
sqlite3 test.db
.help
create table test(id integer primary key,value text);
insert into test(value) values('miny');
.mode [ column csv html insert line list tabs tcl] //设置查看模式
.headers on
SELECT * FROM test;
select last_insert_rowid();
//查看最后一条记录
CREATE index test_idx on test(value); //创建索引
CREATE view schema as SELECT * FROM sqlite_master;
//创建视图,sqlite_master是一个系统视图
.tables
//可查看表和视图
.indices test
//查看索引
.schema [table name]
//可得到一个表或者视图的定义语句
select type,name,tbl_name,rootpage,sql from sqlite_master order by type;
//type 值为"table"、"index"、"trigger"或"view"之一。
//name 对象名称,值为字符串。
//tbl_name 如果是表或视图对象,此字段值与字段2相同。如果是索引或触发器对象,此字段值为与其相关的表名。 //rootpage 对触发器或视图对象,此字段值为0。对表或索引对象,此字段值为其根页的编号。 //SQL 字符串,创建此对象时所使用的SQL语句。 数据导出: .output file.sql .dump // .dump将导出整个数据库。如果提供参数,CLP把参数理解为表名或视图名 .output stdout 数据导入:有两种方法可以导入数据,用哪种方法决定于要导入的文件的格式。如果文件由SQL语句构成,可以使用 .read命令导入(执行)文件。如果文件是由逗号或其它定界符分隔的值(comma-separatedvalues,CSV)组成,可使用 .import[file][table]命令。 droptable test; dropviewschema; .read file.sql 格式化:如果要改变CLP的shell提示符,使用.prompt[value]。如果设置.echoon,则新输入的命令在执行前都会回显。.headers设置为on时,查询结果显示时带有字段名。当遇到NULL值时,如果需要以一个字符串来显示,使用.nullvalue命令设置。 .nullvalue NULL .outputfile.csv .separator,//.modecsv select*fromtest; .outputstdout 备份:sqlite3 test.db .dump > test.sql 导入:sqlite3 test.db < test.sql (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |