302 lines
13 KiB
HTML
302 lines
13 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html><head>
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
|
<link href="sqlite.css" rel="stylesheet">
|
||
|
<title>CREATE INDEX</title>
|
||
|
<!-- path= -->
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class=nosearch>
|
||
|
<a href="index.html">
|
||
|
<img class="logo" src="images/sqlite370_banner.gif" alt="SQLite" border="0">
|
||
|
</a>
|
||
|
<div><!-- IE hack to prevent disappearing logo --></div>
|
||
|
<div class="tagline desktoponly">
|
||
|
Small. Fast. Reliable.<br>Choose any three.
|
||
|
</div>
|
||
|
<div class="menu mainmenu">
|
||
|
<ul>
|
||
|
<li><a href="index.html">Home</a>
|
||
|
<li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
|
||
|
<li class='wideonly'><a href='about.html'>About</a>
|
||
|
<li class='desktoponly'><a href="docs.html">Documentation</a>
|
||
|
<li class='desktoponly'><a href="download.html">Download</a>
|
||
|
<li class='wideonly'><a href='copyright.html'>License</a>
|
||
|
<li class='desktoponly'><a href="support.html">Support</a>
|
||
|
<li class='desktoponly'><a href="prosupport.html">Purchase</a>
|
||
|
<li class='search' id='search_menubutton'>
|
||
|
<a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<div class="menu submenu" id="submenu">
|
||
|
<ul>
|
||
|
<li><a href='about.html'>About</a>
|
||
|
<li><a href='docs.html'>Documentation</a>
|
||
|
<li><a href='download.html'>Download</a>
|
||
|
<li><a href='support.html'>Support</a>
|
||
|
<li><a href='prosupport.html'>Purchase</a>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<div class="searchmenu" id="searchmenu">
|
||
|
<form method="GET" action="search">
|
||
|
<select name="s" id="searchtype">
|
||
|
<option value="d">Search Documentation</option>
|
||
|
<option value="c">Search Changelog</option>
|
||
|
</select>
|
||
|
<input type="text" name="q" id="searchbox" value="">
|
||
|
<input type="submit" value="Go">
|
||
|
</form>
|
||
|
</div>
|
||
|
</div>
|
||
|
<script>
|
||
|
function toggle_div(nm) {
|
||
|
var w = document.getElementById(nm);
|
||
|
if( w.style.display=="block" ){
|
||
|
w.style.display = "none";
|
||
|
}else{
|
||
|
w.style.display = "block";
|
||
|
}
|
||
|
}
|
||
|
function toggle_search() {
|
||
|
var w = document.getElementById("searchmenu");
|
||
|
if( w.style.display=="block" ){
|
||
|
w.style.display = "none";
|
||
|
} else {
|
||
|
w.style.display = "block";
|
||
|
setTimeout(function(){
|
||
|
document.getElementById("searchbox").focus()
|
||
|
}, 30);
|
||
|
}
|
||
|
}
|
||
|
function div_off(nm){document.getElementById(nm).style.display="none";}
|
||
|
window.onbeforeunload = function(e){div_off("submenu");}
|
||
|
/* Disable the Search feature if we are not operating from CGI, since */
|
||
|
/* Search is accomplished using CGI and will not work without it. */
|
||
|
if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){
|
||
|
document.getElementById("search_menubutton").style.display = "none";
|
||
|
}
|
||
|
/* Used by the Hide/Show button beside syntax diagrams, to toggle the */
|
||
|
function hideorshow(btn,obj){
|
||
|
var x = document.getElementById(obj);
|
||
|
var b = document.getElementById(btn);
|
||
|
if( x.style.display!='none' ){
|
||
|
x.style.display = 'none';
|
||
|
b.innerHTML='show';
|
||
|
}else{
|
||
|
x.style.display = '';
|
||
|
b.innerHTML='hide';
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
</script>
|
||
|
</div>
|
||
|
<div class=fancy>
|
||
|
<div class=nosearch>
|
||
|
<div class="fancy_title">
|
||
|
CREATE INDEX
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<h1 id="syntax"><span>1. </span>Syntax</h1>
|
||
|
<p><b><a href="syntax/create-index-stmt.html">create-index-stmt:</a></b>
|
||
|
<button id='x1323' onclick='hideorshow("x1323","x1324")'>hide</button></p>
|
||
|
<div id='x1324' class='imgcontainer'>
|
||
|
<img alt="syntax diagram create-index-stmt" src="images/syntax/create-index-stmt.gif" />
|
||
|
<p><b><a href="syntax/expr.html">expr:</a></b>
|
||
|
<button id='x1325' onclick='hideorshow("x1325","x1326")'>show</button></p>
|
||
|
<div id='x1326' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram expr" src="images/syntax/expr.gif" />
|
||
|
<p><b><a href="syntax/filter-clause.html">filter-clause:</a></b>
|
||
|
<button id='x1327' onclick='hideorshow("x1327","x1328")'>show</button></p>
|
||
|
<div id='x1328' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram filter-clause" src="images/syntax/filter-clause.gif" />
|
||
|
</div>
|
||
|
<p><b><a href="syntax/literal-value.html">literal-value:</a></b>
|
||
|
<button id='x1329' onclick='hideorshow("x1329","x1330")'>show</button></p>
|
||
|
<div id='x1330' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram literal-value" src="images/syntax/literal-value.gif" />
|
||
|
</div>
|
||
|
<p><b><a href="syntax/over-clause.html">over-clause:</a></b>
|
||
|
<button id='x1331' onclick='hideorshow("x1331","x1332")'>show</button></p>
|
||
|
<div id='x1332' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram over-clause" src="images/syntax/over-clause.gif" />
|
||
|
<p><b><a href="syntax/frame-spec.html">frame-spec:</a></b>
|
||
|
<button id='x1333' onclick='hideorshow("x1333","x1334")'>show</button></p>
|
||
|
<div id='x1334' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram frame-spec" src="images/syntax/frame-spec.gif" />
|
||
|
</div>
|
||
|
<p><b><a href="syntax/ordering-term.html">ordering-term:</a></b>
|
||
|
<button id='x1335' onclick='hideorshow("x1335","x1336")'>show</button></p>
|
||
|
<div id='x1336' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram ordering-term" src="images/syntax/ordering-term.gif" />
|
||
|
</div>
|
||
|
</div>
|
||
|
<p><b><a href="syntax/raise-function.html">raise-function:</a></b>
|
||
|
<button id='x1337' onclick='hideorshow("x1337","x1338")'>show</button></p>
|
||
|
<div id='x1338' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram raise-function" src="images/syntax/raise-function.gif" />
|
||
|
</div>
|
||
|
<p><b><a href="syntax/select-stmt.html">select-stmt:</a></b>
|
||
|
<button id='x1339' onclick='hideorshow("x1339","x1340")'>show</button></p>
|
||
|
<div id='x1340' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram select-stmt" src="images/syntax/select-stmt.gif" />
|
||
|
<p><b><a href="syntax/common-table-expression.html">common-table-expression:</a></b>
|
||
|
<button id='x1341' onclick='hideorshow("x1341","x1342")'>show</button></p>
|
||
|
<div id='x1342' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram common-table-expression" src="images/syntax/common-table-expression.gif" />
|
||
|
</div>
|
||
|
<p><b><a href="syntax/compound-operator.html">compound-operator:</a></b>
|
||
|
<button id='x1343' onclick='hideorshow("x1343","x1344")'>show</button></p>
|
||
|
<div id='x1344' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram compound-operator" src="images/syntax/compound-operator.gif" />
|
||
|
</div>
|
||
|
<p><b><a href="syntax/join-clause.html">join-clause:</a></b>
|
||
|
<button id='x1345' onclick='hideorshow("x1345","x1346")'>show</button></p>
|
||
|
<div id='x1346' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram join-clause" src="images/syntax/join-clause.gif" />
|
||
|
<p><b><a href="syntax/join-constraint.html">join-constraint:</a></b>
|
||
|
<button id='x1347' onclick='hideorshow("x1347","x1348")'>show</button></p>
|
||
|
<div id='x1348' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram join-constraint" src="images/syntax/join-constraint.gif" />
|
||
|
</div>
|
||
|
<p><b><a href="syntax/join-operator.html">join-operator:</a></b>
|
||
|
<button id='x1349' onclick='hideorshow("x1349","x1350")'>show</button></p>
|
||
|
<div id='x1350' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram join-operator" src="images/syntax/join-operator.gif" />
|
||
|
</div>
|
||
|
</div>
|
||
|
<p><b><a href="syntax/ordering-term.html">ordering-term:</a></b>
|
||
|
<button id='x1351' onclick='hideorshow("x1351","x1352")'>show</button></p>
|
||
|
<div id='x1352' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram ordering-term" src="images/syntax/ordering-term.gif" />
|
||
|
</div>
|
||
|
<p><b><a href="syntax/result-column.html">result-column:</a></b>
|
||
|
<button id='x1353' onclick='hideorshow("x1353","x1354")'>show</button></p>
|
||
|
<div id='x1354' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram result-column" src="images/syntax/result-column.gif" />
|
||
|
</div>
|
||
|
<p><b><a href="syntax/table-or-subquery.html">table-or-subquery:</a></b>
|
||
|
<button id='x1355' onclick='hideorshow("x1355","x1356")'>show</button></p>
|
||
|
<div id='x1356' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram table-or-subquery" src="images/syntax/table-or-subquery.gif" />
|
||
|
</div>
|
||
|
<p><b><a href="syntax/window-defn.html">window-defn:</a></b>
|
||
|
<button id='x1357' onclick='hideorshow("x1357","x1358")'>show</button></p>
|
||
|
<div id='x1358' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram window-defn" src="images/syntax/window-defn.gif" />
|
||
|
<p><b><a href="syntax/frame-spec.html">frame-spec:</a></b>
|
||
|
<button id='x1359' onclick='hideorshow("x1359","x1360")'>show</button></p>
|
||
|
<div id='x1360' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram frame-spec" src="images/syntax/frame-spec.gif" />
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<p><b><a href="syntax/type-name.html">type-name:</a></b>
|
||
|
<button id='x1361' onclick='hideorshow("x1361","x1362")'>show</button></p>
|
||
|
<div id='x1362' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram type-name" src="images/syntax/type-name.gif" />
|
||
|
<p><b><a href="syntax/signed-number.html">signed-number:</a></b>
|
||
|
<button id='x1363' onclick='hideorshow("x1363","x1364")'>show</button></p>
|
||
|
<div id='x1364' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram signed-number" src="images/syntax/signed-number.gif" />
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<p><b><a href="syntax/indexed-column.html">indexed-column:</a></b>
|
||
|
<button id='x1365' onclick='hideorshow("x1365","x1366")'>show</button></p>
|
||
|
<div id='x1366' style='display:none;' class='imgcontainer'>
|
||
|
<img alt="syntax diagram indexed-column" src="images/syntax/indexed-column.gif" />
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<p>The CREATE INDEX command consists of the keywords "CREATE INDEX" followed
|
||
|
by the name of the new index, the keyword "ON", the name of a previously
|
||
|
created table that is to be indexed, and a parenthesized list of table column
|
||
|
names and/or expressions that are used for the index key.
|
||
|
If the optional WHERE clause is included, then the index is a "<a href="partialindex.html">partial index</a>".
|
||
|
</p>
|
||
|
|
||
|
<p>If the optional IF NOT EXISTS clause is present and another index
|
||
|
with the same name already exists, then this command becomes a no-op.</p>
|
||
|
|
||
|
<p>There are no arbitrary limits on the number of indices that can be
|
||
|
attached to a single table. The number of columns in an index is
|
||
|
limited to the value set by
|
||
|
<a href="c3ref/limit.html">sqlite3_limit</a>(<a href="c3ref/c_limit_attached.html#sqlitelimitcolumn">SQLITE_LIMIT_COLUMN</a>,...).</p>
|
||
|
|
||
|
<p>Indexes are removed with the <a href="lang_dropindex.html">DROP INDEX</a> command.</p>
|
||
|
|
||
|
<a name="uniqueidx"></a>
|
||
|
|
||
|
<h2 id="unique_indexes"><span>1.1. </span>Unique Indexes</h2>
|
||
|
|
||
|
<p>If the UNIQUE keyword appears between CREATE and INDEX then duplicate
|
||
|
index entries are not allowed. Any attempt to insert a duplicate entry
|
||
|
will result in an error.</p>
|
||
|
|
||
|
<p>For the purposes of unique indices, all NULL values
|
||
|
are considered different from all other NULL values and are thus unique.
|
||
|
This is one of the two possible interpretations of the SQL-92 standard
|
||
|
(the language in the standard is ambiguous). The interpretation used
|
||
|
by SQLite is the same and is the interpretation
|
||
|
followed by PostgreSQL, MySQL, Firebird, and Oracle. Informix and
|
||
|
Microsoft SQL Server follow the other interpretation of the standard, which
|
||
|
is that all NULL values are equal to one another.</p>
|
||
|
|
||
|
<a name="indexexpr"></a>
|
||
|
|
||
|
<h2 id="indexes_on_expressions"><span>1.2. </span>Indexes on Expressions</h2>
|
||
|
|
||
|
<p>Expressions in an index may not reference other tables
|
||
|
and may not use subqueries nor functions whose result might
|
||
|
change (ex: <a href="lang_corefunc.html#random">random()</a> or <a href="lang_corefunc.html#sqlite_version">sqlite_version()</a>).
|
||
|
Expressions in an index may only refer to columns in the table
|
||
|
that is being indexed.
|
||
|
Indexes on expression will not work with versions of SQLite prior
|
||
|
to <a href="releaselog/3_9_0.html">version 3.9.0</a> (2015-10-14).
|
||
|
See the <a href="expridx.html">Indexes On Expressions</a> document for additional information
|
||
|
about using general expressions in CREATE INDEX statements.
|
||
|
|
||
|
<a name="descidx"></a>
|
||
|
|
||
|
</p><h2 id="descending_indexes"><span>1.3. </span>Descending Indexes</h2>
|
||
|
|
||
|
<p>Each column name or expression can be followed by one
|
||
|
of the "ASC" or "DESC" keywords to indicate sort order.
|
||
|
The sort order may or may not be ignored depending
|
||
|
on the database file format, and in particular the <a href="fileformat2.html#schemaformat">schema format number</a>.
|
||
|
The "legacy" schema format (1) ignores index
|
||
|
sort order. The descending index schema format (4) takes index sort order
|
||
|
into account. Only versions of SQLite 3.3.0 (2006-01-11)
|
||
|
and later are able to understand
|
||
|
the descending index format. For compatibility, version of SQLite between 3.3.0
|
||
|
and 3.7.9 use the legacy schema format by default. The newer schema format is
|
||
|
used by default in version 3.7.10 (2012-01-16) and later.
|
||
|
The <a href="pragma.html#pragma_legacy_file_format">legacy_file_format pragma</a> can be used to change set the specific
|
||
|
behavior for any version of SQLite.</p>
|
||
|
|
||
|
<h2 id="nulls_first_and_nulls_last"><span>1.4. </span>NULLS FIRST and NULLS LAST</h2>
|
||
|
|
||
|
<p>The NULLS FIRST and NULLS LAST predicates are not supported
|
||
|
for indexes. For <a href="datatype3.html#sortorder">sorting purposes</a>, SQLite considers NULL values
|
||
|
to be smaller than all other values. Hence NULL values always appear at
|
||
|
the beginning of an ASC index and at the end of a DESC index.</p>
|
||
|
|
||
|
<a name="collidx"></a>
|
||
|
|
||
|
<h2 id="collations"><span>1.5. </span>Collations</h2>
|
||
|
|
||
|
<p>The COLLATE clause optionally following each column name
|
||
|
or expression defines a
|
||
|
collating sequence used for text entries in that column.
|
||
|
The default collating
|
||
|
sequence is the collating sequence defined for that column in the
|
||
|
<a href="lang_createtable.html">CREATE TABLE</a> statement. Or if no collating sequence is otherwise defined,
|
||
|
the built-in BINARY collating sequence is used.</p>
|
||
|
|