⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlite.html

📁 SQLite is a software library that implements a self-contained, serverless, zero-configuration, trans
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>sqlite3: A command-line access program for SQLite databases</title><style type="text/css">body {    margin: auto;    font-family: "Verdana" "sans-serif";    padding: 8px 1%;}a { color: #45735f }a:visited { color: #734559 }.logo { position:absolute; margin:3px; }.tagline {  float:right;  text-align:right;  font-style:italic;  width:240px;  margin:12px;  margin-top:58px;}.toolbar {  font-variant: small-caps;  text-align: center;  line-height: 1.6em;  margin: 0;  padding:1px 8px;}.toolbar a { color: white; text-decoration: none; padding: 6px 12px; }.toolbar a:visited { color: white; }.toolbar a:hover { color: #80a796; background: white; }.content    { margin: 5%; }.content dt { font-weight:bold; }.content dd { margin-bottom: 25px; margin-left:20%; }.content ul { padding:0px; padding-left: 15px; margin:0px; }/* rounded corners */.se  { background: url(images/se.png) 100% 100% no-repeat #80a796}.sw  { background: url(images/sw.png) 0% 100% no-repeat }.ne  { background: url(images/ne.png) 100% 0% no-repeat }.nw  { background: url(images/nw.png) 0% 0% no-repeat }</style><meta http-equiv="content-type" content="text/html; charset=UTF-8">  </head><body><div><!-- container div to satisfy validator --><a href="index.html"><img class="logo" src="images/SQLite.gif" alt="SQLite Logo" border="0"></a><div><!-- IE hack to prevent disappearing logo--></div><div class="tagline">Small. Fast. Reliable.<br>Choose any three.</div><table width=100% style="clear:both"><tr><td>  <div class="se"><div class="sw"><div class="ne"><div class="nw">  <div class="toolbar">    <a href="about.html">About</a>    <a href="sitemap.html">Sitemap</a>    <a href="docs.html">Documentation</a>    <a href="download.html">Download</a>    <a href="copyright.html">License</a>    <a href="news.html">News</a>    <a href="http://www.sqlite.org/cvstrac/index">Developers</a>    <a href="support.html">Support</a>  </div></div></div></div></div></td></tr></table>  <h2>sqlite3: A command-line access program for SQLite databases</h2><p>The SQLite library includes a simple command-line utility named<b>sqlite3</b> that allows the user to manually enter and execute SQLcommands against an SQLite database.  This document provides a briefintroduction on how to use <b>sqlite3</b>.<h3>Getting Started</h3><p>To start the <b>sqlite3</b> program, just type "sqlite3" followed bythe name the file that holds the SQLite database.  If the file doesnot exist, a new one is created automatically.The <b>sqlite3</b> program willthen prompt you to enter SQL.  Type in SQL statements (terminated by asemicolon), press "Enter" and the SQL will be executed.</p><p>For example, to create a new SQLite database named "ex1" with a single table named "tbl1", you might do this:</p><blockquote><tt>$&nbsp;<b>sqlite3&nbsp;ex1</b><br>SQLite&nbsp;version&nbsp;3.3.10<br>Enter&nbsp;".help"&nbsp;for&nbsp;instructions<br>sqlite&gt;&nbsp;<b>create&nbsp;table&nbsp;tbl1(one&nbsp;varchar(10),&nbsp;two&nbsp;smallint);</b><br>sqlite&gt;&nbsp;<b>insert&nbsp;into&nbsp;tbl1&nbsp;values('hello!',10);</b><br>sqlite&gt;&nbsp;<b>insert&nbsp;into&nbsp;tbl1&nbsp;values('goodbye',&nbsp;20);</b><br>sqlite&gt;&nbsp;<b>select&nbsp;*&nbsp;from&nbsp;tbl1;</b><br>hello!|10<br>goodbye|20<br>sqlite&gt;</tt></blockquote><p>You can terminate the sqlite3 program by typing your systemsEnd-Of-File character (usually a Control-D) or the interruptcharacter (usually a Control-C).</p><p>Make sure you type a semicolon at the end of each SQL command!The sqlite3 program looks for a semicolon to know when your SQL command iscomplete.  If you omit the semicolon, sqlite3 will give you acontinuation prompt and wait for you to enter more text to beadded to the current SQL command.  This feature allows you toenter SQL commands that span multiple lines.  For example:</p><blockquote><tt>sqlite&gt;&nbsp;<b>CREATE&nbsp;TABLE&nbsp;tbl2&nbsp;(</b><br>&nbsp;&nbsp;&nbsp;...&gt;&nbsp;<b>&nbsp;&nbsp;f1&nbsp;varchar(30)&nbsp;primary&nbsp;key,</b><br>&nbsp;&nbsp;&nbsp;...&gt;&nbsp;<b>&nbsp;&nbsp;f2&nbsp;text,</b><br>&nbsp;&nbsp;&nbsp;...&gt;&nbsp;<b>&nbsp;&nbsp;f3&nbsp;real</b><br>&nbsp;&nbsp;&nbsp;...&gt;&nbsp;<b>);</b><br>sqlite&gt;</tt></blockquote><h3>Aside: Querying the SQLITE_MASTER table</h3><p>The database schema in an SQLite database is stored ina special table named "sqlite_master".You can execute "SELECT" statements against thespecial sqlite_master table just like any other tablein an SQLite database.  For example:</p><blockquote><tt>$&nbsp;<b>sqlite3&nbsp;ex1</b><br>SQlite&nbsp;vresion&nbsp;3.3.10<br>Enter&nbsp;".help"&nbsp;for&nbsp;instructions<br>sqlite&gt;&nbsp;<b>select&nbsp;*&nbsp;from&nbsp;sqlite_master;</b><br>&nbsp;&nbsp;&nbsp;&nbsp;type&nbsp;=&nbsp;table<br>&nbsp;&nbsp;&nbsp;&nbsp;name&nbsp;=&nbsp;tbl1<br>tbl_name&nbsp;=&nbsp;tbl1<br>rootpage&nbsp;=&nbsp;3<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sql&nbsp;=&nbsp;create&nbsp;table&nbsp;tbl1(one&nbsp;varchar(10),&nbsp;two&nbsp;smallint)<br>sqlite&gt;</tt></blockquote><p>But you cannot execute DROP TABLE, UPDATE, INSERT or DELETE againstthe sqlite_master table.  The sqlite_mastertable is updated automatically as you create or drop tables andindices from the database.  You can not make manual changesto the sqlite_master table.</p><p>The schema for TEMPORARY tables is not stored in the "sqlite_master" tablesince TEMPORARY tables are not visible to applications other than theapplication that created the table.  The schema for TEMPORARY tablesis stored in another special table named "sqlite_temp_master".  The"sqlite_temp_master" table is temporary itself.</p><h3>Special commands to sqlite3</h3><p>Most of the time, sqlite3 just reads lines of input and passes themon to the SQLite library for execution.But if an input line begins with a dot ("."), thenthat line is intercepted and interpreted by the sqlite3 program itself.These "dot commands" are typically used to change the output formatof queries, or to execute certain prepackaged query statements.</p><p>For a listing of the available dot commands, you can enter ".help"at any time.  For example:</p><blockquote><tt>sqlite&gt;&nbsp;<b>.help</b><br>.bail&nbsp;ON|OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Stop&nbsp;after&nbsp;hitting&nbsp;an&nbsp;error.&nbsp;&nbsp;Default&nbsp;OFF<br>.databases&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;names&nbsp;and&nbsp;files&nbsp;of&nbsp;attached&nbsp;databases<br>.dump&nbsp;?TABLE?&nbsp;...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dump&nbsp;the&nbsp;database&nbsp;in&nbsp;an&nbsp;SQL&nbsp;text&nbsp;format<br>.echo&nbsp;ON|OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Turn&nbsp;command&nbsp;echo&nbsp;on&nbsp;or&nbsp;off<br>.exit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit&nbsp;this&nbsp;program<br>.explain&nbsp;ON|OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Turn&nbsp;output&nbsp;mode&nbsp;suitable&nbsp;for&nbsp;EXPLAIN&nbsp;on&nbsp;or&nbsp;off.<br>.header(s)&nbsp;ON|OFF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Turn&nbsp;display&nbsp;of&nbsp;headers&nbsp;on&nbsp;or&nbsp;off<br>.help&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Show&nbsp;this&nbsp;message<br>.import&nbsp;FILE&nbsp;TABLE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Import&nbsp;data&nbsp;from&nbsp;FILE&nbsp;into&nbsp;TABLE<br>.indices&nbsp;TABLE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Show&nbsp;names&nbsp;of&nbsp;all&nbsp;indices&nbsp;on&nbsp;TABLE<br>.load&nbsp;FILE&nbsp;?ENTRY?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Load&nbsp;an&nbsp;extension&nbsp;library<br>.mode&nbsp;MODE&nbsp;?TABLE?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set&nbsp;output&nbsp;mode&nbsp;where&nbsp;MODE&nbsp;is&nbsp;one&nbsp;of:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;csv&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Comma-separated&nbsp;values<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;column&nbsp;&nbsp;&nbsp;Left-aligned&nbsp;columns.&nbsp;&nbsp;(See&nbsp;.width)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;H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&nbsp;&nbsp;&nbsp;&nbsp;TCL&nbsp;list&nbsp;elements<br>.nullvalue&nbsp;STRING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Print&nbsp;STRING&nbsp;in&nbsp;place&nbsp;of&nbsp;NULL&nbsp;values<br>.output&nbsp;FILENAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Send&nbsp;output&nbsp;to&nbsp;FILENAME<br>.output&nbsp;stdout&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Send&nbsp;output&nbsp;to&nbsp;the&nbsp;screen<br>.prompt&nbsp;MAIN&nbsp;CONTINUE&nbsp;&nbsp;Replace&nbsp;the&nbsp;standard&nbsp;prompts<br>.quit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit&nbsp;this&nbsp;program<br>.read&nbsp;FILENAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Execute&nbsp;SQL&nbsp;in&nbsp;FILENAME<br>.schema&nbsp;?TABLE?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Show&nbsp;the&nbsp;CREATE&nbsp;statements<br>.separator&nbsp;STRING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Change&nbsp;separator&nbsp;used&nbsp;by&nbsp;output&nbsp;mode&nbsp;and&nbsp;.import<br>.show&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Show&nbsp;the&nbsp;current&nbsp;values&nbsp;for&nbsp;various&nbsp;settings<br>.tables&nbsp;?PATTERN?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;names&nbsp;of&nbsp;tables&nbsp;matching&nbsp;a&nbsp;LIKE&nbsp;pattern<br>.timeout&nbsp;MS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Try&nbsp;opening&nbsp;locked&nbsp;tables&nbsp;for&nbsp;MS&nbsp;milliseconds<br>.width&nbsp;NUM&nbsp;NUM&nbsp;...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Set&nbsp;column&nbsp;widths&nbsp;for&nbsp;"column"&nbsp;mode<br>sqlite&gt;</tt></blockquote><h3>Changing Output Formats</h3><p>The sqlite3 program is able to show the results of a queryin eight different formats: "csv", "column", "html", "insert","line", "tabs", and "tcl".You can use the ".mode" dot command to switch between these outputformats.</p><p>The default output mode is "list".  Inlist mode, each record of a query result is written on one line ofoutput and each column within that record is separated by a specificseparator string.  The default separator is a pipe symbol ("|").List mode is especially useful when you are going to send the outputof a query to another program (such as AWK) for additional processing.</p><blockquote><tt>sqlite&gt;&nbsp;<b>.mode&nbsp;list</b><br>sqlite&gt;&nbsp;<b>select&nbsp;*&nbsp;from&nbsp;tbl1;</b><br>hello|10<br>goodbye|20<br>sqlite&gt;</tt></blockquote><p>You can use the ".separator" dot command to change the separatorfor list mode.  For example, to change the separator to a comma anda space, you could do this:</p><blockquote><tt>sqlite&gt;&nbsp;<b>.separator&nbsp;",&nbsp;"</b><br>sqlite&gt;&nbsp;<b>select&nbsp;*&nbsp;from&nbsp;tbl1;</b><br>hello,&nbsp;10<br>goodbye,&nbsp;20<br>sqlite&gt;</tt></blockquote><p>In "line" mode, each column in a row of the databaseis shown on a line by itself.  Each line consists of the columnname, an equal sign and the column data.  Successive records areseparated by a blank line.  Here is an example of line modeoutput:</p><blockquote><tt>sqlite&gt;&nbsp;<b>.mode&nbsp;line</b><br>sqlite&gt;&nbsp;<b>select&nbsp;*&nbsp;from&nbsp;tbl1;</b><br>one&nbsp;=&nbsp;hello<br>two&nbsp;=&nbsp;10<br><br>one&nbsp;=&nbsp;goodbye<br>two&nbsp;=&nbsp;20<br>sqlite&gt;</tt></blockquote><p>In column mode, each record is shown on a separate line with thedata aligned in columns.  For example:</p><blockquote><tt>sqlite&gt;&nbsp;<b>.mode&nbsp;column</b><br>sqlite&gt;&nbsp;<b>select&nbsp;*&nbsp;from&nbsp;tbl1;</b><br>one&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;two&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>----------&nbsp;&nbsp;----------<br>hello&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>goodbye&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>sqlite&gt;</tt></blockquote><p>By default, each column is at least 10 characters wide. Data that is too wide to fit in a column is truncated.  You canadjust the column widths using the ".width" command.  Like this:</p><blockquote><tt>sqlite&gt;&nbsp;<b>.width&nbsp;12&nbsp;6</b><br>sqlite&gt;&nbsp;<b>select&nbsp;*&nbsp;from&nbsp;tbl1;</b><br>one&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;two&nbsp;&nbsp;&nbsp;<br>------------&nbsp;&nbsp;------<br>hello&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;&nbsp;<br>goodbye&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20&nbsp;&nbsp;&nbsp;&nbsp;<br>sqlite&gt;</tt></blockquote><p>The ".width" command in the example above sets the width of the firstcolumn to 12 and the width of the second column to 6.  All other columnwidths were unaltered.  You can gives as many arguments to ".width" asnecessary to specify the widths of as many columns as are in yourquery results.</p><p>If you specify a column a width of 0, then the columnwidth is automatically adjusted to be the maximum of threenumbers: 10, the width of the header, and the width of thefirst row of data.  This makes the column width self-adjusting.The default width setting for every column is this auto-adjusting 0 value.</p><p>The column labels that appear on the first two lines of outputcan be turned on and off using the ".header" dot command.  In theexamples above, the column labels are on.  To turn them off youcould do this:</p><blockquote><tt>sqlite&gt;&nbsp;<b>.header&nbsp;off</b><br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -