`
mmdev
  • 浏览: 12909150 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

sqlite3命令详解(中)

 
阅读更多
文章参照:www.sqlite.org/sqlite.html<wbr style="line-height:25px"><wbr style="line-height:25px"><div style="line-height:25px"><span style="line-height:25px; font-family:Arial,Helvetica,simsun,u5b8bu4f53"><span style="color:#003366; line-height:25px">在sqlite3中我们可以通过".help"命令来查所有的非SQL命令。</span></span></div> <div style="line-height:25px"><span style="line-height:25px; font-family:Arial,Helvetica,simsun,u5b8bu4f53">比如,<span style="line-height:25px">示例4</span>:</span></div> <div style="line-height:25px"> <span style="line-height:25px; font-family:Arial,Helvetica,simsun,u5b8bu4f53"></span> <div style="line-height:25px">sqlite&gt;<span style="color:#0000ff; line-height:25px">.help</span> </div> <div style="line-height:25px">.help</div> <div style="line-height:25px"> <span style="color:#0000ff; line-height:25px">.</span><span style="line-height:25px">backup ?DB? FILE</span> Backup DB (default "main") to FILE</div> <div style="line-height:25px">.bail ON|OFF Stop after hitting an error. Default OFF</div> <div style="line-height:25px"> <span style="line-height:25px">.databases</span> List names and files of attached databases</div> <div style="line-height:25px"> <span style="line-height:25px">.dump ?TABLE?</span>... <span style="color:#000080; line-height:25px">Dump the database in an SQL text format</span> </div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> If TABLE specified, only dump tables matching</span></div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> LIKE pattern TABLE.</span></div> <div style="line-height:25px"> <span style="line-height:25px">.echo ON|OFF</span> Turn command echo on or off</div> <div style="line-height:25px"> <span style="line-height:25px">.exit</span> <span style="color:#ff6600; line-height:25px">Exit this program</span> </div> <div style="line-height:25px">.explain ?ON|OFF?<span style="line-height:25px"></span> Turn output mode suitable for EXPLAIN on or off.</div> <div style="line-height:25px"> With no args, it turns EXPLAIN on.</div> <div style="line-height:25px"> <span style="line-height:25px">.</span>genfkey ?OPTIONS? Options are:</div> <div style="line-height:25px"> --no-drop: Do not drop old fkey triggers.</div> <div style="line-height:25px"> --ignore-errors: Ignore tables with fkey errors</div> <div style="line-height:25px"> --exec: Execute generated SQL immediately</div> <div style="line-height:25px"> See file tool/genfkey.README in the source</div> <div style="line-height:25px"> distribution for further information.</div> <div style="line-height:25px"> <span style="line-height:25px">.header(s) ON|OFF</span> Turn display of headers on or off</div> <div style="line-height:25px"> <span style="line-height:25px">.help</span> Show this message</div> <div style="line-height:25px">.import FILE TABLE Import data from FILE into TABLE</div> <div style="line-height:25px">.<span style="line-height:25px">indices ?TABLE?</span> Show names of all indices</div> <div style="line-height:25px"> If TABLE specified, only show indices for tables</div> <div style="line-height:25px"> matching LIKE pattern TABLE.</div> <div style="line-height:25px">.<span style="line-height:25px">load FILE ?ENTRY?</span> Load an extension library</div> <div style="line-height:25px"> <span style="line-height:25px">.log FILE|off</span> Turn logging on or off. FILE can be stderr/stdout</div> <div style="line-height:25px"> <span style="line-height:25px">.mode MODE ?TABLE?</span> <span style="color:#000080; line-height:25px">Set output mode where MODE is one of:</span> </div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> csv Comma-separated values</span></div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> column Left-aligned columns. (See .width)</span></div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> html HTML &lt;table&gt; code</span></div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> insert SQL insert statements for TABLE</span></div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> line One value per line</span></div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> list Values delimited by .separator string</span></div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> tabs Tab-separated values</span></div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> tcl TCL list elements</span></div> <div style="line-height:25px"> <span style="line-height:25px">.nullvalue STRING</span> <span style="color:#000080; line-height:25px">Print STRING in place of NULL values</span> </div> <div style="line-height:25px"> <span style="line-height:25px">.output FILENAME</span> <span style="color:#000080; line-height:25px">Send output to FILENAME</span> </div> <div style="line-height:25px"> <span style="line-height:25px">.output stdout</span> <span style="color:#000080; line-height:25px">Send output to the screen</span> </div> <div style="line-height:25px">.prompt MAIN CONTINUE Replace the standard prompts</div> <div style="line-height:25px"> <span style="line-height:25px">.quit</span> <span style="color:#ff6600; line-height:25px">Exit this program</span> </div> <div style="line-height:25px"> <span style="line-height:25px">.read FILENAME</span> Execute SQL in FILENAME</div> <div style="line-height:25px"> <span style="line-height:25px">.restore ?DB? FILE</span> Restore content of DB (default "main") from FILE</div> <div style="line-height:25px"> <span style="line-height:25px">.schema ?TABLE?</span> <span style="color:#000080; line-height:25px">Show the CREATE statements</span> </div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> If TABLE specified, only show tables matching</span></div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> LIKE pattern TABLE.</span></div> <div style="line-height:25px"> <span style="line-height:25px">.separator STRING</span> <span style="color:#ff6600; line-height:25px">Change separator used by output mode and .import</span> </div> <div style="line-height:25px">.show Show the current values for various settings</div> <div style="line-height:25px"> <span style="line-height:25px">.tables ?TABLE?</span> <span style="color:#000080; line-height:25px"> List names of tables</span> </div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> If TABLE specified, only list tables matching</span></div> <div style="line-height:25px"><span style="color:#000080; line-height:25px"> LIKE pattern TABLE.</span></div> <div style="line-height:25px">.timeout MS Try opening locked tables for MS milliseconds</div> <div style="line-height:25px"> <span style="line-height:25px">.width NUM1 NUM2 ...</span><span style="color:#000080; line-height:25px">Set column widths for "column" mode</span> </div> <div style="line-height:25px">.timer ON|OFF Turn the CPU timer measurement on or off</div> <div style="line-height:25px">sqlite&gt;</div> <div style="line-height:25px"> <span style="color:#003366; line-height:25px">sqlite3能以8种不同的方式显示查询返回的结果:</span><strong>"</strong><span style="color:#ff6600; line-height:25px">csv</span><strong>"</strong><span style="color:#003366; line-height:25px">, "</span><span style="color:#ff6600; line-height:25px">column</span><span style="color:#003366; line-height:25px">", "</span><span style="color:#ff6600; line-height:25px">html</span><span style="color:#003366; line-height:25px">", "</span><span style="color:#ff6600; line-height:25px">insert</span><span style="color:#003366; line-height:25px">", "</span><span style="color:#ff6600; line-height:25px">line</span><span style="color:#003366; line-height:25px">", "</span><span style="color:#ff6600; line-height:25px">list</span><span style="color:#003366; line-height:25px">","</span><span style="color:#ff6600; line-height:25px">tabs</span><span style="color:#003366; line-height:25px">", "</span><span style="color:#ff6600; line-height:25px">tcl</span><span style="color:#003366; line-height:25px">".</span> </div> </div> </wbr></wbr>
你可以通过.mode来设置显示的方式。默认的是"list"方式,这时返回结果的一条记录显示一行,每列的内容之间用设定的分隔符隔开,
默认的分隔符是"|".
示例5
sqlite>.mode list
sqlite>select * from tbl1;
hello|10
goodbye|20
sqlite>
你可以通过".separator"来设置"list"模式下的分隔符。比如我们想把", "作为分隔符,可以这样:
示例6
sqlite>.separator ", "
sqlite>select * from tbl1;
hello, 10
goodbye, 20
sqlite>
"line"模式下, 每行只显示数据库的一行的一列。每行由列名,等号和列的值组成。每条记录之间由一个空行隔开。
比如,示例7
sqlite>.mode line
sqlite>select * from tbl1;
one = hello
two = 10

one = goodbye
two = 20
sqlite>
"column"模式下,每条记录都在单独一行显示。第一行显示的是列名,第二行只是用于分割列名和记录的数据,第三行开始才是记录的内容
比如,示例8:
sqlite>.mode column
sqlite>select * from tbl1;
one two
---------- ----------
hello 10
goodbye 20
sqlite>
默认情况下,每列的宽度最多只能显示10个字符。所以如果数据包含的字符如果他太多,可能就显示不完。
但是我们可以通过".width"设置每列的宽度
比如,示例9:
sqlite>.width 12 6
sqlite>select * from tbl1;
one two
------------ ------
hello 10
goodbye 20
sqlite>
示例9就把第1列和第二列的宽度分别设置为了12和6个字符,其他列的宽度并没改变。
如果你把列宽设置为0,那么调整为以下三个的最大值:10,该列的列名字符数,第一行记录该列的字符数。这样列的宽度就可以自动调整。
默认的列宽就是0,以便它可以自动调整
可以通过".header"命令可以设置是否显示头(头包括第一行,列名,第二行,分隔行)。
比如,示例10
sqlite>.header off
sqlite>select * from tbl1;
hello 10
goodbye 20
sqlite>
"insert"模式下,返回的查询结果将以SQL的INSERT语句形式进行显示。
比如,示例11
sqlite>.mode insert new_table
sqlite>select * from tbl1;
INSERT INTO 'new_table' VALUES('hello',10);
INSERT INTO 'new_table' VALUES('goodbye',20);
sqlite>
"html"模式下,查询返回结果将以XHTML table的形式进行显示,
它并不以<TABLE>作为开头和</TABLE>作为结尾。 但是每条记录以<TR>作为开始,</TR>作为结束,记录的数据以<TD>作为开始,以</TD>作为结束
比如,示例12
sqlite>select * from system;
select * from system;
<TR><TD>1</TD>
<TD>volume_music</TD>
<TD>7</TD>
</TR>
<TR><TD>4</TD>
<TD>volume_voice</TD>
<TD>4</TD>
</TR>
........省略.........
sqlite>
".output"命令可以把查询返回结果的输出定向到文件上。该命令的第一个参数即是要定向的位置。在把输出定向了文件后,可以通过".output stdout"把输出重新定向到标准输出上。
示例13
sqlite>.mode list
sqlite> .separator |
sqlite>.output test_file_1.txt
sqlite>select * from tbl1;
sqlite>.exit
$cat test_file_1.txt
hello|10
goodbye|20
$
分享到:
评论

相关推荐

    android-SQLite3命令详解教程

    android-SQLite3命令详解教程,转发分享

    Android Sqlite命令详解(基本命令)

    主要介绍了Android Sqlite命令详解(基本命令)的相关资料,需要的朋友可以参考下

    基于Android SQLite的升级详解

    SQLite提供了ALTER TABLE命令,允许用户重命名或添加新的字段到已有表中,但是不能从表中删除字段。 并且只能在表的末尾添加字段,比如,为 Subscription添加两个字段: 代码如下:ALTER TABLE Subscription ADD ...

    详解Python 数据库 (sqlite3)应用

    Python标准库中的sqlite3提供该数据库的接口。 我将创建一个简单的关系型数据库,为一个书店存储书的分类和价格。数据库中包含两个表:category用于记录分类,book用于记录某个书的信息。一本书归属于某一个分类,...

    解析SQLite中的常见问题与总结详解

    如果接着执行其他查询语句就会失败,比如sqlite3_prepare,编程中出现明明指定了数据库而且里面也有数据,为什么查询失败了,主要是数据库名路径不对引起的。一般的做法是先检查数据库文件是否存在,如果存在就使用

    DJango的创建和使用详解(默认数据库sqlite3)

    3)编辑家目录下面的.bashrc文件,添加下面两行。 export WORKON_HOME=$HOME/.virtualenvs source /usr/local/bin/virtualenvwrapper.sh 4)使用source .bashrc使其生效一下。 创建虚拟环境命令: mkvirtualenv 虚拟...

    rest-smtp-sink:与fakesmtp相似,rest-smtp-sink是SMTP服务器和Web服务器。 它将收到的电子邮件存储在SQLite数据库中,并通过其自己的带有RESTful API的Web服务器为它们提供服务

    它将收到的电子邮件存储在数据库中,并使用RESTful API通过自己的Web服务器为其提供服务。 安装 npm install -g rest-smtp-sink 用法 rest-smtp-sink 使用默认的SMTP端口2525,HTTP端口2526和文件名为rest-smtp-...

    微信小程序 本地数据存储实例详解

    微信小程序 本地数据存储实例详解 前言 如果您在看此文章之前有过其他程序的开发经验,那一定会知道一般例如安卓或者苹果的原生APP都提供了本地的存储功能,甚至可以使用sqlite数据库来做存储。可是微信的小程序框架...

    android系统contentprovier和数据库详解

    详细阐述contentprovier相关的类,用法,以及先关SQLITE数据的语句,语法,命令等

    详解iOS的数据存储

     4.SQLite3  5.Core Data 应用沙盒 每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录)与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒. 模拟器应用沙盒的根路径在: (apple是...

    编程狂人第九期(2014-1-20)

    Rails 3 升级 Rails 4 中遇到的问题及解决方法 php性能优化 Java中的 equals() 和 hashCode() 契约 程序设计 IOS缓存机制详解 ios系类教程之用instruments来检验你的app Android 学习笔记之 SQLite基础用法 如何...

    asp.net知识库

    ASP.NET2.0 ObjectDataSource的使用详解(3) ASP.NET2.0 快速入门 ----默认中的主题外观 数据库开发 ADO.NET 通过DataTable获得表的主键 ADO.NET 2.0 操作实例 ADO.NET 2.0 大批量数据操作和多个动态的结果集 ADO...

    Android文件操作

    他在Android手机中存放在nandflash的 mtd3中,是一个yaffs2文件系统,在启动时被挂载在root的/system目录下,其中包含有: # ls -a -l /system drwxr-xr-x root 208 1970-01-01 08:00 xbin drwxr-xr-x root root ...

    linux下编译安装kangle web server教程详解

    首先下载kangle kangle web server源代码。...yum -y install wget make automake gcc gcc-c++ pcre-devel zlib-devel sqlite-devel openssl-devel 第一步 下载kangle linux版源代码: 下载后我们会得到kangle-3.4.8

    go语言web编程

    1.3. Go 命令 1.4. Go开发工具 1.5. 小结 2.Go语言基础 2.1. 你好,Go 2.2. Go基础 2.3. 流程和函数 2.4. struct 2.5. 面向对象 2.6. interface 2.7. 并发 2.8. 小结 3.Web基础 3.1 web工作方式 3.2 Go搭建一个简单...

    [Django] Django 连接 MySQL数据库 以及 makemigrations&migrate 过程详解总结

    Django 连接 MySQL数据库过程安装MySQL数据库安装mysqlclient包配置settings.py文件生成迁移文件ORM迁移文件具体操作生成数据库的表 ...安装命令pip3 install mysqlclient(blog) [root@centos7 testBl

    php-7.2.26.tar.xz

    如果你解压步骤失败,可能是下载的文件不是 .tar.xz 后缀归档,也有可能是下载过程中数据丢包,不用担心。你重新下运行 rm -rf php-7.2.9* 命令,将你之前下载的删除,然后重新下载即可。 #编译 PHP 编译 PHP ...

Global site tag (gtag.js) - Google Analytics