0000: 23 0a 23 20 52 75 6e 20 74 68 69 73 20 54 63 6c #.# Run this Tcl
0010: 20 73 63 72 69 70 74 20 74 6f 20 67 65 6e 65 72 script to gener
0020: 61 74 65 20 74 68 65 20 73 71 6c 69 74 65 2e 68 ate the sqlite.h
0030: 74 6d 6c 20 66 69 6c 65 2e 0a 23 0a 73 65 74 20 tml file..#.set
0040: 72 63 73 69 64 20 7b 24 49 64 3a 20 6c 61 6e 67 rcsid {$Id: lang
0050: 2e 74 63 6c 2c 76 20 31 2e 32 34 20 32 30 30 32 .tcl,v 1.24 2002
0060: 2f 30 32 2f 31 38 20 31 38 3a 33 30 3a 33 33 20 /02/18 18:30:33
0070: 64 72 68 20 45 78 70 20 24 7d 0a 0a 70 75 74 73 drh Exp $}..puts
0080: 20 7b 3c 68 74 6d 6c 3e 0a 3c 68 65 61 64 3e 0a {<html>.<head>.
0090: 20 20 3c 74 69 74 6c 65 3e 51 75 65 72 79 20 4c <title>Query L
00a0: 61 6e 67 75 61 67 65 20 55 6e 64 65 72 73 74 6f anguage Understo
00b0: 6f 64 20 42 79 20 53 51 4c 69 74 65 3c 2f 74 69 od By SQLite</ti
00c0: 74 6c 65 3e 0a 3c 2f 68 65 61 64 3e 0a 3c 62 6f tle>.</head>.<bo
00d0: 64 79 20 62 67 63 6f 6c 6f 72 3d 77 68 69 74 65 dy bgcolor=white
00e0: 3e 0a 3c 68 31 20 61 6c 69 67 6e 3d 63 65 6e 74 >.<h1 align=cent
00f0: 65 72 3e 0a 53 51 4c 20 41 73 20 55 6e 64 65 72 er>.SQL As Under
0100: 73 74 6f 6f 64 20 42 79 20 53 51 4c 69 74 65 0a stood By SQLite.
0110: 3c 2f 68 31 3e 7d 0a 70 75 74 73 20 22 3c 70 20 </h1>}.puts "<p
0120: 61 6c 69 67 6e 3d 63 65 6e 74 65 72 3e 0a 28 54 align=center>.(T
0130: 68 69 73 20 70 61 67 65 20 77 61 73 20 6c 61 73 his page was las
0140: 74 20 6d 6f 64 69 66 69 65 64 20 6f 6e 20 5b 6c t modified on [l
0150: 72 61 6e 67 65 20 24 72 63 73 69 64 20 33 20 34 range $rcsid 3 4
0160: 5d 20 55 54 43 29 0a 3c 2f 70 3e 22 0a 0a 70 75 ] UTC).</p>"..pu
0170: 74 73 20 7b 0a 3c 70 3e 54 68 65 20 53 51 4c 69 ts {.<p>The SQLi
0180: 74 65 20 6c 69 62 72 61 72 79 20 75 6e 64 65 72 te library under
0190: 73 74 61 6e 64 73 20 6d 6f 73 74 20 6f 66 20 74 stands most of t
01a0: 68 65 20 73 74 61 6e 64 61 72 64 20 53 51 4c 0a he standard SQL.
01b0: 6c 61 6e 67 75 61 67 65 2e 20 20 42 75 74 20 69 language. But i
01c0: 74 20 64 6f 65 73 20 6f 6d 69 74 20 73 6f 6d 65 t does omit some
01d0: 20 66 65 61 74 75 72 65 73 20 77 68 69 6c 65 20 features while
01e0: 61 74 20 74 68 65 20 73 61 6d 65 20 74 69 6d 65 at the same time
01f0: 0a 61 64 64 69 6e 67 20 61 20 66 65 77 20 66 65 .adding a few fe
0200: 61 74 75 72 65 73 20 6f 66 20 69 74 73 20 6f 77 atures of its ow
0210: 6e 2e 20 20 54 68 69 73 20 64 6f 63 75 6d 65 6e n. This documen
0220: 74 20 61 74 74 65 6d 70 74 73 20 74 6f 0a 64 65 t attempts to.de
0230: 73 63 72 69 62 65 20 70 65 72 63 69 73 65 6c 79 scribe percisely
0240: 20 77 68 61 74 20 70 61 72 74 73 20 6f 66 20 74 what parts of t
0250: 68 65 20 53 51 4c 20 6c 61 6e 67 75 61 67 65 20 he SQL language
0260: 53 51 4c 69 74 65 20 64 6f 65 73 0a 61 6e 64 20 SQLite does.and
0270: 64 6f 65 73 20 6e 6f 74 20 73 75 70 70 6f 72 74 does not support
0280: 2e 3c 2f 70 3e 0a 0a 3c 70 3e 49 6e 20 61 6c 6c .</p>..<p>In all
0290: 20 6f 66 20 74 68 65 20 73 79 6e 74 61 78 20 64 of the syntax d
02a0: 69 61 67 72 61 6d 73 20 74 68 61 74 20 66 6f 6c iagrams that fol
02b0: 6c 6f 77 2c 20 6c 69 74 65 72 61 6c 20 74 65 78 low, literal tex
02c0: 74 20 69 73 20 73 68 6f 77 6e 20 69 6e 0a 62 6f t is shown in.bo
02d0: 6c 64 20 62 6c 75 65 2e 20 20 4e 6f 6e 2d 74 65 ld blue. Non-te
02e0: 72 6d 69 6e 61 6c 20 73 79 6d 62 6f 6c 73 20 61 rminal symbols a
02f0: 72 65 20 73 68 6f 77 6e 20 69 6e 20 69 74 61 6c re shown in ital
0300: 69 63 20 72 65 64 2e 20 20 4f 70 65 72 61 74 6f ic red. Operato
0310: 72 73 0a 74 68 61 74 20 61 72 65 20 70 61 72 74 rs.that are part
0320: 20 6f 66 20 74 68 65 20 73 79 6e 74 61 63 74 69 of the syntacti
0330: 63 20 6d 61 72 6b 75 70 20 69 74 73 65 6c 66 20 c markup itself
0340: 61 72 65 20 73 68 6f 77 6e 20 69 6e 20 62 6c 61 are shown in bla
0350: 63 6b 20 72 6f 6d 61 6e 2e 3c 2f 70 3e 0a 0a 3c ck roman.</p>..<
0360: 70 3e 54 68 69 73 20 64 6f 63 75 6d 65 6e 74 20 p>This document
0370: 69 73 20 6a 75 73 74 20 61 6e 20 6f 76 65 72 76 is just an overv
0380: 69 65 77 20 6f 66 20 74 68 65 20 53 51 4c 20 73 iew of the SQL s
0390: 79 6e 74 61 78 20 69 6d 70 6c 65 6d 65 6e 74 65 yntax implemente
03a0: 64 0a 62 79 20 53 51 4c 69 74 65 2e 20 20 4d 61 d.by SQLite. Ma
03b0: 6e 79 20 6c 6f 77 2d 6c 65 76 65 6c 20 70 72 6f ny low-level pro
03c0: 64 75 63 74 69 6f 6e 73 20 61 72 65 20 6f 6d 69 ductions are omi
03d0: 74 74 65 64 2e 20 20 46 6f 72 20 64 65 74 61 69 tted. For detai
03e0: 6c 65 64 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 0a led information.
03f0: 6f 6e 20 74 68 65 20 6c 61 6e 67 75 61 67 65 20 on the language
0400: 74 68 61 74 20 53 51 4c 69 74 65 20 75 6e 64 65 that SQLite unde
0410: 72 73 74 61 6e 64 73 2c 20 72 65 66 65 72 20 74 rstands, refer t
0420: 6f 20 74 68 65 20 73 6f 75 72 63 65 20 63 6f 64 o the source cod
0430: 65 2e 3c 2f 70 3e 0a 0a 0a 3c 70 3e 53 51 4c 69 e.</p>...<p>SQLi
0440: 74 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20 74 68 te implements th
0450: 65 20 66 6f 6c 6c 6f 77 20 73 79 6e 74 61 78 3a e follow syntax:
0460: 3c 2f 70 3e 0a 3c 70 3e 3c 75 6c 3e 0a 7d 0a 0a </p>.<p><ul>.}..
0470: 66 6f 72 65 61 63 68 20 7b 73 65 63 74 69 6f 6e foreach {section
0480: 7d 20 5b 6c 73 6f 72 74 20 2d 69 6e 64 65 78 20 } [lsort -index
0490: 30 20 2d 64 69 63 74 69 6f 6e 61 72 79 20 7b 0a 0 -dictionary {.
04a0: 20 20 7b 7b 43 52 45 41 54 45 20 54 41 42 4c 45 {{CREATE TABLE
04b0: 7d 20 63 72 65 61 74 65 74 61 62 6c 65 7d 0a 20 } createtable}.
04c0: 20 7b 7b 43 52 45 41 54 45 20 49 4e 44 45 58 7d {{CREATE INDEX}
04d0: 20 63 72 65 61 74 65 69 6e 64 65 78 7d 0a 20 20 createindex}.
04e0: 7b 56 41 43 55 55 4d 20 76 61 63 75 75 6d 7d 0a {VACUUM vacuum}.
04f0: 20 20 7b 7b 44 52 4f 50 20 54 41 42 4c 45 7d 20 {{DROP TABLE}
0500: 64 72 6f 70 74 61 62 6c 65 7d 0a 20 20 7b 7b 44 droptable}. {{D
0510: 52 4f 50 20 49 4e 44 45 58 7d 20 64 72 6f 70 69 ROP INDEX} dropi
0520: 6e 64 65 78 7d 0a 20 20 7b 49 4e 53 45 52 54 20 ndex}. {INSERT
0530: 69 6e 73 65 72 74 7d 0a 20 20 7b 52 45 50 4c 41 insert}. {REPLA
0540: 43 45 20 72 65 70 6c 61 63 65 7d 0a 20 20 7b 44 CE replace}. {D
0550: 45 4c 45 54 45 20 64 65 6c 65 74 65 7d 0a 20 20 ELETE delete}.
0560: 7b 55 50 44 41 54 45 20 75 70 64 61 74 65 7d 0a {UPDATE update}.
0570: 20 20 7b 53 45 4c 45 43 54 20 73 65 6c 65 63 74 {SELECT select
0580: 7d 0a 20 20 7b 43 4f 50 59 20 63 6f 70 79 7d 0a }. {COPY copy}.
0590: 20 20 7b 45 58 50 4c 41 49 4e 20 65 78 70 6c 61 {EXPLAIN expla
05a0: 69 6e 7d 0a 20 20 7b 65 78 70 72 65 73 73 69 6f in}. {expressio
05b0: 6e 20 65 78 70 72 7d 0a 20 20 7b 7b 42 45 47 49 n expr}. {{BEGI
05c0: 4e 20 54 52 41 4e 53 41 43 54 49 4f 4e 7d 20 74 N TRANSACTION} t
05d0: 72 61 6e 73 61 63 74 69 6f 6e 7d 0a 20 20 7b 50 ransaction}. {P
05e0: 52 41 47 4d 41 20 70 72 61 67 6d 61 7d 0a 20 20 RAGMA pragma}.
05f0: 7b 7b 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 63 6c {{ON CONFLICT cl
0600: 61 75 73 65 7d 20 63 6f 6e 66 6c 69 63 74 7d 0a ause} conflict}.
0610: 7d 5d 20 7b 0a 20 20 70 75 74 73 20 22 3c 6c 69 }] {. puts "<li
0620: 3e 3c 61 20 68 72 65 66 3d 5c 22 23 5b 6c 69 6e ><a href=\"#[lin
0630: 64 65 78 20 24 73 65 63 74 69 6f 6e 20 31 5d 5c dex $section 1]\
0640: 22 3e 5b 6c 69 6e 64 65 78 20 24 73 65 63 74 69 ">[lindex $secti
0650: 6f 6e 20 30 5d 3c 2f 61 3e 3c 2f 6c 69 3e 22 0a on 0]</a></li>".
0660: 7d 0a 70 75 74 73 20 7b 3c 2f 75 6c 3e 3c 2f 70 }.puts {</ul></p
0670: 3e 0a 0a 3c 70 3e 44 65 74 61 69 6c 73 20 6f 6e >..<p>Details on
0680: 20 74 68 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 the implementat
0690: 69 6f 6e 20 6f 66 20 65 61 63 68 20 63 6f 6d 6d ion of each comm
06a0: 61 6e 64 20 61 72 65 20 70 72 6f 76 69 64 65 64 and are provided
06b0: 20 69 6e 0a 74 68 65 20 73 65 71 75 65 6c 2e 3c in.the sequel.<
06c0: 2f 70 3e 0a 7d 0a 0a 70 72 6f 63 20 53 79 6e 74 /p>.}..proc Synt
06d0: 61 78 20 7b 61 72 67 73 7d 20 7b 0a 20 20 70 75 ax {args} {. pu
06e0: 74 73 20 7b 3c 74 61 62 6c 65 20 63 65 6c 6c 70 ts {<table cellp
06f0: 61 64 64 69 6e 67 3d 22 31 30 22 3e 7d 0a 20 20 adding="10">}.
0700: 66 6f 72 65 61 63 68 20 7b 72 75 6c 65 20 62 6f foreach {rule bo
0710: 64 79 7d 20 24 61 72 67 73 20 7b 0a 20 20 20 20 dy} $args {.
0720: 70 75 74 73 20 22 3c 74 72 3e 3c 74 64 20 61 6c puts "<tr><td al
0730: 69 67 6e 3d 5c 22 72 69 67 68 74 5c 22 20 76 61 ign=\"right\" va
0740: 6c 69 67 6e 3d 5c 22 74 6f 70 5c 22 3e 22 0a 20 lign=\"top\">".
0750: 20 20 20 70 75 74 73 20 22 3c 69 3e 3c 66 6f 6e puts "<i><fon
0760: 74 20 63 6f 6c 6f 72 3d 5c 22 23 66 66 33 34 33 t color=\"#ff343
0770: 34 5c 22 3e 24 72 75 6c 65 3c 2f 66 6f 6e 74 3e 4\">$rule</font>
0780: 3c 2f 69 3e 26 6e 62 73 70 3b 3a 3a 3d 3c 2f 74 </i> ::=</t
0790: 64 3e 22 0a 20 20 20 20 72 65 67 73 75 62 20 2d d>". regsub -
07a0: 61 6c 6c 20 3c 20 24 62 6f 64 79 20 7b 25 4c 54 all < $body {%LT
07b0: 7d 20 62 6f 64 79 0a 20 20 20 20 72 65 67 73 75 } body. regsu
07c0: 62 20 2d 61 6c 6c 20 3e 20 24 62 6f 64 79 20 7b b -all > $body {
07d0: 25 47 54 7d 20 62 6f 64 79 0a 20 20 20 20 72 65 %GT} body. re
07e0: 67 73 75 62 20 2d 61 6c 6c 20 25 4c 54 20 24 62 gsub -all %LT $b
07f0: 6f 64 79 20 7b 3c 2f 66 6f 6e 74 3e 3c 2f 62 3e ody {</font></b>
0800: 3c 69 3e 3c 66 6f 6e 74 20 63 6f 6c 6f 72 3d 22 <i><font color="
0810: 23 66 66 33 34 33 34 22 3e 7d 20 62 6f 64 79 0a #ff3434">} body.
0820: 20 20 20 20 72 65 67 73 75 62 20 2d 61 6c 6c 20 regsub -all
0830: 25 47 54 20 24 62 6f 64 79 20 7b 3c 2f 66 6f 6e %GT $body {</fon
0840: 74 3e 3c 2f 69 3e 3c 62 3e 3c 66 6f 6e 74 20 63 t></i><b><font c
0850: 6f 6c 6f 72 3d 22 23 32 63 32 63 66 30 22 3e 7d olor="#2c2cf0">}
0860: 20 62 6f 64 79 0a 20 20 20 20 72 65 67 73 75 62 body. regsub
0870: 20 2d 61 6c 6c 20 7b 5b 5d 7c 5b 2a 3f 5d 7d 20 -all {[]|[*?]}
0880: 24 62 6f 64 79 20 7b 3c 2f 66 6f 6e 74 3e 3c 2f $body {</font></
0890: 62 3e 26 3c 62 3e 3c 66 6f 6e 74 20 63 6f 6c 6f b>&<b><font colo
08a0: 72 3d 22 23 32 63 32 63 66 30 22 3e 7d 20 62 6f r="#2c2cf0">} bo
08b0: 64 79 0a 20 20 20 20 72 65 67 73 75 62 20 2d 61 dy. regsub -a
08c0: 6c 6c 20 22 5c 6e 22 20 5b 73 74 72 69 6e 67 20 ll "\n" [string
08d0: 74 72 69 6d 20 24 62 6f 64 79 5d 20 22 3c 62 72 trim $body] "<br
08e0: 3e 5c 6e 22 20 62 6f 64 79 0a 20 20 20 20 72 65 >\n" body. re
08f0: 67 73 75 62 20 2d 61 6c 6c 20 22 5c 6e 20 20 2a gsub -all "\n *
0900: 22 20 24 62 6f 64 79 20 22 5c 6e 5c 5c 26 6e 62 " $body "\n\\&nb
0910: 73 70 3b 5c 5c 26 6e 62 73 70 3b 5c 5c 26 6e 62 sp;\\ \\&nb
0920: 73 70 3b 5c 5c 26 6e 62 73 70 3b 22 20 62 6f 64 sp;\\ " bod
0930: 79 0a 20 20 20 20 72 65 67 73 75 62 20 2d 61 6c y. regsub -al
0940: 6c 20 7b 5b 7c 2c 2e 2a 28 29 5d 7d 20 24 62 6f l {[|,.*()]} $bo
0950: 64 79 20 7b 3c 62 69 67 3e 26 3c 2f 62 69 67 3e dy {<big>&</big>
0960: 7d 20 62 6f 64 79 0a 20 20 20 20 72 65 67 73 75 } body. regsu
0970: 62 20 2d 61 6c 6c 20 7b 20 3d 20 7d 20 24 62 6f b -all { = } $bo
0980: 64 79 20 7b 20 3c 62 69 67 3e 3d 3c 2f 62 69 67 dy { <big>=</big
0990: 3e 20 7d 20 62 6f 64 79 0a 20 20 20 20 72 65 67 > } body. reg
09a0: 73 75 62 20 2d 61 6c 6c 20 7b 53 54 41 52 7d 20 sub -all {STAR}
09b0: 24 62 6f 64 79 20 7b 3c 62 69 67 3e 2a 3c 2f 62 $body {<big>*</b
09c0: 69 67 3e 7d 20 62 6f 64 79 0a 20 20 20 20 70 75 ig>} body. pu
09d0: 74 73 20 22 3c 74 64 3e 3c 62 3e 3c 66 6f 6e 74 ts "<td><b><font
09e0: 20 63 6f 6c 6f 72 3d 5c 22 23 32 63 32 63 66 30 color=\"#2c2cf0
09f0: 5c 22 3e 24 62 6f 64 79 3c 2f 66 6f 6e 74 3e 3c \">$body</font><
0a00: 2f 62 3e 3c 2f 74 64 3e 3c 2f 74 72 3e 22 0a 20 /b></td></tr>".
0a10: 20 7d 0a 20 20 70 75 74 73 20 7b 3c 2f 74 61 62 }. puts {</tab
0a20: 6c 65 3e 7d 0a 7d 0a 70 72 6f 63 20 4f 70 65 72 le>}.}.proc Oper
0a30: 61 74 6f 72 20 7b 6e 61 6d 65 7d 20 7b 0a 20 20 ator {name} {.
0a40: 72 65 74 75 72 6e 20 22 3c 66 6f 6e 74 20 63 6f return "<font co
0a50: 6c 6f 72 3d 5c 22 23 32 63 32 63 66 30 5c 22 3e lor=\"#2c2cf0\">
0a60: 3c 62 69 67 3e 24 6e 61 6d 65 3c 2f 62 69 67 3e <big>$name</big>
0a70: 3c 2f 66 6f 6e 74 3e 22 0a 7d 0a 70 72 6f 63 20 </font>".}.proc
0a80: 4e 6f 6e 74 65 72 6d 69 6e 61 6c 20 7b 6e 61 6d Nonterminal {nam
0a90: 65 7d 20 7b 0a 20 20 72 65 74 75 72 6e 20 22 3c e} {. return "<
0aa0: 69 3e 3c 66 6f 6e 74 20 63 6f 6c 6f 72 3d 5c 22 i><font color=\"
0ab0: 23 66 66 33 34 33 34 5c 22 3e 24 6e 61 6d 65 3c #ff3434\">$name<
0ac0: 2f 66 6f 6e 74 3e 3c 2f 69 3e 22 0a 7d 0a 70 72 /font></i>".}.pr
0ad0: 6f 63 20 4b 65 79 77 6f 72 64 20 7b 6e 61 6d 65 oc Keyword {name
0ae0: 7d 20 7b 0a 20 20 72 65 74 75 72 6e 20 22 3c 66 } {. return "<f
0af0: 6f 6e 74 20 63 6f 6c 6f 72 3d 5c 22 23 32 63 32 ont color=\"#2c2
0b00: 63 66 30 5c 22 3e 24 6e 61 6d 65 3c 2f 66 6f 6e cf0\">$name</fon
0b10: 74 3e 22 0a 7d 0a 20 0a 0a 70 72 6f 63 20 53 65 t>".}. ..proc Se
0b20: 63 74 69 6f 6e 20 7b 6e 61 6d 65 20 7b 6c 61 62 ction {name {lab
0b30: 65 6c 20 7b 7d 7d 7d 20 7b 0a 20 20 70 75 74 73 el {}}} {. puts
0b40: 20 22 5c 6e 3c 68 72 20 2f 3e 22 0a 20 20 69 66 "\n<hr />". if
0b50: 20 7b 24 6c 61 62 65 6c 21 3d 22 22 7d 20 7b 0a {$label!=""} {.
0b60: 20 20 20 20 70 75 74 73 20 22 3c 61 20 6e 61 6d puts "<a nam
0b70: 65 3d 5c 22 24 6c 61 62 65 6c 5c 22 3e 22 0a 20 e=\"$label\">".
0b80: 20 7d 0a 20 20 70 75 74 73 20 22 3c 68 31 3e 24 }. puts "<h1>$
0b90: 6e 61 6d 65 3c 2f 68 31 3e 5c 6e 22 0a 7d 0a 0a name</h1>\n".}..
0ba0: 70 72 6f 63 20 45 78 61 6d 70 6c 65 20 7b 74 65 proc Example {te
0bb0: 78 74 7d 20 7b 0a 20 20 70 75 74 73 20 22 3c 62 xt} {. puts "<b
0bc0: 6c 6f 63 6b 71 75 6f 74 65 3e 3c 70 72 65 3e 24 lockquote><pre>$
0bd0: 74 65 78 74 3c 2f 70 72 65 3e 3c 2f 62 6c 6f 63 text</pre></bloc
0be0: 6b 71 75 6f 74 65 3e 22 0a 7d 0a 0a 53 65 63 74 kquote>".}..Sect
0bf0: 69 6f 6e 20 7b 42 45 47 49 4e 20 54 52 41 4e 53 ion {BEGIN TRANS
0c00: 41 43 54 49 4f 4e 7d 20 63 72 65 61 74 65 69 6e ACTION} createin
0c10: 64 65 78 0a 0a 53 79 6e 74 61 78 20 7b 73 71 6c dex..Syntax {sql
0c20: 2d 73 74 61 74 65 6d 65 6e 74 7d 20 7b 0a 42 45 -statement} {.BE
0c30: 47 49 4e 20 5b 54 52 41 4e 53 41 43 54 49 4f 4e GIN [TRANSACTION
0c40: 20 5b 3c 6e 61 6d 65 3e 5d 5d 20 5b 4f 4e 20 43 [<name>]] [ON C
0c50: 4f 4e 46 4c 49 43 54 20 3c 63 6f 6e 66 6c 69 63 ONFLICT <conflic
0c60: 74 2d 61 6c 67 6f 72 69 74 68 6d 3e 5d 0a 7d 0a t-algorithm>].}.
0c70: 53 79 6e 74 61 78 20 7b 73 71 6c 2d 73 74 61 74 Syntax {sql-stat
0c80: 65 6d 65 6e 74 7d 20 7b 0a 45 4e 44 20 5b 54 52 ement} {.END [TR
0c90: 41 4e 53 41 43 54 49 4f 4e 20 5b 3c 6e 61 6d 65 ANSACTION [<name
0ca0: 3e 5d 5d 0a 7d 0a 53 79 6e 74 61 78 20 7b 73 71 >]].}.Syntax {sq
0cb0: 6c 2d 73 74 61 74 65 6d 65 6e 74 7d 20 7b 0a 43 l-statement} {.C
0cc0: 4f 4d 4d 49 54 20 5b 54 52 41 4e 53 41 43 54 49 OMMIT [TRANSACTI
0cd0: 4f 4e 20 5b 3c 6e 61 6d 65 3e 5d 5d 0a 7d 0a 53 ON [<name>]].}.S
0ce0: 79 6e 74 61 78 20 7b 73 71 6c 2d 73 74 61 74 65 yntax {sql-state
0cf0: 6d 65 6e 74 7d 20 7b 0a 52 4f 4c 4c 42 41 43 4b ment} {.ROLLBACK
0d00: 20 5b 54 52 41 4e 53 41 43 54 49 4f 4e 20 5b 3c [TRANSACTION [<
0d10: 6e 61 6d 65 3e 5d 5d 0a 7d 0a 0a 70 75 74 73 20 name>]].}..puts
0d20: 7b 0a 3c 70 3e 42 65 67 69 6e 6e 69 6e 67 20 69 {.<p>Beginning i
0d30: 6e 20 76 65 72 73 69 6f 6e 20 32 2e 30 2c 20 53 n version 2.0, S
0d40: 51 4c 69 74 65 20 73 75 70 70 6f 72 74 73 20 74 QLite supports t
0d50: 72 61 6e 73 61 63 74 69 6f 6e 73 20 77 69 74 68 ransactions with
0d60: 0a 72 6f 6c 6c 62 61 63 6b 20 61 6e 64 20 61 74 .rollback and at
0d70: 6f 6d 69 63 20 63 6f 6d 6d 69 74 2e 3c 2f 70 3e omic commit.</p>
0d80: 0a 0a 3c 70 3e 0a 4e 6f 20 63 68 61 6e 67 65 73 ..<p>.No changes
0d90: 20 63 61 6e 20 62 65 20 6d 61 64 65 20 74 6f 20 can be made to
0da0: 74 68 65 20 64 61 74 61 62 61 73 65 20 65 78 63 the database exc
0db0: 65 70 74 20 77 69 74 68 69 6e 20 61 20 74 72 61 ept within a tra
0dc0: 6e 73 61 63 74 69 6f 6e 2e 0a 41 6e 79 20 63 6f nsaction..Any co
0dd0: 6d 6d 61 6e 64 20 74 68 61 74 20 63 68 61 6e 67 mmand that chang
0de0: 65 73 20 74 68 65 20 64 61 74 61 62 61 73 65 20 es the database
0df0: 28 62 61 73 69 63 61 6c 6c 79 2c 20 61 6e 79 20 (basically, any
0e00: 53 51 4c 20 63 6f 6d 6d 61 6e 64 0a 6f 74 68 65 SQL command.othe
0e10: 72 20 74 68 61 6e 20 53 45 4c 45 43 54 29 20 77 r than SELECT) w
0e20: 69 6c 6c 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c ill automaticall
0e30: 79 20 73 74 61 72 74 73 20 61 20 74 72 61 6e 73 y starts a trans
0e40: 61 63 74 69 6f 6e 20 69 66 0a 6f 6e 65 20 69 73 action if.one is
0e50: 20 6e 6f 74 20 61 6c 72 65 61 64 79 20 69 6e 20 not already in
0e60: 65 66 66 65 63 74 2e 20 20 41 75 74 6f 6d 61 74 effect. Automat
0e70: 69 63 61 6c 6c 79 20 73 74 61 72 65 64 20 74 72 ically stared tr
0e80: 61 6e 73 61 63 74 69 6f 6e 73 0a 61 72 65 20 63 ansactions.are c
0e90: 6f 6d 6d 69 74 74 65 64 20 61 74 20 74 68 65 20 ommitted at the
0ea0: 63 6f 6e 63 6c 75 73 69 6f 6e 20 6f 66 20 74 68 conclusion of th
0eb0: 65 20 63 6f 6d 6d 61 6e 64 2e 0a 3c 2f 70 3e 0a e command..</p>.
0ec0: 0a 3c 70 3e 0a 54 72 61 6e 73 61 63 74 69 6f 6e .<p>.Transaction
0ed0: 73 20 63 61 6e 20 62 65 20 73 74 61 72 74 65 64 s can be started
0ee0: 20 6d 61 6e 75 61 6c 6c 79 20 75 73 69 6e 67 20 manually using
0ef0: 74 68 65 20 42 45 47 49 4e 0a 63 6f 6d 6d 61 6e the BEGIN.comman
0f00: 64 2e 20 53 75 63 68 20 74 72 61 6e 73 61 63 74 d. Such transact
0f10: 69 6f 6e 73 20 75 73 75 61 6c 6c 79 20 70 65 72 ions usually per
0f20: 73 69 73 74 20 75 6e 74 69 6c 20 74 68 65 20 6e sist until the n
0f30: 65 78 74 0a 43 4f 4d 4d 49 54 20 6f 72 20 52 4f ext.COMMIT or RO
0f40: 4c 4c 42 41 43 4b 20 63 6f 6d 6d 61 6e 64 2e 20 LLBACK command.
0f50: 42 75 74 20 61 20 74 72 61 6e 73 61 63 74 69 6f But a transactio
0f60: 6e 20 77 69 6c 6c 20 61 6c 73 6f 20 0a 52 4f 4c n will also .ROL
0f70: 4c 42 41 43 4b 20 69 66 20 74 68 65 20 64 61 74 LBACK if the dat
0f80: 61 62 61 73 65 20 69 73 20 63 6c 6f 73 65 64 20 abase is closed
0f90: 6f 72 20 69 66 20 61 6e 20 65 72 72 6f 72 20 6f or if an error o
0fa0: 63 63 75 72 73 0a 61 6e 64 20 74 68 65 20 52 4f ccurs.and the RO
0fb0: 4c 4c 42 41 43 4b 20 63 6f 6e 66 6c 69 63 74 20 LLBACK conflict
0fc0: 72 65 73 6f 6c 75 74 69 6f 6e 20 61 6c 67 6f 72 resolution algor
0fd0: 69 74 68 6d 20 69 73 20 73 70 65 63 69 66 69 65 ithm is specifie
0fe0: 64 2e 0a 53 65 65 20 74 68 65 20 64 6f 63 75 6d d..See the docum
0ff0: 65 6e 74 69 6f 6e 20 6f 6e 20 74 68 65 20 3c 61 ention on the <a
1000: 20 68 72 65 66 3d 22 23 63 6f 6e 66 6c 69 63 74 href="#conflict
1010: 22 3e 4f 4e 20 43 4f 4e 46 4c 49 43 54 3c 2f 61 ">ON CONFLICT</a
1020: 3e 0a 63 6c 61 75 73 65 20 66 6f 72 20 61 64 64 >.clause for add
1030: 69 74 69 6f 6e 61 6c 20 69 6e 66 6f 72 6d 61 74 itional informat
1040: 69 6f 6e 20 61 62 6f 75 74 20 74 68 65 20 52 4f ion about the RO
1050: 4c 4c 42 41 43 4b 0a 63 6f 6e 66 6c 69 63 74 20 LLBACK.conflict
1060: 72 65 73 6f 6c 75 74 69 6f 6e 20 61 6c 67 6f 72 resolution algor
1070: 69 74 68 6d 2e 0a 3c 2f 70 3e 0a 0a 3c 70 3e 0a ithm..</p>..<p>.
1080: 54 68 65 20 6f 70 74 69 6f 6e 61 6c 20 4f 4e 20 The optional ON
1090: 43 4f 4e 46 4c 49 43 54 20 63 6c 61 75 73 65 20 CONFLICT clause
10a0: 61 74 20 74 68 65 20 65 6e 64 20 6f 66 20 61 20 at the end of a
10b0: 42 45 47 49 4e 20 73 74 61 74 65 6d 65 6e 74 0a BEGIN statement.
10c0: 63 61 6e 20 62 65 20 75 73 65 64 20 74 6f 20 63 can be used to c
10d0: 68 61 6e 67 65 64 20 74 68 65 20 64 65 66 61 75 hanged the defau
10e0: 6c 74 20 63 6f 6e 66 6c 69 63 74 20 72 65 73 6f lt conflict reso
10f0: 6c 75 74 69 6f 6e 20 61 6c 67 6f 72 69 74 68 6d lution algorithm
1100: 2e 0a 54 68 65 20 6e 6f 72 6d 61 6c 20 64 65 66 ..The normal def
1110: 61 75 6c 74 20 69 73 20 41 42 4f 52 54 2e 20 20 ault is ABORT.
1120: 49 66 20 61 6e 20 61 6c 74 65 72 6e 61 74 69 76 If an alternativ
1130: 65 20 69 73 20 73 70 65 63 69 66 69 65 64 20 62 e is specified b
1140: 79 0a 74 68 65 20 4f 4e 20 43 4f 4e 46 4c 49 43 y.the ON CONFLIC
1150: 54 20 63 6c 61 75 73 65 20 6f 66 20 61 20 42 45 T clause of a BE
1160: 47 49 4e 2c 20 74 68 65 6e 20 74 68 61 74 20 61 GIN, then that a
1170: 6c 74 65 72 6e 61 74 69 76 65 20 69 73 20 75 73 lternative is us
1180: 65 64 0a 61 73 20 74 68 65 20 64 65 66 61 75 6c ed.as the defaul
1190: 74 20 66 6f 72 20 61 6c 6c 20 63 6f 6d 6d 61 6e t for all comman
11a0: 64 73 20 77 69 74 68 69 6e 20 74 68 65 20 74 72 ds within the tr
11b0: 61 6e 73 61 63 74 69 6f 6e 2e 20 20 54 68 65 20 ansaction. The
11c0: 64 65 66 61 75 6c 74 0a 61 6c 67 6f 72 69 74 68 default.algorith
11d0: 6d 20 69 73 20 6f 76 65 72 72 69 64 64 65 6e 20 m is overridden
11e0: 62 79 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 63 by ON CONFLICT c
11f0: 6c 61 75 73 65 73 20 6f 6e 20 69 6e 64 69 76 69 lauses on indivi
1200: 64 75 61 6c 0a 63 6f 6e 73 74 72 61 69 6e 74 73 dual.constraints
1210: 20 77 69 74 68 69 6e 20 74 68 65 20 43 52 45 41 within the CREA
1220: 54 45 20 54 41 42 4c 45 20 6f 72 20 43 52 45 41 TE TABLE or CREA
1230: 54 45 20 49 4e 44 45 58 20 73 74 61 74 65 6d 65 TE INDEX stateme
1240: 6e 74 73 0a 61 6e 64 20 62 79 20 74 68 65 20 4f nts.and by the O
1250: 52 20 63 6c 61 75 73 65 73 20 6f 6e 20 43 4f 50 R clauses on COP
1260: 59 2c 20 49 4e 53 45 52 54 2c 20 61 6e 64 20 55 Y, INSERT, and U
1270: 50 44 41 54 45 20 63 6f 6d 6d 61 6e 64 73 2e 0a PDATE commands..
1280: 3c 2f 70 3e 0a 7d 0a 0a 53 65 63 74 69 6f 6e 20 </p>.}..Section
1290: 43 4f 50 59 20 63 6f 70 79 0a 0a 53 79 6e 74 61 COPY copy..Synta
12a0: 78 20 7b 73 71 6c 2d 73 74 61 74 65 6d 65 6e 74 x {sql-statement
12b0: 7d 20 7b 0a 43 4f 50 59 20 5b 20 4f 52 20 3c 63 } {.COPY [ OR <c
12c0: 6f 6e 66 6c 69 63 74 2d 61 6c 67 6f 72 69 74 68 onflict-algorith
12d0: 6d 3e 20 5d 20 3c 74 61 62 6c 65 2d 6e 61 6d 65 m> ] <table-name
12e0: 3e 20 46 52 4f 4d 20 3c 66 69 6c 65 6e 61 6d 65 > FROM <filename
12f0: 3e 0a 5b 20 55 53 49 4e 47 20 44 45 4c 49 4d 49 >.[ USING DELIMI
1300: 54 45 52 53 20 3c 64 65 6c 69 6d 3e 20 5d 0a 7d TERS <delim> ].}
1310: 0a 0a 0a 70 75 74 73 20 7b 0a 3c 70 3e 54 68 65 ...puts {.<p>The
1320: 20 43 4f 50 59 20 63 6f 6d 6d 61 6e 64 20 69 73 COPY command is
1330: 20 61 6e 20 65 78 74 65 6e 73 69 6f 6e 20 75 73 an extension us
1340: 65 64 20 74 6f 20 6c 6f 61 64 20 6c 61 72 67 65 ed to load large
1350: 20 61 6d 6f 75 6e 74 73 20 6f 66 0a 64 61 74 61 amounts of.data
1360: 20 69 6e 74 6f 20 61 20 74 61 62 6c 65 2e 20 20 into a table.
1370: 49 74 20 69 73 20 6d 6f 64 65 6c 65 64 20 61 66 It is modeled af
1380: 74 65 72 20 61 20 73 69 6d 69 6c 61 72 20 63 6f ter a similar co
1390: 6d 6d 61 6e 64 20 66 6f 75 6e 64 0a 69 6e 20 50 mmand found.in P
13a0: 6f 73 74 67 72 65 53 51 4c 2e 20 20 49 6e 20 66 ostgreSQL. In f
13b0: 61 63 74 2c 20 74 68 65 20 53 51 4c 69 74 65 20 act, the SQLite
13c0: 43 4f 50 59 20 63 6f 6d 6d 61 6e 64 20 69 73 20 COPY command is
13d0: 73 70 65 63 69 66 69 63 61 6c 6c 79 0a 64 65 73 specifically.des
13e0: 69 67 6e 65 64 20 74 6f 20 62 65 20 61 62 6c 65 igned to be able
13f0: 20 74 6f 20 72 65 61 64 20 74 68 65 20 6f 75 74 to read the out
1400: 70 75 74 20 6f 66 20 74 68 65 20 50 6f 73 74 67 put of the Postg
1410: 72 65 53 51 4c 20 64 75 6d 70 0a 75 74 69 6c 69 reSQL dump.utili
1420: 74 79 20 3c 62 3e 70 67 5f 64 75 6d 70 3c 2f 62 ty <b>pg_dump</b
1430: 3e 20 73 6f 20 74 68 61 74 20 64 61 74 61 20 63 > so that data c
1440: 61 6e 20 62 65 20 65 61 73 69 6c 79 20 74 72 61 an be easily tra
1450: 6e 73 66 65 72 72 65 64 20 66 72 6f 6d 0a 50 6f nsferred from.Po
1460: 73 74 67 72 65 53 51 4c 20 69 6e 74 6f 20 53 51 stgreSQL into SQ
1470: 4c 69 74 65 2e 3c 70 3e 0a 0a 3c 70 3e 54 68 65 Lite.<p>..<p>The
1480: 20 74 61 62 6c 65 2d 6e 61 6d 65 20 69 73 20 74 table-name is t
1490: 68 65 20 6e 61 6d 65 20 6f 66 20 61 6e 20 65 78 he name of an ex
14a0: 69 73 74 69 6e 67 20 74 61 62 6c 65 20 77 68 69 isting table whi
14b0: 63 68 20 69 73 20 74 6f 0a 62 65 20 66 69 6c 6c ch is to.be fill
14c0: 65 64 20 77 69 74 68 20 64 61 74 61 2e 20 20 54 ed with data. T
14d0: 68 65 20 66 69 6c 65 6e 61 6d 65 20 69 73 20 61 he filename is a
14e0: 20 73 74 72 69 6e 67 20 6f 72 20 69 64 65 6e 74 string or ident
14f0: 69 66 69 65 72 20 74 68 61 74 0a 6e 61 6d 65 73 ifier that.names
1500: 20 61 20 66 69 6c 65 20 66 72 6f 6d 20 77 68 69 a file from whi
1510: 63 68 20 64 61 74 61 20 77 69 6c 6c 20 62 65 20 ch data will be
1520: 72 65 61 64 2e 20 20 54 68 65 20 66 69 6c 65 6e read. The filen
1530: 61 6d 65 20 63 61 6e 20 62 65 0a 74 68 65 20 3c ame can be.the <
1540: 62 3e 53 54 44 49 4e 3c 2f 62 3e 20 74 6f 20 72 b>STDIN</b> to r
1550: 65 61 64 20 64 61 74 61 20 66 72 6f 6d 20 73 74 ead data from st
1560: 61 6e 64 61 72 64 20 69 6e 70 75 74 2e 3c 70 3e andard input.<p>
1570: 0a 0a 3c 70 3e 45 61 63 68 20 6c 69 6e 65 20 6f ..<p>Each line o
1580: 66 20 74 68 65 20 69 6e 70 75 74 20 66 69 6c 65 f the input file
1590: 20 69 73 20 63 6f 6e 76 65 72 74 65 64 20 69 6e is converted in
15a0: 74 6f 20 61 20 73 69 6e 67 6c 65 20 72 65 63 6f to a single reco
15b0: 72 64 0a 69 6e 20 74 68 65 20 74 61 62 6c 65 2e rd.in the table.
15c0: 20 20 43 6f 6c 75 6d 6e 73 20 61 72 65 20 73 65 Columns are se
15d0: 70 61 72 61 74 65 64 20 62 79 20 74 61 62 73 2e parated by tabs.
15e0: 20 20 49 66 20 61 20 74 61 62 20 6f 63 63 75 72 If a tab occur
15f0: 73 20 61 73 0a 64 61 74 61 20 77 69 74 68 69 6e s as.data within
1600: 20 61 20 63 6f 6c 75 6d 6e 2c 20 74 68 65 6e 20 a column, then
1610: 74 68 61 74 20 74 61 62 20 69 73 20 70 72 65 63 that tab is prec
1620: 65 64 65 64 20 62 79 20 61 20 62 61 73 6b 73 6c eded by a basksl
1630: 61 73 68 20 22 5c 22 0a 63 68 61 72 61 63 74 65 ash "\".characte
1640: 72 2e 20 20 41 20 62 61 73 6b 73 6c 61 73 68 20 r. A baskslash
1650: 69 6e 20 74 68 65 20 64 61 74 61 20 61 70 70 65 in the data appe
1660: 61 72 73 20 61 73 20 74 77 6f 20 62 61 63 6b 73 ars as two backs
1670: 6c 61 73 68 65 73 20 69 6e 0a 61 20 72 6f 77 2e lashes in.a row.
1680: 20 20 54 68 65 20 6f 70 74 69 6f 6e 61 6c 20 55 The optional U
1690: 53 49 4e 47 20 44 45 4c 49 4d 49 54 45 52 53 20 SING DELIMITERS
16a0: 63 6c 61 75 73 65 20 63 61 6e 20 73 70 65 63 69 clause can speci
16b0: 66 79 20 61 20 64 65 6c 69 6d 69 74 65 72 0a 6f fy a delimiter.o
16c0: 74 68 65 72 20 74 68 61 6e 20 74 61 62 2e 3c 2f ther than tab.</
16d0: 70 3e 0a 0a 3c 70 3e 49 66 20 61 20 63 6f 6c 75 p>..<p>If a colu
16e0: 6d 6e 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 74 mn consists of t
16f0: 68 65 20 63 68 61 72 61 63 74 65 72 20 22 5c 4e he character "\N
1700: 22 2c 20 74 68 61 74 20 63 6f 6c 75 6d 6e 20 69 ", that column i
1710: 73 20 66 69 6c 6c 65 64 0a 77 69 74 68 20 74 68 s filled.with th
1720: 65 20 76 61 6c 75 65 20 4e 55 4c 4c 2e 3c 2f 70 e value NULL.</p
1730: 3e 0a 0a 3c 70 3e 54 68 65 20 6f 70 74 69 6f 6e >..<p>The option
1740: 61 6c 20 63 6f 6e 66 6c 69 63 74 2d 63 6c 61 75 al conflict-clau
1750: 73 65 20 61 6c 6c 6f 77 73 20 74 68 65 20 73 70 se allows the sp
1760: 65 63 69 66 69 63 61 74 69 6f 6e 20 6f 66 20 61 ecification of a
1770: 6e 20 61 6c 74 65 72 6e 61 74 69 76 65 0a 63 6f n alternative.co
1780: 6e 73 74 72 61 69 6e 74 20 63 6f 6e 66 6c 69 63 nstraint conflic
1790: 74 20 72 65 73 6f 6c 75 74 69 6f 6e 20 61 6c 67 t resolution alg
17a0: 6f 72 69 74 68 6d 20 74 6f 20 75 73 65 20 66 6f orithm to use fo
17b0: 72 20 74 68 69 73 20 6f 6e 65 20 63 6f 6d 6d 61 r this one comma
17c0: 6e 64 2e 0a 53 65 65 20 74 68 65 20 73 65 63 74 nd..See the sect
17d0: 69 6f 6e 20 74 69 74 6c 65 64 0a 3c 61 20 68 72 ion titled.<a hr
17e0: 65 66 3d 22 23 63 6f 6e 66 6c 69 63 74 22 3e 4f ef="#conflict">O
17f0: 4e 20 43 4f 4e 46 4c 49 43 54 3c 2f 61 3e 20 66 N CONFLICT</a> f
1800: 6f 72 20 61 64 64 69 74 69 6f 6e 61 6c 20 69 6e or additional in
1810: 66 6f 72 6d 61 74 69 6f 6e 2e 3c 2f 70 3e 0a 0a formation.</p>..
1820: 3c 70 3e 57 68 65 6e 20 74 68 65 20 69 6e 70 75 <p>When the inpu
1830: 74 20 64 61 74 61 20 73 6f 75 72 63 65 20 69 73 t data source is
1840: 20 53 54 44 49 4e 2c 20 74 68 65 20 69 6e 70 75 STDIN, the inpu
1850: 74 20 63 61 6e 20 62 65 20 74 65 72 6d 69 6e 61 t can be termina
1860: 74 65 64 0a 62 79 20 61 20 6c 69 6e 65 20 74 68 ted.by a line th
1870: 61 74 20 63 6f 6e 74 61 69 6e 73 20 6f 6e 6c 79 at contains only
1880: 20 61 20 62 61 73 6b 73 6c 61 73 68 20 61 6e 64 a baskslash and
1890: 20 61 20 64 6f 74 3a 7d 0a 70 75 74 73 20 22 5c a dot:}.puts "\
18a0: 22 5b 4f 70 65 72 61 74 6f 72 20 5c 5c 2e 5d 5c "[Operator \\.]\
18b0: 22 2e 3c 2f 70 3e 22 0a 0a 53 65 63 74 69 6f 6e ".</p>"..Section
18c0: 20 7b 43 52 45 41 54 45 20 49 4e 44 45 58 7d 20 {CREATE INDEX}
18d0: 63 72 65 61 74 65 69 6e 64 65 78 0a 0a 53 79 6e createindex..Syn
18e0: 74 61 78 20 7b 73 71 6c 2d 73 74 61 74 65 6d 65 tax {sql-stateme
18f0: 6e 74 7d 20 7b 0a 43 52 45 41 54 45 20 5b 55 4e nt} {.CREATE [UN
1900: 49 51 55 45 5d 20 49 4e 44 45 58 20 3c 69 6e 64 IQUE] INDEX <ind
1910: 65 78 2d 6e 61 6d 65 3e 20 0a 4f 4e 20 3c 74 61 ex-name> .ON <ta
1920: 62 6c 65 2d 6e 61 6d 65 3e 20 28 20 3c 63 6f 6c ble-name> ( <col
1930: 75 6d 6e 2d 6e 61 6d 65 3e 20 5b 2c 20 3c 63 6f umn-name> [, <co
1940: 6c 75 6d 6e 2d 6e 61 6d 65 3e 5d 2a 20 29 0a 5b lumn-name>]* ).[
1950: 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 3c 63 6f ON CONFLICT <co
1960: 6e 66 6c 69 63 74 2d 61 6c 67 6f 72 69 74 68 6d nflict-algorithm
1970: 3e 20 5d 0a 7d 20 7b 63 6f 6c 75 6d 6e 2d 6e 61 > ].} {column-na
1980: 6d 65 7d 20 7b 0a 3c 6e 61 6d 65 3e 20 5b 20 41 me} {.<name> [ A
1990: 53 43 20 7c 20 44 45 53 43 20 5d 0a 7d 0a 0a 0a SC | DESC ].}...
19a0: 70 75 74 73 20 7b 0a 3c 70 3e 54 68 65 20 43 52 puts {.<p>The CR
19b0: 45 41 54 45 20 49 4e 44 45 58 20 63 6f 6d 6d 61 EATE INDEX comma
19c0: 6e 64 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 74 nd consists of t
19d0: 68 65 20 6b 65 79 77 6f 72 64 73 20 22 43 52 45 he keywords "CRE
19e0: 41 54 45 20 49 4e 44 45 58 22 20 66 6f 6c 6c 6f ATE INDEX" follo
19f0: 77 65 64 0a 62 79 20 74 68 65 20 6e 61 6d 65 20 wed.by the name
1a00: 6f 66 20 74 68 65 20 6e 65 77 20 69 6e 64 65 78 of the new index
1a10: 2c 20 74 68 65 20 6b 65 79 77 6f 72 64 20 22 4f , the keyword "O
1a20: 4e 22 2c 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 N", the name of
1a30: 61 20 70 72 65 76 69 6f 75 73 6c 79 0a 63 72 65 a previously.cre
1a40: 61 74 65 64 20 74 61 62 6c 65 20 74 68 61 74 20 ated table that
1a50: 69 73 20 74 6f 20 62 65 20 69 6e 64 65 78 65 64 is to be indexed
1a60: 2c 20 61 6e 64 20 61 20 70 61 72 65 6e 74 68 65 , and a parenthe
1a70: 73 69 7a 65 64 20 6c 69 73 74 20 6f 66 20 6e 61 sized list of na
1a80: 6d 65 73 20 6f 66 0a 63 6f 6c 75 6d 6e 73 20 69 mes of.columns i
1a90: 6e 20 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 n the table that
1aa0: 20 61 72 65 20 75 73 65 64 20 66 6f 72 20 74 68 are used for th
1ab0: 65 20 69 6e 64 65 78 20 6b 65 79 2e 0a 45 61 63 e index key..Eac
1ac0: 68 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 20 63 61 h column name ca
1ad0: 6e 20 62 65 20 66 6f 6c 6c 6f 77 65 64 20 62 79 n be followed by
1ae0: 20 6f 6e 65 20 6f 66 20 74 68 65 20 22 41 53 43 one of the "ASC
1af0: 22 20 6f 72 20 22 44 45 53 43 22 20 6b 65 79 77 " or "DESC" keyw
1b00: 6f 72 64 73 0a 74 6f 20 69 6e 64 69 63 61 74 65 ords.to indicate
1b10: 20 73 6f 72 74 20 6f 72 64 65 72 2c 20 62 75 74 sort order, but
1b20: 20 74 68 65 20 73 6f 72 74 20 6f 72 64 65 72 20 the sort order
1b30: 69 73 20 69 67 6e 6f 72 65 64 20 69 6e 20 74 68 is ignored in th
1b40: 65 20 63 75 72 72 65 6e 74 0a 69 6d 70 6c 65 6d e current.implem
1b50: 65 6e 74 61 74 69 6f 6e 2e 3c 2f 70 3e 0a 0a 3c entation.</p>..<
1b60: 70 3e 54 68 65 72 65 20 61 72 65 20 6e 6f 20 61 p>There are no a
1b70: 72 62 69 74 72 61 72 79 20 6c 69 6d 69 74 73 20 rbitrary limits
1b80: 6f 6e 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 on the number of
1b90: 20 69 6e 64 69 63 65 73 20 74 68 61 74 20 63 61 indices that ca
1ba0: 6e 20 62 65 0a 61 74 74 61 63 68 65 64 20 74 6f n be.attached to
1bb0: 20 61 20 73 69 6e 67 6c 65 20 74 61 62 6c 65 2c a single table,
1bc0: 20 6e 6f 72 20 6f 6e 20 74 68 65 20 6e 75 6d 62 nor on the numb
1bd0: 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 69 6e er of columns in
1be0: 20 61 6e 20 69 6e 64 65 78 2e 3c 2f 70 3e 0a 0a an index.</p>..
1bf0: 3c 70 3e 49 66 20 74 68 65 20 55 4e 49 51 55 45 <p>If the UNIQUE
1c00: 20 6b 65 79 77 6f 72 64 20 61 70 70 65 61 72 73 keyword appears
1c10: 20 62 65 74 77 65 65 6e 20 43 52 45 41 54 45 20 between CREATE
1c20: 61 6e 64 20 49 4e 44 45 58 20 74 68 65 6e 20 64 and INDEX then d
1c30: 75 70 6c 69 63 61 74 65 0a 69 6e 64 65 78 20 65 uplicate.index e
1c40: 6e 74 72 69 65 73 20 61 72 65 20 6e 6f 74 20 61 ntries are not a
1c50: 6c 6c 6f 77 65 64 2e 20 20 41 6e 79 20 61 74 74 llowed. Any att
1c60: 65 6d 70 74 20 74 6f 20 69 6e 73 65 72 74 20 61 empt to insert a
1c70: 20 64 75 70 6c 69 63 61 74 65 20 65 6e 74 72 79 duplicate entry
1c80: 0a 77 69 6c 6c 20 72 65 73 75 6c 74 20 69 6e 20 .will result in
1c90: 61 20 72 6f 6c 6c 62 61 63 6b 20 61 6e 64 20 61 a rollback and a
1ca0: 6e 20 65 72 72 6f 72 20 6d 65 73 73 61 67 65 2e n error message.
1cb0: 3c 2f 70 3e 0a 0a 3c 70 3e 54 68 65 20 6f 70 74 </p>..<p>The opt
1cc0: 69 6f 6e 61 6c 20 63 6f 6e 66 6c 69 63 74 2d 63 ional conflict-c
1cd0: 6c 61 75 73 65 20 61 6c 6c 6f 77 73 20 74 68 65 lause allows the
1ce0: 20 73 70 65 63 69 66 69 63 61 74 69 6f 6e 20 6f specification o
1cf0: 66 20 61 6c 20 61 6c 74 65 72 6e 61 74 69 76 65 f al alternative
1d00: 0a 64 65 66 61 75 6c 74 20 63 6f 6e 73 74 72 61 .default constra
1d10: 69 6e 74 20 63 6f 6e 66 6c 69 63 74 20 72 65 73 int conflict res
1d20: 6f 6c 75 74 69 6f 6e 20 61 6c 67 6f 72 69 74 68 olution algorith
1d30: 6d 20 66 6f 72 20 74 68 69 73 20 69 6e 64 65 78 m for this index
1d40: 2e 0a 54 68 69 73 20 6f 6e 6c 79 20 6d 61 6b 65 ..This only make
1d50: 73 20 73 65 6e 73 65 20 69 66 20 74 68 65 20 55 s sense if the U
1d60: 4e 49 51 55 45 20 6b 65 79 77 6f 72 64 20 69 73 NIQUE keyword is
1d70: 20 75 73 65 64 20 73 69 6e 63 65 20 6f 74 68 65 used since othe
1d80: 72 77 69 73 65 0a 74 68 65 72 65 20 61 72 65 20 rwise.there are
1d90: 6e 6f 74 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 not constraints
1da0: 6f 6e 20 74 68 65 20 69 6e 64 65 78 2e 20 20 54 on the index. T
1db0: 68 65 20 64 65 66 61 75 6c 74 20 61 6c 67 6f 72 he default algor
1dc0: 69 74 68 6d 20 69 73 0a 41 42 4f 52 54 2e 20 20 ithm is.ABORT.
1dd0: 49 66 20 61 20 43 4f 50 59 2c 20 49 4e 53 45 52 If a COPY, INSER
1de0: 54 2c 20 6f 72 20 55 50 44 41 54 45 20 73 74 61 T, or UPDATE sta
1df0: 74 65 6d 65 6e 74 20 73 70 65 63 69 66 69 65 73 tement specifies
1e00: 20 61 20 70 61 72 74 69 63 75 6c 61 72 0a 63 6f a particular.co
1e10: 6e 66 6c 69 63 74 20 72 65 73 6f 6c 75 74 69 6f nflict resolutio
1e20: 6e 20 61 6c 67 6f 72 69 74 68 6d 2c 20 74 68 61 n algorithm, tha
1e30: 74 20 61 6c 67 6f 72 69 74 68 6d 20 69 73 20 75 t algorithm is u
1e40: 73 65 64 20 69 6e 20 70 6c 61 63 65 20 6f 66 0a sed in place of.
1e50: 74 68 65 20 64 65 66 61 75 6c 74 20 61 6c 67 6f the default algo
1e60: 72 69 74 68 6d 20 73 70 65 63 69 66 69 65 64 20 rithm specified
1e70: 68 65 72 65 2e 0a 53 65 65 20 74 68 65 20 73 65 here..See the se
1e80: 63 74 69 6f 6e 20 74 69 74 6c 65 64 0a 3c 61 20 ction titled.<a
1e90: 68 72 65 66 3d 22 23 63 6f 6e 66 6c 69 63 74 22 href="#conflict"
1ea0: 3e 4f 4e 20 43 4f 4e 46 4c 49 43 54 3c 2f 61 3e >ON CONFLICT</a>
1eb0: 20 66 6f 72 20 61 64 64 69 74 69 6f 6e 61 6c 20 for additional
1ec0: 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 3c 2f 70 3e information.</p>
1ed0: 0a 0a 3c 70 3e 54 68 65 20 65 78 61 63 74 20 74 ..<p>The exact t
1ee0: 65 78 74 0a 6f 66 20 65 61 63 68 20 43 52 45 41 ext.of each CREA
1ef0: 54 45 20 49 4e 44 45 58 20 73 74 61 74 65 6d 65 TE INDEX stateme
1f00: 6e 74 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 nt is stored in
1f10: 74 68 65 20 3c 62 3e 73 71 6c 69 74 65 5f 6d 61 the <b>sqlite_ma
1f20: 73 74 65 72 3c 2f 62 3e 0a 74 61 62 6c 65 2e 20 ster</b>.table.
1f30: 20 45 76 65 72 79 74 69 6d 65 20 74 68 65 20 64 Everytime the d
1f40: 61 74 61 62 61 73 65 20 69 73 20 6f 70 65 6e 65 atabase is opene
1f50: 64 2c 20 61 6c 6c 20 43 52 45 41 54 45 20 49 4e d, all CREATE IN
1f60: 44 45 58 20 73 74 61 74 65 6d 65 6e 74 73 0a 61 DEX statements.a
1f70: 72 65 20 72 65 61 64 20 66 72 6f 6d 20 74 68 65 re read from the
1f80: 20 3c 62 3e 73 71 6c 69 74 65 5f 6d 61 73 74 65 <b>sqlite_maste
1f90: 72 3c 2f 62 3e 20 74 61 62 6c 65 20 61 6e 64 20 r</b> table and
1fa0: 75 73 65 64 20 74 6f 20 72 65 67 65 6e 65 72 61 used to regenera
1fb0: 74 65 0a 53 51 4c 69 74 65 27 73 20 69 6e 74 65 te.SQLite's inte
1fc0: 72 6e 61 6c 20 72 65 70 72 65 73 65 6e 74 61 74 rnal representat
1fd0: 69 6f 6e 20 6f 66 20 74 68 65 20 69 6e 64 65 78 ion of the index
1fe0: 20 6c 61 79 6f 75 74 2e 3c 2f 70 3e 0a 7d 0a 0a layout.</p>.}..
1ff0: 0a 53 65 63 74 69 6f 6e 20 7b 43 52 45 41 54 45 .Section {CREATE
2000: 20 54 41 42 4c 45 7d 20 7b 63 72 65 61 74 65 74 TABLE} {createt
2010: 61 62 6c 65 7d 0a 0a 53 79 6e 74 61 78 20 7b 73 able}..Syntax {s
2020: 71 6c 2d 63 6f 6d 6d 61 6e 64 7d 20 7b 0a 43 52 ql-command} {.CR
2030: 45 41 54 45 20 5b 54 45 4d 50 20 7c 20 54 45 4d EATE [TEMP | TEM
2040: 50 4f 52 41 52 59 5d 20 54 41 42 4c 45 20 3c 74 PORARY] TABLE <t
2050: 61 62 6c 65 2d 6e 61 6d 65 3e 20 28 0a 20 20 3c able-name> (. <
2060: 63 6f 6c 75 6d 6e 2d 64 65 66 3e 20 5b 2c 20 3c column-def> [, <
2070: 63 6f 6c 75 6d 6e 2d 64 65 66 3e 5d 2a 0a 20 20 column-def>]*.
2080: 5b 2c 20 3c 63 6f 6e 73 74 72 61 69 6e 74 3e 5d [, <constraint>]
2090: 2a 0a 29 0a 7d 20 7b 73 71 6c 2d 63 6f 6d 6d 61 *.).} {sql-comma
20a0: 6e 64 7d 20 7b 0a 43 52 45 41 54 45 20 5b 54 45 nd} {.CREATE [TE
20b0: 4d 50 20 7c 20 54 45 4d 50 4f 52 41 52 59 5d 20 MP | TEMPORARY]
20c0: 54 41 42 4c 45 20 3c 74 61 62 6c 65 2d 6e 61 6d TABLE <table-nam
20d0: 65 3e 20 41 53 20 3c 73 65 6c 65 63 74 2d 73 74 e> AS <select-st
20e0: 61 74 65 6d 65 6e 74 3e 0a 7d 20 7b 63 6f 6c 75 atement>.} {colu
20f0: 6d 6e 2d 64 65 66 7d 20 7b 0a 3c 6e 61 6d 65 3e mn-def} {.<name>
2100: 20 5b 3c 74 79 70 65 3e 5d 20 5b 3c 63 6f 6c 75 [<type>] [<colu
2110: 6d 6e 2d 63 6f 6e 73 74 72 61 69 6e 74 3e 5d 2a mn-constraint>]*
2120: 0a 7d 20 7b 74 79 70 65 7d 20 7b 0a 3c 74 79 70 .} {type} {.<typ
2130: 65 6e 61 6d 65 3e 20 7c 0a 3c 74 79 70 65 6e 61 ename> |.<typena
2140: 6d 65 3e 20 28 20 3c 6e 75 6d 62 65 72 3e 20 29 me> ( <number> )
2150: 20 7c 0a 3c 74 79 70 65 6e 61 6d 65 3e 20 28 20 |.<typename> (
2160: 3c 6e 75 6d 62 65 72 3e 20 2c 20 3c 6e 75 6d 62 <number> , <numb
2170: 65 72 3e 20 29 0a 7d 20 7b 63 6f 6c 75 6d 6e 2d er> ).} {column-
2180: 63 6f 6e 73 74 72 61 69 6e 74 7d 20 7b 0a 4e 4f constraint} {.NO
2190: 54 20 4e 55 4c 4c 20 5b 20 3c 63 6f 6e 66 6c 69 T NULL [ <confli
21a0: 63 74 2d 63 6c 61 75 73 65 3e 20 5d 20 7c 0a 50 ct-clause> ] |.P
21b0: 52 49 4d 41 52 59 20 4b 45 59 20 5b 3c 73 6f 72 RIMARY KEY [<sor
21c0: 74 2d 6f 72 64 65 72 3e 5d 20 5b 20 3c 63 6f 6e t-order>] [ <con
21d0: 66 6c 69 63 74 2d 63 6c 61 75 73 65 3e 20 5d 20 flict-clause> ]
21e0: 7c 0a 55 4e 49 51 55 45 20 5b 20 3c 63 6f 6e 66 |.UNIQUE [ <conf
21f0: 6c 69 63 74 2d 63 6c 61 75 73 65 3e 20 5d 20 7c lict-clause> ] |
2200: 0a 43 48 45 43 4b 20 28 20 3c 65 78 70 72 3e 20 .CHECK ( <expr>
2210: 29 20 5b 20 3c 63 6f 6e 66 6c 69 63 74 2d 63 6c ) [ <conflict-cl
2220: 61 75 73 65 3e 20 5d 20 7c 0a 44 45 46 41 55 4c ause> ] |.DEFAUL
2230: 54 20 3c 76 61 6c 75 65 3e 0a 7d 20 7b 63 6f 6e T <value>.} {con
2240: 73 74 72 61 69 6e 74 7d 20 7b 0a 50 52 49 4d 41 straint} {.PRIMA
2250: 52 59 20 4b 45 59 20 28 20 3c 6e 61 6d 65 3e 20 RY KEY ( <name>
2260: 5b 2c 20 3c 6e 61 6d 65 3e 5d 2a 20 29 20 5b 20 [, <name>]* ) [
2270: 3c 63 6f 6e 66 6c 69 63 74 2d 63 6c 61 75 73 65 <conflict-clause
2280: 3e 20 5d 7c 0a 55 4e 49 51 55 45 20 28 20 3c 6e > ]|.UNIQUE ( <n
2290: 61 6d 65 3e 20 5b 2c 20 3c 6e 61 6d 65 3e 5d 2a ame> [, <name>]*
22a0: 20 29 20 5b 20 3c 63 6f 6e 66 6c 69 63 74 2d 63 ) [ <conflict-c
22b0: 6c 61 75 73 65 3e 20 5d 20 7c 0a 43 48 45 43 4b lause> ] |.CHECK
22c0: 20 28 20 3c 65 78 70 72 3e 20 29 20 5b 20 3c 63 ( <expr> ) [ <c
22d0: 6f 6e 66 6c 69 63 74 2d 63 6c 61 75 73 65 3e 20 onflict-clause>
22e0: 5d 0a 7d 20 7b 63 6f 6e 66 6c 69 63 74 2d 63 6c ].} {conflict-cl
22f0: 61 75 73 65 7d 20 7b 0a 4f 4e 20 43 4f 4e 46 4c ause} {.ON CONFL
2300: 49 43 54 20 3c 63 6f 6e 66 6c 69 63 74 2d 61 6c ICT <conflict-al
2310: 67 6f 72 69 74 68 6d 3e 0a 7d 0a 0a 70 75 74 73 gorithm>.}..puts
2320: 20 7b 0a 3c 70 3e 41 20 43 52 45 41 54 45 20 54 {.<p>A CREATE T
2330: 41 42 4c 45 20 73 74 61 74 65 6d 65 6e 74 20 69 ABLE statement i
2340: 73 20 62 61 73 69 63 61 6c 6c 79 20 74 68 65 20 s basically the
2350: 6b 65 79 77 6f 72 64 73 20 22 43 52 45 41 54 45 keywords "CREATE
2360: 20 54 41 42 4c 45 22 0a 66 6f 6c 6c 6f 77 65 64 TABLE".followed
2370: 20 62 79 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 by the name of
2380: 61 20 6e 65 77 20 74 61 62 6c 65 20 61 6e 64 20 a new table and
2390: 61 20 70 61 72 65 6e 74 68 65 73 69 7a 65 64 20 a parenthesized
23a0: 6c 69 73 74 20 6f 66 20 63 6f 6c 75 6d 6e 0a 64 list of column.d
23b0: 65 66 69 6e 69 74 69 6f 6e 73 20 61 6e 64 20 63 efinitions and c
23c0: 6f 6e 73 74 72 61 69 6e 74 73 2e 20 20 54 68 65 onstraints. The
23d0: 20 74 61 62 6c 65 20 6e 61 6d 65 20 63 61 6e 20 table name can
23e0: 62 65 20 65 69 74 68 65 72 20 61 6e 20 69 64 65 be either an ide
23f0: 6e 74 69 66 69 65 72 0a 6f 72 20 61 20 73 74 72 ntifier.or a str
2400: 69 6e 67 2e 20 20 54 68 65 20 6f 6e 6c 79 20 72 ing. The only r
2410: 65 73 65 72 76 65 64 20 74 61 62 6c 65 20 6e 61 eserved table na
2420: 6d 65 20 69 73 20 22 3c 62 3e 73 71 6c 69 74 65 me is "<b>sqlite
2430: 5f 6d 61 73 74 65 72 3c 2f 62 3e 22 20 77 68 69 _master</b>" whi
2440: 63 68 0a 69 73 20 74 68 65 20 6e 61 6d 65 20 6f ch.is the name o
2450: 66 20 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 f the table that
2460: 20 72 65 63 6f 72 64 73 20 74 68 65 20 64 61 74 records the dat
2470: 61 62 61 73 65 20 73 63 68 65 6d 61 2e 3c 2f 70 abase schema.</p
2480: 3e 0a 0a 3c 70 3e 45 61 63 68 20 63 6f 6c 75 6d >..<p>Each colum
2490: 6e 20 64 65 66 69 6e 69 74 69 6f 6e 20 69 73 20 n definition is
24a0: 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 the name of the
24b0: 63 6f 6c 75 6d 6e 20 66 6f 6c 6c 6f 77 65 64 20 column followed
24c0: 62 79 20 74 68 65 0a 64 61 74 61 74 79 70 65 20 by the.datatype
24d0: 66 6f 72 20 74 68 61 74 20 63 6f 6c 75 6d 6e 2c for that column,
24e0: 20 74 68 65 6e 20 6f 6e 65 20 6f 72 20 6d 6f 72 then one or mor
24f0: 65 20 6f 70 74 69 6f 6e 61 6c 20 63 6f 6c 75 6d e optional colum
2500: 6e 20 63 6f 6e 73 74 72 61 69 6e 74 73 2e 0a 54 n constraints..T
2510: 68 65 20 64 61 74 61 74 79 70 65 20 66 6f 72 20 he datatype for
2520: 74 68 65 20 63 6f 6c 75 6d 6e 20 69 73 20 28 75 the column is (u
2530: 73 75 61 6c 6c 79 29 20 69 67 6e 6f 72 65 64 20 sually) ignored
2540: 61 6e 64 20 6d 61 79 20 62 65 20 6f 6d 69 74 74 and may be omitt
2550: 65 64 2e 0a 41 6c 6c 20 69 6e 66 6f 72 6d 61 74 ed..All informat
2560: 69 6f 6e 20 69 73 20 73 74 6f 72 65 64 20 61 73 ion is stored as
2570: 20 6e 75 6c 6c 2d 74 65 72 6d 69 6e 61 74 65 64 null-terminated
2580: 20 73 74 72 69 6e 67 73 2e 0a 54 68 65 20 55 4e strings..The UN
2590: 49 51 55 45 20 63 6f 6e 73 74 72 61 69 6e 74 20 IQUE constraint
25a0: 63 61 75 73 65 73 20 61 6e 20 69 6e 64 65 78 20 causes an index
25b0: 74 6f 20 62 65 20 63 72 65 61 74 65 64 20 6f 6e to be created on
25c0: 20 74 68 65 20 73 70 65 63 69 66 69 65 64 0a 63 the specified.c
25d0: 6f 6c 75 6d 6e 73 2e 20 20 54 68 69 73 20 69 6e olumns. This in
25e0: 64 65 78 20 6d 75 73 74 20 63 6f 6e 74 61 69 6e dex must contain
25f0: 20 75 6e 69 71 75 65 20 6b 65 79 73 2e 0a 54 68 unique keys..Th
2600: 65 20 44 45 46 41 55 4c 54 20 63 6f 6e 73 74 72 e DEFAULT constr
2610: 61 69 6e 74 0a 73 70 65 63 69 66 69 65 73 20 61 aint.specifies a
2620: 20 64 65 66 61 75 6c 74 20 76 61 6c 75 65 20 74 default value t
2630: 6f 20 75 73 65 20 77 68 65 6e 20 64 6f 69 6e 67 o use when doing
2640: 20 61 6e 20 49 4e 53 45 52 54 2e 0a 3c 2f 70 3e an INSERT..</p>
2650: 0a 0a 3c 70 3e 53 70 65 63 69 66 79 69 6e 67 20 ..<p>Specifying
2660: 61 20 50 52 49 4d 41 52 59 20 4b 45 59 20 6e 6f a PRIMARY KEY no
2670: 72 6d 61 6c 6c 79 20 6a 75 73 74 20 63 72 65 61 rmally just crea
2680: 74 65 73 20 61 20 55 4e 49 51 55 45 20 69 6e 64 tes a UNIQUE ind
2690: 65 78 0a 6f 6e 20 74 68 65 20 70 72 69 6d 61 72 ex.on the primar
26a0: 79 20 6b 65 79 2e 20 20 48 6f 77 65 76 65 72 2c y key. However,
26b0: 20 69 66 20 70 72 69 6d 61 72 79 20 6b 65 79 20 if primary key
26c0: 69 73 20 6f 6e 20 61 20 73 69 6e 67 6c 65 20 63 is on a single c
26d0: 6f 6c 75 6d 6e 0a 74 68 61 74 20 68 61 73 20 64 olumn.that has d
26e0: 61 74 61 74 79 70 65 20 49 4e 54 45 47 45 52 2c atatype INTEGER,
26f0: 20 74 68 65 6e 20 74 68 61 74 20 63 6f 6c 75 6d then that colum
2700: 6e 20 69 73 20 75 73 65 64 20 69 6e 74 65 72 6e n is used intern
2710: 61 6c 6c 79 0a 61 73 20 74 68 65 20 61 63 74 75 ally.as the actu
2720: 61 6c 20 6b 65 79 20 6f 66 20 74 68 65 20 42 2d al key of the B-
2730: 54 72 65 65 20 66 6f 72 20 74 68 65 20 74 61 62 Tree for the tab
2740: 6c 65 2e 20 20 54 68 69 73 20 6d 65 61 6e 73 20 le. This means
2750: 74 68 61 74 20 74 68 65 20 63 6f 6c 75 6d 6e 0a that the column.
2760: 6d 61 79 20 6f 6e 6c 79 20 68 6f 6c 64 20 75 6e may only hold un
2770: 69 71 75 65 20 69 6e 74 65 67 65 72 20 76 61 6c ique integer val
2780: 75 65 73 2e 20 20 28 45 78 63 65 70 74 20 66 6f ues. (Except fo
2790: 72 20 74 68 69 73 20 6f 6e 65 20 63 61 73 65 2c r this one case,
27a0: 0a 53 51 4c 69 74 65 20 69 67 6e 6f 72 65 73 20 .SQLite ignores
27b0: 74 68 65 20 64 61 74 61 74 79 70 65 20 73 70 65 the datatype spe
27c0: 63 69 66 69 63 61 74 69 6f 6e 20 6f 66 20 63 6f cification of co
27d0: 6c 75 6d 6e 73 20 61 6e 64 20 61 6c 6c 6f 77 73 lumns and allows
27e0: 0a 61 6e 79 20 6b 69 6e 64 20 6f 66 20 64 61 74 .any kind of dat
27f0: 61 20 74 6f 20 62 65 20 70 75 74 20 69 6e 20 61 a to be put in a
2800: 20 63 6f 6c 75 6d 6e 20 72 65 67 61 72 64 6c 65 column regardle
2810: 73 73 20 6f 66 20 69 74 73 20 64 65 63 6c 61 72 ss of its declar
2820: 65 64 0a 64 61 74 61 74 79 70 65 2e 29 20 20 49 ed.datatype.) I
2830: 66 20 61 20 74 61 62 6c 65 20 64 6f 65 73 20 6e f a table does n
2840: 6f 74 20 68 61 76 65 20 61 6e 20 49 4e 54 45 47 ot have an INTEG
2850: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 20 63 ER PRIMARY KEY c
2860: 6f 6c 75 6d 6e 2c 0a 74 68 65 6e 20 74 68 65 20 olumn,.then the
2870: 42 2d 54 72 65 65 20 6b 65 79 20 77 69 6c 6c 20 B-Tree key will
2880: 62 65 20 61 20 72 61 6e 64 6f 6d 6c 79 20 67 65 be a randomly ge
2890: 6e 65 72 61 74 65 64 20 69 6e 74 65 67 65 72 2e nerated integer.
28a0: 20 20 54 68 65 0a 42 2d 54 72 65 65 20 6b 65 79 The.B-Tree key
28b0: 20 66 6f 72 20 61 20 72 6f 77 20 63 61 6e 20 61 for a row can a
28c0: 6c 77 61 79 73 20 62 65 20 61 63 63 65 73 73 65 lways be accesse
28d0: 64 20 75 73 69 6e 67 20 6f 6e 65 20 6f 66 20 74 d using one of t
28e0: 68 65 0a 73 70 65 63 69 61 6c 20 6e 61 6d 65 73 he.special names
28f0: 20 22 3c 62 3e 52 4f 57 49 44 3c 2f 62 3e 22 2c "<b>ROWID</b>",
2900: 20 22 3c 62 3e 4f 49 44 3c 2f 62 3e 22 2c 20 6f "<b>OID</b>", o
2910: 72 20 22 3c 62 3e 5f 52 4f 57 49 44 5f 3c 2f 62 r "<b>_ROWID_</b
2920: 3e 22 2e 0a 54 68 69 73 20 69 73 20 74 72 75 65 >"..This is true
2930: 20 72 65 67 61 72 64 6c 65 73 73 20 6f 66 20 77 regardless of w
2940: 68 65 74 68 65 72 20 6f 72 20 6e 6f 74 20 74 68 hether or not th
2950: 65 72 65 20 69 73 20 61 6e 20 49 4e 54 45 47 45 ere is an INTEGE
2960: 52 0a 50 52 49 4d 41 52 59 20 4b 45 59 2e 3c 2f R.PRIMARY KEY.</
2970: 70 3e 0a 0a 3c 70 3e 49 66 20 74 68 65 20 22 54 p>..<p>If the "T
2980: 45 4d 50 22 20 6f 72 20 22 54 45 4d 50 4f 52 41 EMP" or "TEMPORA
2990: 52 59 22 20 6b 65 79 77 6f 72 64 20 6f 63 63 75 RY" keyword occu
29a0: 72 73 20 69 6e 20 62 65 74 77 65 65 6e 20 22 43 rs in between "C
29b0: 52 45 41 54 45 22 0a 61 6e 64 20 22 54 41 42 4c REATE".and "TABL
29c0: 45 22 20 74 68 65 6e 20 74 68 65 20 74 61 62 6c E" then the tabl
29d0: 65 20 74 68 61 74 20 69 73 20 63 72 65 61 74 65 e that is create
29e0: 64 20 69 73 20 6f 6e 6c 79 20 76 69 73 69 62 6c d is only visibl
29f0: 65 20 74 6f 20 74 68 65 0a 70 72 6f 63 65 73 73 e to the.process
2a00: 20 74 68 61 74 20 6f 70 65 6e 65 64 20 74 68 65 that opened the
2a10: 20 64 61 74 61 62 61 73 65 20 61 6e 64 20 69 73 database and is
2a20: 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 20 64 automatically d
2a30: 65 6c 65 74 65 64 20 77 68 65 6e 0a 74 68 65 20 eleted when.the
2a40: 64 61 74 61 62 61 73 65 20 69 73 20 63 6c 6f 73 database is clos
2a50: 65 64 2e 20 20 41 6e 79 20 69 6e 64 69 63 65 73 ed. Any indices
2a60: 20 63 72 65 61 74 65 64 20 6f 6e 20 61 20 74 65 created on a te
2a70: 6d 70 6f 72 61 72 79 20 74 61 62 6c 65 0a 61 72 mporary table.ar
2a80: 65 20 61 6c 73 6f 20 74 65 6d 70 6f 72 61 72 79 e also temporary
2a90: 2e 20 20 54 65 6d 70 6f 72 61 72 79 20 74 61 62 . Temporary tab
2aa0: 6c 65 73 20 61 6e 64 20 69 6e 64 69 63 65 73 20 les and indices
2ab0: 61 72 65 20 73 74 6f 72 65 64 20 69 6e 20 61 0a are stored in a.
2ac0: 73 65 70 61 72 61 74 65 20 66 69 6c 65 20 64 69 separate file di
2ad0: 73 74 69 6e 63 74 20 66 72 6f 6d 20 74 68 65 20 stinct from the
2ae0: 6d 61 69 6e 20 64 61 74 61 62 61 73 65 20 66 69 main database fi
2af0: 6c 65 2e 3c 2f 70 3e 0a 0a 3c 70 3e 54 68 65 20 le.</p>..<p>The
2b00: 6f 70 74 69 6f 6e 61 6c 20 63 6f 6e 66 6c 69 63 optional conflic
2b10: 74 2d 63 6c 61 75 73 65 20 66 6f 6c 6c 6f 77 69 t-clause followi
2b20: 6e 67 20 65 61 63 68 20 63 6f 6e 73 74 72 61 69 ng each constrai
2b30: 6e 74 0a 61 6c 6c 6f 77 73 20 74 68 65 20 73 70 nt.allows the sp
2b40: 65 63 69 66 69 63 61 74 69 6f 6e 20 6f 66 20 61 ecification of a
2b50: 6e 20 61 6c 74 65 72 6e 61 74 69 76 65 20 64 65 n alternative de
2b60: 66 61 75 6c 74 0a 63 6f 6e 73 74 72 61 69 6e 74 fault.constraint
2b70: 20 63 6f 6e 66 6c 69 63 74 20 72 65 73 6f 6c 75 conflict resolu
2b80: 74 69 6f 6e 20 61 6c 67 6f 72 69 74 68 6d 20 66 tion algorithm f
2b90: 6f 72 20 74 68 61 74 20 63 6f 6e 73 74 72 61 69 or that constrai
2ba0: 6e 74 2e 0a 54 68 65 20 64 65 66 61 75 6c 74 20 nt..The default
2bb0: 69 73 20 61 62 6f 72 74 20 41 42 4f 52 54 2e 20 is abort ABORT.
2bc0: 20 44 69 66 66 65 72 65 6e 74 20 63 6f 6e 73 74 Different const
2bd0: 72 61 69 6e 74 73 20 77 69 74 68 69 6e 20 74 68 raints within th
2be0: 65 20 73 61 6d 65 0a 74 61 62 6c 65 20 6d 61 79 e same.table may
2bf0: 20 68 61 76 65 20 64 69 66 66 65 72 65 6e 74 20 have different
2c00: 64 65 66 61 75 6c 74 20 63 6f 6e 66 6c 69 63 74 default conflict
2c10: 20 72 65 73 6f 6c 75 74 69 6f 6e 20 61 6c 67 6f resolution algo
2c20: 72 69 74 68 6d 73 2e 0a 49 66 20 61 6e 20 43 4f rithms..If an CO
2c30: 50 59 2c 20 49 4e 53 45 52 54 2c 20 6f 72 20 55 PY, INSERT, or U
2c40: 50 44 41 54 45 20 63 6f 6d 6d 61 6e 64 20 73 70 PDATE command sp
2c50: 65 63 69 66 69 65 73 20 61 20 64 69 66 66 65 72 ecifies a differ
2c60: 65 6e 74 20 63 6f 6e 66 6c 69 63 74 0a 72 65 73 ent conflict.res
2c70: 6f 6c 75 74 69 6f 6e 20 61 6c 67 6f 72 69 74 68 olution algorith
2c80: 6d 2c 20 74 68 65 6e 20 74 68 61 74 20 61 6c 67 m, then that alg
2c90: 6f 72 69 74 68 6d 20 69 73 20 75 73 65 64 20 69 orithm is used i
2ca0: 6e 20 70 6c 61 63 65 20 6f 66 20 74 68 65 0a 64 n place of the.d
2cb0: 65 66 61 75 6c 74 20 61 6c 67 6f 72 69 74 68 6d efault algorithm
2cc0: 20 73 70 65 63 69 66 69 65 64 20 69 6e 20 74 68 specified in th
2cd0: 65 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 73 e CREATE TABLE s
2ce0: 74 61 74 65 6d 65 6e 74 2e 0a 53 65 65 20 74 68 tatement..See th
2cf0: 65 20 73 65 63 74 69 6f 6e 20 74 69 74 6c 65 64 e section titled
2d00: 0a 3c 61 20 68 72 65 66 3d 22 23 63 6f 6e 66 6c .<a href="#confl
2d10: 69 63 74 22 3e 4f 4e 20 43 4f 4e 46 4c 49 43 54 ict">ON CONFLICT
2d20: 3c 2f 61 3e 20 66 6f 72 20 61 64 64 69 74 69 6f </a> for additio
2d30: 6e 61 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e nal information.
2d40: 3c 2f 70 3e 0a 0a 3c 70 3e 43 48 45 43 4b 20 63 </p>..<p>CHECK c
2d50: 6f 6e 73 74 72 61 69 6e 74 73 20 61 72 65 20 69 onstraints are i
2d60: 67 6e 6f 72 65 64 20 69 6e 20 74 68 65 20 63 75 gnored in the cu
2d70: 72 72 65 6e 74 20 69 6d 70 6c 65 6d 65 6e 74 61 rrent implementa
2d80: 74 69 6f 6e 2e 0a 53 75 70 70 6f 72 74 20 66 6f tion..Support fo
2d90: 72 20 43 48 45 43 4b 20 63 6f 6e 73 74 72 61 69 r CHECK constrai
2da0: 6e 74 73 20 6d 61 79 20 62 65 20 61 64 64 65 64 nts may be added
2db0: 20 69 6e 20 74 68 65 20 66 75 74 75 72 65 2e 20 in the future.
2dc0: 20 41 73 20 6f 66 0a 76 65 72 73 69 6f 6e 20 32 As of.version 2
2dd0: 2e 33 2e 30 2c 20 4e 4f 54 20 4e 55 4c 4c 2c 20 .3.0, NOT NULL,
2de0: 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 61 6e 64 PRIMARY KEY, and
2df0: 20 55 4e 49 51 55 45 20 63 6f 6e 73 74 72 61 69 UNIQUE constrai
2e00: 6e 74 73 20 61 6c 6c 0a 77 6f 72 6b 2e 3c 2f 70 nts all.work.</p
2e10: 3e 0a 0a 3c 70 3e 54 68 65 72 65 20 61 72 65 20 >..<p>There are
2e20: 6e 6f 20 61 72 62 69 74 72 61 72 79 20 6c 69 6d no arbitrary lim
2e30: 69 74 73 20 6f 6e 20 74 68 65 20 6e 75 6d 62 65 its on the numbe
2e40: 72 0a 6f 66 20 63 6f 6c 75 6d 6e 73 20 6f 72 20 r.of columns or
2e50: 6f 6e 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 on the number of
2e60: 20 63 6f 6e 73 74 72 61 69 6e 74 73 20 69 6e 20 constraints in
2e70: 61 20 74 61 62 6c 65 2e 0a 54 68 65 20 74 6f 74 a table..The tot
2e80: 61 6c 20 61 6d 6f 75 6e 74 20 6f 66 20 64 61 74 al amount of dat
2e90: 61 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 72 6f a in a single ro
2ea0: 77 20 69 73 20 6c 69 6d 69 74 65 64 20 74 6f 20 w is limited to
2eb0: 61 62 6f 75 74 0a 31 20 6d 65 67 61 62 79 74 65 about.1 megabyte
2ec0: 73 2e 20 20 28 54 68 69 73 20 6c 69 6d 69 74 20 s. (This limit
2ed0: 63 61 6e 20 62 65 20 69 6e 63 72 65 61 73 65 64 can be increased
2ee0: 20 74 6f 20 31 36 4d 42 20 62 79 20 63 68 61 6e to 16MB by chan
2ef0: 67 69 6e 67 0a 61 20 73 69 6e 67 6c 65 20 23 64 ging.a single #d
2f00: 65 66 69 6e 65 20 69 6e 20 74 68 65 20 73 6f 75 efine in the sou
2f10: 72 63 65 20 63 6f 64 65 20 61 6e 64 20 72 65 63 rce code and rec
2f20: 6f 6d 70 69 6c 69 6e 67 2e 29 3c 2f 70 3e 0a 0a ompiling.)</p>..
2f30: 3c 70 3e 54 68 65 20 43 52 45 41 54 45 20 54 41 <p>The CREATE TA
2f40: 42 4c 45 20 41 53 20 66 6f 72 6d 20 64 65 66 69 BLE AS form defi
2f50: 6e 65 73 20 74 68 65 20 74 61 62 6c 65 20 74 6f nes the table to
2f60: 20 62 65 0a 74 68 65 20 72 65 73 75 6c 74 20 73 be.the result s
2f70: 65 74 20 6f 66 20 61 20 71 75 65 72 79 2e 20 20 et of a query.
2f80: 54 68 65 20 6e 61 6d 65 73 20 6f 66 20 74 68 65 The names of the
2f90: 20 74 61 62 6c 65 20 63 6f 6c 75 6d 6e 73 20 61 table columns a
2fa0: 72 65 0a 74 68 65 20 6e 61 6d 65 73 20 6f 66 20 re.the names of
2fb0: 74 68 65 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 74 the columns in t
2fc0: 68 65 20 72 65 73 75 6c 74 2e 3c 2f 70 3e 0a 0a he result.</p>..
2fd0: 3c 70 3e 54 68 65 20 65 78 61 63 74 20 74 65 78 <p>The exact tex
2fe0: 74 0a 6f 66 20 65 61 63 68 20 43 52 45 41 54 45 t.of each CREATE
2ff0: 20 54 41 42 4c 45 20 73 74 61 74 65 6d 65 6e 74 TABLE statement
3000: 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 74 68 is stored in th
3010: 65 20 3c 62 3e 73 71 6c 69 74 65 5f 6d 61 73 74 e <b>sqlite_mast
3020: 65 72 3c 2f 62 3e 0a 74 61 62 6c 65 2e 20 20 45 er</b>.table. E
3030: 76 65 72 79 74 69 6d 65 20 74 68 65 20 64 61 74 verytime the dat
3040: 61 62 61 73 65 20 69 73 20 6f 70 65 6e 65 64 2c abase is opened,
3050: 20 61 6c 6c 20 43 52 45 41 54 45 20 54 41 42 4c all CREATE TABL
3060: 45 20 73 74 61 74 65 6d 65 6e 74 73 0a 61 72 65 E statements.are
3070: 20 72 65 61 64 20 66 72 6f 6d 20 74 68 65 20 3c read from the <
3080: 62 3e 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 3c b>sqlite_master<
3090: 2f 62 3e 20 74 61 62 6c 65 20 61 6e 64 20 75 73 /b> table and us
30a0: 65 64 20 74 6f 20 72 65 67 65 6e 65 72 61 74 65 ed to regenerate
30b0: 0a 53 51 4c 69 74 65 27 73 20 69 6e 74 65 72 6e .SQLite's intern
30c0: 61 6c 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f al representatio
30d0: 6e 20 6f 66 20 74 68 65 20 74 61 62 6c 65 20 6c n of the table l
30e0: 61 79 6f 75 74 2e 0a 49 66 20 74 68 65 20 6f 72 ayout..If the or
30f0: 69 67 69 6e 61 6c 20 63 6f 6d 6d 61 6e 64 20 77 iginal command w
3100: 61 73 20 61 20 43 52 45 41 54 45 20 54 41 42 4c as a CREATE TABL
3110: 45 20 41 53 20 74 68 65 6e 20 74 68 65 6e 20 61 E AS then then a
3120: 6e 20 65 71 75 69 76 61 6c 65 6e 74 0a 43 52 45 n equivalent.CRE
3130: 41 54 45 20 54 41 42 4c 45 20 73 74 61 74 65 6d ATE TABLE statem
3140: 65 6e 74 20 69 73 20 73 79 6e 74 68 65 73 69 7a ent is synthesiz
3150: 65 64 20 61 6e 64 20 73 74 6f 72 65 20 69 6e 20 ed and store in
3160: 3c 62 3e 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 <b>sqlite_master
3170: 3c 2f 62 3e 0a 69 6e 20 70 6c 61 63 65 20 6f 66 </b>.in place of
3180: 20 74 68 65 20 6f 72 69 67 69 6e 61 6c 20 63 6f the original co
3190: 6d 6d 61 6e 64 2e 0a 3c 2f 70 3e 0a 7d 0a 0a 53 mmand..</p>.}..S
31a0: 65 63 74 69 6f 6e 20 44 45 4c 45 54 45 20 64 65 ection DELETE de
31b0: 6c 65 74 65 0a 0a 53 79 6e 74 61 78 20 7b 73 71 lete..Syntax {sq
31c0: 6c 2d 73 74 61 74 65 6d 65 6e 74 7d 20 7b 0a 44 l-statement} {.D
31d0: 45 4c 45 54 45 20 46 52 4f 4d 20 3c 74 61 62 6c ELETE FROM <tabl
31e0: 65 2d 6e 61 6d 65 3e 20 5b 57 48 45 52 45 20 3c e-name> [WHERE <
31f0: 65 78 70 72 65 73 73 69 6f 6e 3e 5d 0a 7d 0a 0a expression>].}..
3200: 70 75 74 73 20 7b 0a 3c 70 3e 54 68 65 20 44 45 puts {.<p>The DE
3210: 4c 45 54 45 20 63 6f 6d 6d 61 6e 64 20 69 73 20 LETE command is
3220: 75 73 65 64 20 74 6f 20 72 65 6d 6f 76 65 20 72 used to remove r
3230: 65 63 6f 72 64 73 20 66 72 6f 6d 20 61 20 74 61 ecords from a ta
3240: 62 6c 65 2e 0a 54 68 65 20 63 6f 6d 6d 61 6e 64 ble..The command
3250: 20 63 6f 6e 73 69 73 74 73 20 6f 66 20 74 68 65 consists of the
3260: 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 22 20 6b "DELETE FROM" k
3270: 65 79 77 6f 72 64 73 20 66 6f 6c 6c 6f 77 65 64 eywords followed
3280: 20 62 79 0a 74 68 65 20 6e 61 6d 65 20 6f 66 20 by.the name of
3290: 74 68 65 20 74 61 62 6c 65 20 66 72 6f 6d 20 77 the table from w
32a0: 68 69 63 68 20 72 65 63 6f 72 64 73 20 61 72 65 hich records are
32b0: 20 74 6f 20 62 65 20 72 65 6d 6f 76 65 64 2e 0a to be removed..
32c0: 3c 2f 70 3e 0a 0a 3c 70 3e 57 69 74 68 6f 75 74 </p>..<p>Without
32d0: 20 61 20 57 48 45 52 45 20 63 6c 61 75 73 65 2c a WHERE clause,
32e0: 20 61 6c 6c 20 72 6f 77 73 20 6f 66 20 74 68 65 all rows of the
32f0: 20 74 61 62 6c 65 20 61 72 65 20 72 65 6d 6f 76 table are remov
3300: 65 64 2e 0a 49 66 20 61 20 57 48 45 52 45 20 63 ed..If a WHERE c
3310: 6c 61 75 73 65 20 69 73 20 73 75 70 70 6c 69 65 lause is supplie
3320: 64 2c 20 74 68 65 6e 20 6f 6e 6c 79 20 74 68 6f d, then only tho
3330: 73 65 20 72 6f 77 73 20 74 68 61 74 20 6d 61 74 se rows that mat
3340: 63 68 0a 74 68 65 20 65 78 70 72 65 73 73 69 6f ch.the expressio
3350: 6e 20 61 72 65 20 72 65 6d 6f 76 65 64 2e 3c 2f n are removed.</
3360: 70 3e 0a 7d 0a 0a 0a 53 65 63 74 69 6f 6e 20 7b p>.}...Section {
3370: 44 52 4f 50 20 49 4e 44 45 58 7d 20 64 72 6f 70 DROP INDEX} drop
3380: 69 6e 64 65 78 0a 0a 53 79 6e 74 61 78 20 7b 73 index..Syntax {s
3390: 71 6c 2d 63 6f 6d 6d 61 6e 64 7d 20 7b 0a 44 52 ql-command} {.DR
33a0: 4f 50 20 49 4e 44 45 58 20 3c 69 6e 64 65 78 2d OP INDEX <index-
33b0: 6e 61 6d 65 3e 0a 7d 0a 0a 70 75 74 73 20 7b 0a name>.}..puts {.
33c0: 3c 70 3e 54 68 65 20 44 52 4f 50 20 49 4e 44 45 <p>The DROP INDE
33d0: 58 20 73 74 61 74 65 6d 65 6e 74 20 63 6f 6e 73 X statement cons
33e0: 69 73 74 73 20 6f 66 20 74 68 65 20 6b 65 79 77 ists of the keyw
33f0: 6f 72 64 73 20 22 44 52 4f 50 20 49 4e 44 45 58 ords "DROP INDEX
3400: 22 20 66 6f 6c 6c 6f 77 65 64 0a 62 79 20 74 68 " followed.by th
3410: 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 69 6e e name of the in
3420: 64 65 78 2e 20 20 54 68 65 20 69 6e 64 65 78 20 dex. The index
3430: 6e 61 6d 65 64 20 69 73 20 63 6f 6d 70 6c 65 74 named is complet
3440: 65 6c 79 20 72 65 6d 6f 76 65 64 20 66 72 6f 6d ely removed from
3450: 0a 74 68 65 20 64 69 73 6b 2e 20 20 54 68 65 20 .the disk. The
3460: 6f 6e 6c 79 20 77 61 79 20 74 6f 20 72 65 63 6f only way to reco
3470: 76 65 72 20 74 68 65 20 69 6e 64 65 78 20 69 73 ver the index is
3480: 20 74 6f 20 72 65 65 6e 74 65 72 20 74 68 65 0a to reenter the.
3490: 61 70 70 72 6f 70 72 69 61 74 65 20 43 52 45 41 appropriate CREA
34a0: 54 45 20 49 4e 44 45 58 20 63 6f 6d 6d 61 6e 64 TE INDEX command
34b0: 2e 3c 2f 70 3e 0a 7d 0a 0a 53 65 63 74 69 6f 6e .</p>.}..Section
34c0: 20 7b 44 52 4f 50 20 54 41 42 4c 45 7d 20 64 72 {DROP TABLE} dr
34d0: 6f 70 74 61 62 6c 65 0a 0a 53 79 6e 74 61 78 20 optable..Syntax
34e0: 7b 73 71 6c 2d 63 6f 6d 6d 61 6e 64 7d 20 7b 0a {sql-command} {.
34f0: 44 52 4f 50 20 54 41 42 4c 45 20 3c 74 61 62 6c DROP TABLE <tabl
3500: 65 2d 6e 61 6d 65 3e 0a 7d 0a 0a 70 75 74 73 20 e-name>.}..puts
3510: 7b 0a 3c 70 3e 54 68 65 20 44 52 4f 50 20 54 41 {.<p>The DROP TA
3520: 42 4c 45 20 73 74 61 74 65 6d 65 6e 74 20 63 6f BLE statement co
3530: 6e 73 69 73 74 73 20 6f 66 20 74 68 65 20 6b 65 nsists of the ke
3540: 79 77 6f 72 64 73 20 22 44 52 4f 50 20 54 41 42 ywords "DROP TAB
3550: 4c 45 22 20 66 6f 6c 6c 6f 77 65 64 0a 62 79 20 LE" followed.by
3560: 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65 20 the name of the
3570: 74 61 62 6c 65 2e 20 20 54 68 65 20 74 61 62 6c table. The tabl
3580: 65 20 6e 61 6d 65 64 20 69 73 20 63 6f 6d 70 6c e named is compl
3590: 65 74 65 6c 79 20 72 65 6d 6f 76 65 64 20 66 72 etely removed fr
35a0: 6f 6d 0a 74 68 65 20 64 69 73 6b 2e 20 20 54 68 om.the disk. Th
35b0: 65 20 74 61 62 6c 65 20 63 61 6e 20 6e 6f 74 20 e table can not
35c0: 62 65 20 72 65 63 6f 76 65 72 65 64 2e 20 20 41 be recovered. A
35d0: 6c 6c 20 69 6e 64 69 63 65 73 20 61 73 73 6f 63 ll indices assoc
35e0: 69 61 74 65 64 20 77 69 74 68 0a 74 68 65 20 74 iated with.the t
35f0: 61 62 6c 65 20 61 72 65 20 61 6c 73 6f 20 64 65 able are also de
3600: 6c 65 74 65 64 2e 3c 2f 70 3e 7d 0a 0a 53 65 63 leted.</p>}..Sec
3610: 74 69 6f 6e 20 45 58 50 4c 41 49 4e 20 65 78 70 tion EXPLAIN exp
3620: 6c 61 69 6e 0a 0a 53 79 6e 74 61 78 20 7b 73 71 lain..Syntax {sq
3630: 6c 2d 73 74 61 74 65 6d 65 6e 74 7d 20 7b 0a 45 l-statement} {.E
3640: 58 50 4c 41 49 4e 20 3c 73 71 6c 2d 73 74 61 74 XPLAIN <sql-stat
3650: 65 6d 65 6e 74 3e 0a 7d 0a 0a 70 75 74 73 20 7b ement>.}..puts {
3660: 0a 3c 70 3e 54 68 65 20 45 58 50 4c 41 49 4e 20 .<p>The EXPLAIN
3670: 63 6f 6d 6d 61 6e 64 20 6d 6f 64 69 66 69 65 72 command modifier
3680: 20 69 73 20 61 20 6e 6f 6e 2d 73 74 61 6e 64 61 is a non-standa
3690: 72 64 20 65 78 74 65 6e 73 69 6f 6e 2e 20 20 54 rd extension. T
36a0: 68 65 0a 69 64 65 61 20 63 6f 6d 65 73 20 66 72 he.idea comes fr
36b0: 6f 6d 20 61 20 73 69 6d 69 6c 61 72 20 63 6f 6d om a similar com
36c0: 6d 61 6e 64 20 66 6f 75 6e 64 20 69 6e 20 50 6f mand found in Po
36d0: 73 74 67 72 65 53 51 4c 2c 20 62 75 74 20 74 68 stgreSQL, but th
36e0: 65 20 6f 70 65 72 61 74 69 6f 6e 0a 69 73 20 63 e operation.is c
36f0: 6f 6d 70 6c 65 74 65 6c 79 20 64 69 66 66 65 72 ompletely differ
3700: 65 6e 74 2e 3c 2f 70 3e 0a 0a 3c 70 3e 49 66 20 ent.</p>..<p>If
3710: 74 68 65 20 45 58 50 4c 41 49 4e 20 6b 65 79 77 the EXPLAIN keyw
3720: 6f 72 64 20 61 70 70 65 61 72 73 20 62 65 66 6f ord appears befo
3730: 72 65 20 61 6e 79 20 6f 74 68 65 72 20 53 51 4c re any other SQL
3740: 69 74 65 20 53 51 4c 20 63 6f 6d 6d 61 6e 64 0a ite SQL command.
3750: 74 68 65 6e 20 69 6e 73 74 65 61 64 20 6f 66 20 then instead of
3760: 61 63 74 75 61 6c 6c 79 20 65 78 65 63 75 74 69 actually executi
3770: 6e 67 20 74 68 65 20 63 6f 6d 6d 61 6e 64 2c 20 ng the command,
3780: 74 68 65 20 53 51 4c 69 74 65 20 6c 69 62 72 61 the SQLite libra
3790: 72 79 20 77 69 6c 6c 0a 72 65 70 6f 72 74 20 62 ry will.report b
37a0: 61 63 6b 20 74 68 65 20 73 65 71 75 65 6e 63 65 ack the sequence
37b0: 20 6f 66 20 76 69 72 74 75 61 6c 20 6d 61 63 68 of virtual mach
37c0: 69 6e 65 20 69 6e 73 74 72 75 63 74 69 6f 6e 73 ine instructions
37d0: 20 69 74 20 77 6f 75 6c 64 20 68 61 76 65 0a 75 it would have.u
37e0: 73 65 64 20 74 6f 20 65 78 65 63 75 74 65 20 74 sed to execute t
37f0: 68 65 20 63 6f 6d 6d 61 6e 64 20 68 61 64 20 74 he command had t
3800: 68 65 20 45 58 50 4c 41 49 4e 20 6b 65 79 77 6f he EXPLAIN keywo
3810: 72 64 20 6e 6f 74 20 62 65 65 6e 20 70 72 65 73 rd not been pres
3820: 65 6e 74 2e 0a 46 6f 72 20 61 64 64 69 74 69 6f ent..For additio
3830: 6e 61 6c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 nal information
3840: 61 62 6f 75 74 20 76 69 72 74 75 61 6c 20 6d 61 about virtual ma
3850: 63 68 69 6e 65 20 69 6e 73 74 72 75 63 74 69 6f chine instructio
3860: 6e 73 20 73 65 65 0a 74 68 65 20 3c 61 20 68 72 ns see.the <a hr
3870: 65 66 3d 22 61 72 63 68 2e 68 74 6d 6c 22 3e 61 ef="arch.html">a
3880: 72 63 68 69 74 65 63 74 75 72 65 20 64 65 73 63 rchitecture desc
3890: 72 69 70 74 69 6f 6e 3c 2f 61 3e 20 6f 72 20 74 ription</a> or t
38a0: 68 65 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e he documentation
38b0: 0a 6f 6e 20 3c 61 20 68 72 65 66 3d 22 6f 70 63 .on <a href="opc
38c0: 6f 64 65 2e 68 74 6d 6c 22 3e 61 76 61 69 6c 61 ode.html">availa
38d0: 62 6c 65 20 6f 70 63 6f 64 65 73 3c 2f 61 3e 20 ble opcodes</a>
38e0: 66 6f 72 20 74 68 65 20 76 69 72 74 75 61 6c 20 for the virtual
38f0: 6d 61 63 68 69 6e 65 2e 3c 2f 70 3e 0a 7d 0a 0a machine.</p>.}..
3900: 53 65 63 74 69 6f 6e 20 65 78 70 72 65 73 73 69 Section expressi
3910: 6f 6e 20 65 78 70 72 0a 0a 53 79 6e 74 61 78 20 on expr..Syntax
3920: 7b 65 78 70 72 65 73 73 69 6f 6e 7d 20 7b 0a 3c {expression} {.<
3930: 65 78 70 72 65 73 73 69 6f 6e 3e 20 3c 62 69 6e expression> <bin
3940: 61 72 79 2d 6f 70 3e 20 3c 65 78 70 72 65 73 73 ary-op> <express
3950: 69 6f 6e 3e 20 7c 0a 3c 65 78 70 72 65 73 73 69 ion> |.<expressi
3960: 6f 6e 3e 20 3c 6c 69 6b 65 2d 6f 70 3e 20 3c 65 on> <like-op> <e
3970: 78 70 72 65 73 73 69 6f 6e 3e 20 7c 0a 3c 75 6e xpression> |.<un
3980: 61 72 79 2d 6f 70 3e 20 3c 65 78 70 72 65 73 73 ary-op> <express
3990: 69 6f 6e 3e 20 7c 0a 28 20 3c 65 78 70 72 65 73 ion> |.( <expres
39a0: 73 69 6f 6e 3e 20 29 20 7c 0a 3c 63 6f 6c 75 6d sion> ) |.<colum
39b0: 6e 2d 6e 61 6d 65 3e 20 7c 0a 3c 74 61 62 6c 65 n-name> |.<table
39c0: 2d 6e 61 6d 65 3e 20 2e 20 3c 63 6f 6c 75 6d 6e -name> . <column
39d0: 2d 6e 61 6d 65 3e 20 7c 0a 3c 6c 69 74 65 72 61 -name> |.<litera
39e0: 6c 2d 76 61 6c 75 65 3e 20 7c 0a 3c 66 75 6e 63 l-value> |.<func
39f0: 74 69 6f 6e 2d 6e 61 6d 65 3e 20 28 20 3c 65 78 tion-name> ( <ex
3a00: 70 72 2d 6c 69 73 74 3e 20 7c 20 53 54 41 52 20 pr-list> | STAR
3a10: 29 20 7c 0a 3c 65 78 70 72 65 73 73 69 6f 6e 3e ) |.<expression>
3a20: 20 49 53 4e 55 4c 4c 20 7c 0a 3c 65 78 70 72 65 ISNULL |.<expre
3a30: 73 73 69 6f 6e 3e 20 4e 4f 54 4e 55 4c 4c 20 7c ssion> NOTNULL |
3a40: 0a 3c 65 78 70 72 65 73 73 69 6f 6e 3e 20 5b 4e .<expression> [N
3a50: 4f 54 5d 20 42 45 54 57 45 45 4e 20 3c 65 78 70 OT] BETWEEN <exp
3a60: 72 65 73 73 69 6f 6e 3e 20 41 4e 44 20 3c 65 78 ression> AND <ex
3a70: 70 72 65 73 73 69 6f 6e 3e 20 7c 0a 3c 65 78 70 pression> |.<exp
3a80: 72 65 73 73 69 6f 6e 3e 20 5b 4e 4f 54 5d 20 49 ression> [NOT] I
3a90: 4e 20 28 20 3c 76 61 6c 75 65 2d 6c 69 73 74 3e N ( <value-list>
3aa0: 20 29 20 7c 0a 3c 65 78 70 72 65 73 73 69 6f 6e ) |.<expression
3ab0: 3e 20 5b 4e 4f 54 5d 20 49 4e 20 28 20 3c 73 65 > [NOT] IN ( <se
3ac0: 6c 65 63 74 3e 20 29 20 7c 0a 28 20 3c 73 65 6c lect> ) |.( <sel
3ad0: 65 63 74 3e 20 29 0a 7d 20 7b 6c 69 6b 65 2d 6f ect> ).} {like-o
3ae0: 70 7d 20 7b 0a 4c 49 4b 45 20 7c 20 47 4c 4f 42 p} {.LIKE | GLOB
3af0: 20 7c 20 4e 4f 54 20 4c 49 4b 45 20 7c 20 4e 4f | NOT LIKE | NO
3b00: 54 20 47 4c 4f 42 0a 7d 0a 0a 70 75 74 73 20 7b T GLOB.}..puts {
3b10: 0a 3c 70 3e 54 68 69 73 20 73 65 63 74 69 6f 6e .<p>This section
3b20: 20 69 73 20 64 69 66 66 65 72 65 6e 74 20 66 72 is different fr
3b30: 6f 6d 20 74 68 65 20 6f 74 68 65 72 73 2e 20 20 om the others.
3b40: 4d 6f 73 74 20 6f 74 68 65 72 20 73 65 63 74 69 Most other secti
3b50: 6f 6e 73 20 6f 66 0a 74 68 69 73 20 64 6f 63 75 ons of.this docu
3b60: 6d 65 6e 74 20 74 61 6c 6b 73 20 61 62 6f 75 74 ment talks about
3b70: 20 61 20 70 61 72 74 69 63 75 6c 61 72 20 53 51 a particular SQ
3b80: 4c 20 63 6f 6d 6d 61 6e 64 2e 20 20 54 68 69 73 L command. This
3b90: 20 73 65 63 74 69 6f 6e 20 64 6f 65 73 0a 6e 6f section does.no
3ba0: 74 20 74 61 6c 6b 20 61 62 6f 75 74 20 61 20 73 t talk about a s
3bb0: 74 61 6e 64 61 6c 6f 6e 65 20 63 6f 6d 6d 61 6e tandalone comman
3bc0: 64 20 62 75 74 20 61 62 6f 75 74 20 22 65 78 70 d but about "exp
3bd0: 72 65 73 73 69 6f 6e 73 22 20 77 68 69 63 68 20 ressions" which
3be0: 61 72 65 20 0a 73 75 62 63 6f 6d 70 6f 6e 65 6e are .subcomponen
3bf0: 74 20 6f 66 20 6d 6f 73 74 20 6f 74 68 65 72 20 t of most other
3c00: 63 6f 6d 6d 61 6e 64 73 2e 3c 2f 70 3e 0a 0a 3c commands.</p>..<
3c10: 70 3e 53 51 4c 69 74 65 20 75 6e 64 65 72 73 74 p>SQLite underst
3c20: 61 6e 64 73 20 74 68 65 20 66 6f 6c 6c 6f 77 69 ands the followi
3c30: 6e 67 20 62 69 6e 61 72 79 20 6f 70 65 72 61 74 ng binary operat
3c40: 6f 72 73 2c 20 69 6e 20 6f 72 64 65 72 20 66 72 ors, in order fr
3c50: 6f 6d 0a 68 69 67 68 65 73 74 20 74 6f 20 6c 6f om.highest to lo
3c60: 77 65 73 74 20 70 72 65 63 65 64 65 6e 63 65 3a west precedence:
3c70: 3c 2f 70 3e 0a 0a 3c 62 6c 6f 63 6b 71 75 6f 74 </p>..<blockquot
3c80: 65 3e 3c 70 72 65 3e 0a 3c 66 6f 6e 74 20 63 6f e><pre>.<font co
3c90: 6c 6f 72 3d 22 23 32 63 32 63 66 30 22 3e 3c 62 lor="#2c2cf0"><b
3ca0: 69 67 3e 2a 20 20 20 20 2f 20 20 20 20 25 0a 2b ig>* / %.+
3cb0: 20 20 20 20 2d 0a 26 6c 74 3b 26 6c 74 3b 20 20 -.<<
3cc0: 20 26 67 74 3b 26 67 74 3b 20 20 20 26 61 6d 70 >> &
3cd0: 3b 20 20 20 20 7c 0a 26 6c 74 3b 20 20 20 20 26 ; |.< &
3ce0: 6c 74 3b 3d 20 20 20 26 67 74 3b 20 20 20 20 26 lt;= > &
3cf0: 67 74 3b 3d 0a 3d 20 20 20 20 3d 3d 20 20 20 21 gt;=.= == !
3d00: 3d 20 20 20 26 6c 74 3b 26 67 74 3b 20 20 20 3c = <> <
3d10: 2f 62 69 67 3e 49 4e 0a 41 4e 44 0a 4f 52 3c 2f /big>IN.AND.OR</
3d20: 66 6f 6e 74 3e 0a 3c 2f 70 72 65 3e 3c 2f 62 6c font>.</pre></bl
3d30: 6f 63 6b 71 75 6f 74 65 3e 0a 0a 3c 70 3e 53 75 ockquote>..<p>Su
3d40: 70 70 6f 72 74 65 64 20 75 6e 61 72 79 20 6f 70 pported unary op
3d50: 65 72 61 74 65 72 73 20 61 72 65 20 74 68 65 73 eraters are thes
3d60: 65 3a 3c 2f 70 3e 0a 0a 3c 62 6c 6f 63 6b 71 75 e:</p>..<blockqu
3d70: 6f 74 65 3e 3c 70 72 65 3e 0a 3c 66 6f 6e 74 20 ote><pre>.<font
3d80: 63 6f 6c 6f 72 3d 22 23 32 63 32 63 66 30 22 3e color="#2c2cf0">
3d90: 3c 62 69 67 3e 2d 20 20 20 20 2b 20 20 20 20 21 <big>- + !
3da0: 20 20 20 20 7e 3c 2f 62 69 67 3e 3c 2f 66 6f 6e ~</big></fon
3db0: 74 3e 0a 3c 2f 70 72 65 3e 3c 2f 62 6c 6f 63 6b t>.</pre></block
3dc0: 71 75 6f 74 65 3e 0a 0a 3c 70 3e 41 6e 79 20 53 quote>..<p>Any S
3dd0: 51 4c 69 74 65 20 76 61 6c 75 65 20 63 61 6e 20 QLite value can
3de0: 62 65 20 75 73 65 64 20 61 73 20 70 61 72 74 20 be used as part
3df0: 6f 66 20 61 6e 20 65 78 70 72 65 73 73 69 6f 6e of an expression
3e00: 2e 20 20 0a 46 6f 72 20 61 72 69 74 68 6d 65 74 . .For arithmet
3e10: 69 63 20 6f 70 65 72 61 74 69 6f 6e 73 2c 20 69 ic operations, i
3e20: 6e 74 65 67 65 72 73 20 61 72 65 20 74 72 65 61 ntegers are trea
3e30: 74 65 64 20 61 73 20 69 6e 74 65 67 65 72 73 2e ted as integers.
3e40: 0a 53 74 72 69 6e 67 73 20 61 72 65 20 66 69 72 .Strings are fir
3e50: 73 74 20 63 6f 6e 76 65 72 74 65 64 20 74 6f 20 st converted to
3e60: 72 65 61 6c 20 6e 75 6d 62 65 72 73 20 75 73 69 real numbers usi
3e70: 6e 67 20 3c 62 3e 61 74 6f 66 28 29 3c 2f 62 3e ng <b>atof()</b>
3e80: 2e 0a 46 6f 72 20 63 6f 6d 70 61 72 69 73 6f 6e ..For comparison
3e90: 20 6f 70 65 72 61 74 6f 72 73 2c 20 6e 75 6d 62 operators, numb
3ea0: 65 72 73 20 63 6f 6d 70 61 72 65 20 61 73 20 6e ers compare as n
3eb0: 75 6d 62 65 72 73 20 61 6e 64 20 73 74 72 69 6e umbers and strin
3ec0: 67 73 0a 63 6f 6d 70 61 72 65 20 61 73 20 73 74 gs.compare as st
3ed0: 72 69 6e 67 73 2e 20 20 46 6f 72 20 73 74 72 69 rings. For stri
3ee0: 6e 67 20 63 6f 6d 70 61 72 69 73 6f 6e 73 2c 20 ng comparisons,
3ef0: 63 61 73 65 20 69 73 20 73 69 67 6e 69 66 69 63 case is signific
3f00: 61 6e 74 0a 62 75 74 20 69 73 20 6f 6e 6c 79 20 ant.but is only
3f10: 75 73 65 64 20 74 6f 20 62 72 65 61 6b 20 61 20 used to break a
3f20: 74 69 65 2e 0a 4e 6f 74 65 20 74 68 61 74 20 74 tie..Note that t
3f30: 68 65 72 65 20 61 72 65 20 74 77 6f 20 76 61 72 here are two var
3f40: 69 61 74 69 6f 6e 73 20 6f 66 20 74 68 65 20 65 iations of the e
3f50: 71 75 61 6c 73 20 61 6e 64 20 6e 6f 74 20 65 71 quals and not eq
3f60: 75 61 6c 73 0a 6f 70 65 72 61 74 6f 72 73 2e 20 uals.operators.
3f70: 20 45 71 75 61 6c 73 20 63 61 6e 20 62 65 20 65 Equals can be e
3f80: 69 74 68 65 72 7d 0a 70 75 74 73 20 22 5b 4f 70 ither}.puts "[Op
3f90: 65 72 61 74 6f 72 20 3d 5d 20 6f 72 20 5b 4f 70 erator =] or [Op
3fa0: 65 72 61 74 6f 72 20 3d 3d 5d 2e 0a 54 68 65 20 erator ==]..The
3fb0: 6e 6f 6e 2d 65 71 75 61 6c 73 20 6f 70 65 72 61 non-equals opera
3fc0: 74 6f 72 20 63 61 6e 20 62 65 20 65 69 74 68 65 tor can be eithe
3fd0: 72 0a 5b 4f 70 65 72 61 74 6f 72 20 21 3d 5d 20 r.[Operator !=]
3fe0: 6f 72 20 5b 4f 70 65 72 61 74 6f 72 20 7b 26 6c or [Operator {&l
3ff0: 74 3b 26 67 74 3b 7d 5d 2e 3c 2f 70 3e 22 0a 70 t;>}].</p>".p
4000: 75 74 73 20 7b 0a 0a 3c 70 3e 54 68 65 20 4c 49 uts {..<p>The LI
4010: 4b 45 20 6f 70 65 72 61 74 6f 72 20 64 6f 65 73 KE operator does
4020: 20 61 20 77 69 6c 64 63 61 72 64 20 63 6f 6d 70 a wildcard comp
4030: 61 72 69 73 69 6f 6e 2e 20 20 54 68 65 20 6f 70 arision. The op
4040: 65 72 61 6e 64 0a 74 6f 20 74 68 65 20 72 69 67 erand.to the rig
4050: 68 74 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 ht contains the
4060: 77 69 6c 64 63 61 72 64 73 2e 7d 0a 70 75 74 73 wildcards.}.puts
4070: 20 22 41 20 70 65 72 63 65 6e 74 20 73 79 6d 62 "A percent symb
4080: 6f 6c 20 5b 4f 70 65 72 61 74 6f 72 20 25 5d 20 ol [Operator %]
4090: 69 6e 20 74 68 65 20 72 69 67 68 74 20 6f 70 65 in the right ope
40a0: 72 61 6e 64 0a 6d 61 74 63 68 65 73 20 61 6e 79 rand.matches any
40b0: 20 73 65 71 75 65 6e 63 65 20 6f 66 20 7a 65 72 sequence of zer
40c0: 6f 20 6f 72 20 6d 6f 72 65 20 63 68 61 72 61 63 o or more charac
40d0: 74 65 72 73 20 6f 6e 20 74 68 65 20 6c 65 66 74 ters on the left
40e0: 2e 0a 41 6e 20 75 6e 64 65 72 73 63 6f 72 65 20 ..An underscore
40f0: 5b 4f 70 65 72 61 74 6f 72 20 5f 5d 20 6f 6e 20 [Operator _] on
4100: 74 68 65 20 72 69 67 68 74 0a 6d 61 74 63 68 65 the right.matche
4110: 73 20 61 6e 79 20 73 69 6e 67 6c 65 20 63 68 61 s any single cha
4120: 72 61 63 74 65 72 20 6f 6e 20 74 68 65 20 6c 65 racter on the le
4130: 66 74 2e 22 0a 70 75 74 73 20 7b 54 68 65 20 4c ft.".puts {The L
4140: 49 4b 45 20 6f 70 65 72 61 74 6f 72 20 69 73 0a IKE operator is.
4150: 6e 6f 74 20 63 61 73 65 20 73 65 6e 73 69 74 69 not case sensiti
4160: 76 65 20 61 6e 64 20 77 69 6c 6c 20 6d 61 74 63 ve and will matc
4170: 68 20 75 70 70 65 72 20 63 61 73 65 20 63 68 61 h upper case cha
4180: 72 61 63 74 65 72 73 20 6f 6e 20 6f 6e 65 0a 73 racters on one.s
4190: 69 64 65 20 61 67 61 69 6e 73 74 20 6c 6f 77 65 ide against lowe
41a0: 72 20 63 61 73 65 20 63 68 61 72 61 63 74 65 72 r case character
41b0: 73 20 6f 6e 20 74 68 65 20 6f 74 68 65 72 2e 0a s on the other..
41c0: 28 41 20 62 75 67 3a 20 53 51 4c 69 74 65 20 6f (A bug: SQLite o
41d0: 6e 6c 79 20 75 6e 64 65 72 73 74 61 6e 64 73 20 nly understands
41e0: 75 70 70 65 72 2f 6c 6f 77 65 72 20 63 61 73 65 upper/lower case
41f0: 20 66 6f 72 20 37 2d 62 69 74 20 4c 61 74 69 6e for 7-bit Latin
4200: 0a 63 68 61 72 61 63 74 65 72 73 2e 20 20 48 65 .characters. He
4210: 6e 63 65 20 74 68 65 20 4c 49 4b 45 20 6f 70 65 nce the LIKE ope
4220: 72 61 74 6f 72 20 69 73 20 63 61 73 65 20 73 65 rator is case se
4230: 6e 73 69 74 69 76 65 20 66 6f 72 0a 38 2d 62 69 nsitive for.8-bi
4240: 74 20 69 73 6f 38 38 35 39 20 63 68 61 72 61 63 t iso8859 charac
4250: 74 65 72 73 20 6f 72 20 55 54 46 2d 38 20 63 68 ters or UTF-8 ch
4260: 61 72 61 63 74 65 72 73 2e 20 20 46 6f 72 20 65 aracters. For e
4270: 78 61 6d 70 6c 65 2c 0a 74 68 65 20 65 78 70 72 xample,.the expr
4280: 65 73 73 69 6f 6e 20 3c 62 3e 27 61 27 26 6e 62 ession <b>'a'&nb
4290: 73 70 3b 4c 49 4b 45 26 6e 62 73 70 3b 27 41 27 sp;LIKE 'A'
42a0: 3c 2f 62 3e 20 69 73 20 54 52 55 45 20 62 75 74 </b> is TRUE but
42b0: 0a 3c 62 3e 27 26 61 65 6c 69 67 3b 27 26 6e 62 .<b>'æ'&nb
42c0: 73 70 3b 4c 49 4b 45 26 6e 62 73 70 3b 27 26 41 sp;LIKE '&A
42d0: 45 6c 69 67 3b 27 3c 2f 62 3e 20 69 73 20 46 41 Elig;'</b> is FA
42e0: 4c 53 45 2e 29 0a 3c 2f 70 3e 0a 0a 3c 70 3e 54 LSE.).</p>..<p>T
42f0: 68 65 20 47 4c 4f 42 20 6f 70 65 72 61 74 6f 72 he GLOB operator
4300: 20 69 73 20 73 69 6d 69 6c 61 72 20 74 6f 20 4c is similar to L
4310: 49 4b 45 20 62 75 74 20 75 73 65 73 20 74 68 65 IKE but uses the
4320: 20 55 6e 69 78 0a 66 69 6c 65 20 67 6c 6f 62 62 Unix.file globb
4330: 69 6e 67 20 73 79 6e 74 61 78 20 66 6f 72 20 69 ing syntax for i
4340: 74 73 20 77 69 6c 64 63 61 72 64 73 2e 20 20 41 ts wildcards. A
4350: 6c 73 6f 2c 20 47 4c 4f 42 20 69 73 20 63 61 73 lso, GLOB is cas
4360: 65 0a 73 65 6e 73 69 74 69 76 65 2c 20 75 6e 6c e.sensitive, unl
4370: 69 6b 65 20 4c 49 4b 45 2e 20 20 42 6f 74 68 20 ike LIKE. Both
4380: 47 4c 4f 42 20 61 6e 64 20 4c 49 4b 45 20 6d 61 GLOB and LIKE ma
4390: 79 20 62 65 20 70 72 65 63 65 64 65 64 20 62 79 y be preceded by
43a0: 0a 74 68 65 20 4e 4f 54 20 6b 65 79 77 6f 72 64 .the NOT keyword
43b0: 20 74 6f 20 69 6e 76 65 72 74 20 74 68 65 20 73 to invert the s
43c0: 65 6e 73 65 20 6f 66 20 74 68 65 20 74 65 73 74 ense of the test
43d0: 2e 3c 2f 70 3e 0a 0a 3c 70 3e 41 20 63 6f 6c 75 .</p>..<p>A colu
43e0: 6d 6e 20 6e 61 6d 65 20 63 61 6e 20 62 65 20 61 mn name can be a
43f0: 6e 79 20 6f 66 20 74 68 65 20 6e 61 6d 65 73 20 ny of the names
4400: 64 65 66 69 6e 65 64 20 69 6e 20 74 68 65 20 43 defined in the C
4410: 52 45 41 54 45 20 54 41 42 4c 45 0a 73 74 61 74 REATE TABLE.stat
4420: 65 6d 65 6e 74 20 6f 72 20 6f 6e 65 20 6f 66 20 ement or one of
4430: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 73 70 the following sp
4440: 65 63 69 61 6c 20 69 64 65 6e 74 69 66 69 65 72 ecial identifier
4450: 73 3a 20 22 3c 62 3e 52 4f 57 49 44 3c 2f 62 3e s: "<b>ROWID</b>
4460: 22 2c 0a 22 3c 62 3e 4f 49 44 3c 2f 62 3e 22 2c ",."<b>OID</b>",
4470: 20 6f 72 20 22 3c 62 3e 5f 52 4f 57 49 44 5f 3c or "<b>_ROWID_<
4480: 2f 62 3e 22 2e 0a 54 68 65 73 65 20 73 70 65 63 /b>"..These spec
4490: 69 61 6c 20 69 64 65 6e 74 69 66 69 65 72 73 20 ial identifiers
44a0: 61 6c 6c 20 64 65 73 63 72 69 62 65 20 74 68 65 all describe the
44b0: 0a 75 6e 69 71 75 65 20 72 61 6e 64 6f 6d 20 69 .unique random i
44c0: 6e 74 65 67 65 72 20 6b 65 79 20 28 74 68 65 20 nteger key (the
44d0: 22 72 6f 77 20 6b 65 79 22 29 20 61 73 73 6f 63 "row key") assoc
44e0: 69 61 74 65 64 20 77 69 74 68 20 65 76 65 72 79 iated with every
44f0: 20 0a 72 6f 77 20 6f 66 20 65 76 65 72 79 20 74 .row of every t
4500: 61 62 6c 65 2e 0a 54 68 65 20 73 70 65 63 69 61 able..The specia
4510: 6c 20 69 64 65 6e 74 69 66 69 65 72 73 20 6f 6e l identifiers on
4520: 6c 79 20 72 65 66 65 72 20 74 6f 20 74 68 65 20 ly refer to the
4530: 72 6f 77 20 6b 65 79 20 69 66 20 74 68 65 20 43 row key if the C
4540: 52 45 41 54 45 20 54 41 42 4c 45 0a 73 74 61 74 REATE TABLE.stat
4550: 65 6d 65 6e 74 20 64 6f 65 73 20 6e 6f 74 20 64 ement does not d
4560: 65 66 69 6e 65 20 61 20 72 65 61 6c 20 63 6f 6c efine a real col
4570: 75 6d 6e 20 77 69 74 68 20 74 68 65 20 73 61 6d umn with the sam
4580: 65 20 6e 61 6d 65 2e 20 20 52 6f 77 20 6b 65 79 e name. Row key
4590: 73 0a 61 63 74 20 6c 69 6b 65 20 72 65 61 64 2d s.act like read-
45a0: 6f 6e 6c 79 20 63 6f 6c 75 6d 6e 73 2e 20 20 41 only columns. A
45b0: 20 72 6f 77 20 6b 65 79 20 63 61 6e 20 62 65 20 row key can be
45c0: 75 73 65 64 20 61 6e 79 77 68 65 72 65 20 61 20 used anywhere a
45d0: 72 65 67 75 6c 61 72 0a 63 6f 6c 75 6d 6e 20 63 regular.column c
45e0: 61 6e 20 62 65 20 75 73 65 64 2c 20 65 78 63 65 an be used, exce
45f0: 70 74 20 74 68 61 74 20 79 6f 75 20 63 61 6e 6e pt that you cann
4600: 6f 74 20 63 68 61 6e 67 65 20 74 68 65 20 76 61 ot change the va
4610: 6c 75 65 0a 6f 66 20 61 20 72 6f 77 20 6b 65 79 lue.of a row key
4620: 20 69 6e 20 61 6e 20 55 50 44 41 54 45 20 6f 72 in an UPDATE or
4630: 20 49 4e 53 45 52 54 20 73 74 61 74 65 6d 65 6e INSERT statemen
4640: 74 2e 0a 22 53 45 4c 45 43 54 20 2a 20 2e 2e 2e t.."SELECT * ...
4650: 22 20 64 6f 65 73 20 6e 6f 74 20 72 65 74 75 72 " does not retur
4660: 6e 20 74 68 65 20 72 6f 77 20 6b 65 79 2e 3c 2f n the row key.</
4670: 70 3e 0a 0a 3c 70 3e 53 45 4c 45 43 54 20 73 74 p>..<p>SELECT st
4680: 61 74 65 6d 65 6e 74 73 20 63 61 6e 20 61 70 70 atements can app
4690: 65 61 72 20 69 6e 20 65 78 70 72 65 73 73 69 6f ear in expressio
46a0: 6e 73 20 61 73 20 65 69 74 68 65 72 20 74 68 65 ns as either the
46b0: 0a 72 69 67 68 74 2d 68 61 6e 64 20 6f 70 65 72 .right-hand oper
46c0: 61 6e 64 20 6f 66 20 74 68 65 20 49 4e 20 6f 70 and of the IN op
46d0: 65 72 61 74 6f 72 20 6f 72 20 61 73 20 61 20 73 erator or as a s
46e0: 63 61 6c 61 72 20 71 75 61 6e 74 69 74 79 2e 0a calar quantity..
46f0: 49 6e 20 62 6f 74 68 20 63 61 73 65 73 2c 20 74 In both cases, t
4700: 68 65 20 53 45 4c 45 43 54 20 73 68 6f 75 6c 64 he SELECT should
4710: 20 68 61 76 65 20 6f 6e 6c 79 20 61 20 73 69 6e have only a sin
4720: 67 6c 65 20 63 6f 6c 75 6d 6e 20 69 6e 20 69 74 gle column in it
4730: 73 0a 72 65 73 75 6c 74 2e 20 20 43 6f 6d 70 6f s.result. Compo
4740: 75 6e 64 20 53 45 4c 45 43 54 73 20 28 63 6f 6e und SELECTs (con
4750: 6e 65 63 74 65 64 20 77 69 74 68 20 6b 65 79 77 nected with keyw
4760: 6f 72 64 73 20 6c 69 6b 65 20 55 4e 49 4f 4e 20 ords like UNION
4770: 6f 72 0a 45 58 43 45 50 54 29 20 61 72 65 20 61 or.EXCEPT) are a
4780: 6c 6c 6f 77 65 64 2e 20 20 41 6e 79 20 4f 52 44 llowed. Any ORD
4790: 45 52 20 42 59 20 63 6c 61 75 73 65 20 6f 6e 20 ER BY clause on
47a0: 74 68 65 20 73 65 6c 65 63 74 20 69 73 20 69 67 the select is ig
47b0: 6e 6f 72 65 64 2e 0a 41 20 53 45 4c 45 43 54 20 nored..A SELECT
47c0: 69 6e 20 61 6e 20 65 78 70 72 65 73 73 69 6f 6e in an expression
47d0: 20 69 73 20 65 76 61 6c 75 61 74 65 64 20 6f 6e is evaluated on
47e0: 63 65 20 62 65 66 6f 72 65 20 61 6e 79 20 6f 74 ce before any ot
47f0: 68 65 72 20 70 72 6f 63 65 73 73 69 6e 67 0a 69 her processing.i
4800: 73 20 70 65 72 66 6f 72 6d 65 64 2c 20 73 6f 20 s performed, so
4810: 6e 6f 6e 65 20 6f 66 20 74 68 65 20 65 78 70 72 none of the expr
4820: 65 73 73 69 6f 6e 73 20 77 69 74 68 69 6e 20 74 essions within t
4830: 68 65 20 73 65 6c 65 63 74 20 69 74 73 65 6c 66 he select itself
4840: 20 63 61 6e 0a 72 65 66 65 72 20 74 6f 20 71 75 can.refer to qu
4850: 61 6e 74 69 74 69 65 73 20 69 6e 20 74 68 65 20 antities in the
4860: 63 6f 6e 74 61 69 6e 69 6e 67 20 65 78 70 72 65 containing expre
4870: 73 73 69 6f 6e 2e 3c 2f 70 3e 0a 0a 3c 70 3e 57 ssion.</p>..<p>W
4880: 68 65 6e 20 61 20 53 45 4c 45 43 54 20 69 73 20 hen a SELECT is
4890: 74 68 65 20 72 69 67 68 74 20 6f 70 65 72 61 6e the right operan
48a0: 64 20 6f 66 20 74 68 65 20 49 4e 20 6f 70 65 72 d of the IN oper
48b0: 61 74 6f 72 2c 20 74 68 65 20 49 4e 0a 6f 70 65 ator, the IN.ope
48c0: 72 61 74 6f 72 20 72 65 74 75 72 6e 73 20 54 52 rator returns TR
48d0: 55 45 20 69 66 20 74 68 65 20 72 65 73 75 6c 74 UE if the result
48e0: 20 6f 66 20 74 68 65 20 6c 65 66 74 20 6f 70 65 of the left ope
48f0: 72 61 6e 64 20 69 73 20 61 6e 79 20 6f 66 0a 74 rand is any of.t
4900: 68 65 20 76 61 6c 75 65 73 20 67 65 6e 65 72 61 he values genera
4910: 74 65 64 20 62 79 20 74 68 65 20 73 65 6c 65 63 ted by the selec
4920: 74 2e 20 20 54 68 65 20 49 4e 20 6f 70 65 72 61 t. The IN opera
4930: 74 6f 72 20 6d 61 79 20 62 65 20 70 72 65 63 65 tor may be prece
4940: 64 65 64 0a 62 79 20 74 68 65 20 4e 4f 54 20 6b ded.by the NOT k
4950: 65 79 77 6f 72 64 20 74 6f 20 69 6e 76 65 72 74 eyword to invert
4960: 20 74 68 65 20 73 65 6e 73 65 20 6f 66 20 74 68 the sense of th
4970: 65 20 74 65 73 74 2e 3c 2f 70 3e 0a 0a 3c 70 3e e test.</p>..<p>
4980: 57 68 65 6e 20 61 20 53 45 4c 45 43 54 20 61 70 When a SELECT ap
4990: 70 65 61 72 73 20 77 69 74 68 69 6e 20 61 6e 20 pears within an
49a0: 65 78 70 72 65 73 73 69 6f 6e 20 62 75 74 20 69 expression but i
49b0: 73 20 6e 6f 74 20 74 68 65 20 72 69 67 68 74 0a s not the right.
49c0: 6f 70 65 72 61 6e 64 20 6f 66 20 61 6e 20 49 4e operand of an IN
49d0: 20 6f 70 65 72 61 74 6f 72 2c 20 74 68 65 6e 20 operator, then
49e0: 74 68 65 20 66 69 72 73 74 20 72 6f 77 20 6f 66 the first row of
49f0: 20 74 68 65 20 72 65 73 75 6c 74 20 6f 66 20 74 the result of t
4a00: 68 65 0a 53 45 4c 45 43 54 20 62 65 63 6f 6d 65 he.SELECT become
4a10: 73 20 74 68 65 20 76 61 6c 75 65 20 75 73 65 64 s the value used
4a20: 20 69 6e 20 74 68 65 20 65 78 70 72 65 73 73 69 in the expressi
4a30: 6f 6e 2e 20 20 49 66 20 74 68 65 20 53 45 4c 45 on. If the SELE
4a40: 43 54 20 79 69 65 6c 64 73 0a 6d 6f 72 65 20 74 CT yields.more t
4a50: 68 61 6e 20 6f 6e 65 20 72 65 73 75 6c 74 20 72 han one result r
4a60: 6f 77 2c 20 61 6c 6c 20 72 6f 77 73 20 61 66 74 ow, all rows aft
4a70: 65 72 20 74 68 65 20 66 69 72 73 74 20 61 72 65 er the first are
4a80: 20 69 67 6e 6f 72 65 64 2e 20 20 49 66 0a 74 68 ignored. If.th
4a90: 65 20 53 45 4c 45 43 54 20 79 65 69 6c 64 73 20 e SELECT yeilds
4aa0: 6e 6f 20 72 6f 77 73 2c 20 74 68 65 6e 20 74 68 no rows, then th
4ab0: 65 20 76 61 6c 75 65 20 6f 66 20 74 68 65 20 53 e value of the S
4ac0: 45 4c 45 43 54 20 69 73 20 4e 55 4c 4c 2e 3c 2f ELECT is NULL.</
4ad0: 70 3e 0a 0a 3c 70 3e 54 68 65 20 65 78 70 72 65 p>..<p>The expre
4ae0: 73 73 69 6f 6e 20 73 79 6e 74 61 78 20 63 75 72 ssion syntax cur
4af0: 72 65 6e 74 6c 79 20 73 75 70 70 6f 72 74 73 20 rently supports
4b00: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a 66 75 the following.fu
4b10: 6e 63 74 69 6f 6e 73 3a 3c 2f 70 3e 0a 0a 3c 62 nctions:</p>..<b
4b20: 6c 6f 63 6b 71 75 6f 74 65 3e 3c 70 72 65 3e 0a lockquote><pre>.
4b30: 3c 66 6f 6e 74 20 63 6f 6c 6f 72 3d 22 23 32 63 <font color="#2c
4b40: 32 63 66 30 22 3e 3c 62 69 67 3e 63 6f 75 6e 74 2cf0"><big>count
4b50: 20 20 20 20 6d 69 6e 20 20 20 20 20 20 20 6d 61 min ma
4b60: 78 20 20 20 20 20 20 20 73 75 6d 0a 61 76 67 20 x sum.avg
4b70: 20 20 20 20 20 6c 65 6e 67 74 68 20 20 20 20 73 length s
4b80: 75 62 73 74 72 20 20 20 20 61 62 73 20 20 20 20 ubstr abs
4b90: 20 20 20 72 6f 75 6e 64 3c 2f 62 69 67 3e 3c 2f round</big></
4ba0: 66 6f 6e 74 3e 0a 3c 2f 70 72 65 3e 3c 2f 62 6c font>.</pre></bl
4bb0: 6f 63 6b 71 75 6f 74 65 3e 0a 0a 3c 70 3e 0a 54 ockquote>..<p>.T
4bc0: 68 65 20 66 75 6e 63 74 69 6f 6e 73 20 3c 62 3e he functions <b>
4bd0: 63 6f 75 6e 74 3c 2f 62 3e 2c 20 3c 62 3e 73 75 count</b>, <b>su
4be0: 6d 3c 2f 62 3e 2c 20 61 6e 64 20 3c 62 3e 61 76 m</b>, and <b>av
4bf0: 67 3c 2f 62 3e 20 61 6e 64 20 74 68 65 20 66 75 g</b> and the fu
4c00: 6e 63 74 69 6f 6e 73 0a 3c 62 3e 6d 69 6e 3c 2f nctions.<b>min</
4c10: 62 3e 20 61 6e 64 20 3c 62 3e 6d 61 78 3c 2f 62 b> and <b>max</b
4c20: 3e 20 75 73 65 64 20 77 69 74 68 20 6f 6e 6c 79 > used with only
4c30: 20 6f 6e 65 20 61 72 67 75 6d 65 6e 74 20 61 72 one argument ar
4c40: 65 20 61 6c 6c 20 61 67 67 72 65 67 61 74 65 0a e all aggregate.
4c50: 66 75 6e 63 74 69 6f 6e 73 2e 20 20 54 68 69 73 functions. This
4c60: 20 6d 65 61 6e 73 20 74 68 61 74 20 74 68 65 79 means that they
4c70: 20 61 72 65 20 63 6f 6d 70 75 74 65 64 20 61 63 are computed ac
4c80: 72 6f 73 73 20 61 6c 6c 20 72 6f 77 73 20 6f 66 ross all rows of
4c90: 20 74 68 65 20 72 65 73 75 6c 74 2e 0a 54 68 65 the result..The
4ca0: 20 66 75 6e 63 74 69 6f 6e 73 20 3c 62 3e 6d 69 functions <b>mi
4cb0: 6e 3c 2f 62 3e 20 61 6e 64 20 3c 62 3e 6d 61 78 n</b> and <b>max
4cc0: 3c 2f 62 3e 0a 77 69 74 68 20 74 77 6f 20 6f 72 </b>.with two or
4cd0: 20 6d 6f 72 65 20 61 72 67 75 6d 65 6e 74 73 20 more arguments
4ce0: 61 6e 64 20 61 6c 6c 20 6f 74 68 65 72 20 66 75 and all other fu
4cf0: 6e 63 74 69 6f 6e 73 0a 61 72 65 20 6e 6f 6e 2d nctions.are non-
4d00: 61 67 67 72 65 67 61 74 65 73 2e 20 20 4e 6f 6e aggregates. Non
4d10: 2d 61 67 67 72 65 67 61 74 65 20 66 75 6e 63 74 -aggregate funct
4d20: 69 6f 6e 73 0a 61 72 65 20 63 6f 6d 70 75 74 65 ions.are compute
4d30: 64 20 73 65 70 61 72 61 74 65 6c 79 20 66 6f 72 d separately for
4d40: 20 65 61 63 68 20 72 6f 77 20 6f 66 20 74 68 65 each row of the
4d50: 20 72 65 73 75 6c 74 2e 0a 3c 2f 70 3e 0a 0a 3c result..</p>..<
4d60: 70 3e 0a 54 68 65 20 3c 62 3e 72 6f 75 6e 64 3c p>.The <b>round<
4d70: 2f 62 3e 20 66 75 6e 63 74 69 6f 6e 20 63 61 6e /b> function can
4d80: 20 74 61 6b 65 20 65 69 74 68 65 72 20 31 20 6f take either 1 o
4d90: 72 20 32 20 61 72 67 75 6d 65 6e 74 73 2e 20 20 r 2 arguments.
4da0: 54 68 65 0a 66 69 72 73 74 20 61 72 67 75 6d 65 The.first argume
4db0: 6e 74 20 69 73 20 74 68 65 20 66 6c 6f 61 74 69 nt is the floati
4dc0: 6e 67 20 70 6f 69 6e 74 20 76 61 6c 75 65 20 74 ng point value t
4dd0: 68 61 74 20 69 73 20 72 6f 75 6e 64 65 64 2e 20 hat is rounded.
4de0: 20 54 68 65 0a 73 65 63 6f 6e 64 20 61 72 67 75 The.second argu
4df0: 6d 65 6e 74 20 69 73 20 74 68 65 20 6e 75 6d 62 ment is the numb
4e00: 65 72 20 6f 66 20 64 69 67 69 74 73 20 74 6f 20 er of digits to
4e10: 74 68 65 20 72 69 67 68 74 20 6f 66 20 74 68 65 the right of the
4e20: 0a 64 65 63 69 6d 61 6c 20 70 6f 69 6e 74 20 74 .decimal point t
4e30: 6f 20 70 72 65 73 65 72 76 65 2e 20 20 49 66 20 o preserve. If
4e40: 74 68 65 20 73 65 63 6f 6e 64 20 61 72 67 75 6d the second argum
4e50: 65 6e 74 20 69 73 20 6f 6d 69 74 74 65 64 2c 0a ent is omitted,.
4e60: 7a 65 72 6f 20 69 73 20 61 73 73 75 6d 65 64 2e zero is assumed.
4e70: 20 20 53 6f 20 72 6f 75 6e 64 28 31 2e 32 33 34 So round(1.234
4e80: 35 36 2c 32 29 20 69 73 20 31 2e 32 33 20 61 6e 56,2) is 1.23 an
4e90: 64 0a 72 6f 75 6e 64 28 31 32 2e 33 34 2c 30 29 d.round(12.34,0)
4ea0: 20 61 6e 64 20 72 6f 75 6e 64 28 31 32 2e 33 34 and round(12.34
4eb0: 29 20 62 6f 74 68 20 65 76 61 6c 75 61 74 65 20 ) both evaluate
4ec0: 74 6f 20 31 32 2e 0a 3c 2f 70 3e 0a 0a 3c 70 3e to 12..</p>..<p>
4ed0: 0a 54 68 65 20 22 3c 62 3e 63 6f 75 6e 74 28 2a .The "<b>count(*
4ee0: 29 3c 2f 62 3e 22 20 73 79 6e 74 61 78 20 69 73 )</b>" syntax is
4ef0: 20 73 75 70 70 6f 72 74 65 64 20 62 75 74 0a 22 supported but."
4f00: 3c 62 3e 63 6f 75 6e 74 28 64 69 73 74 69 6e 63 <b>count(distinc
4f10: 74 3c 2f 62 3e 20 3c 69 3e 43 4f 4c 55 4d 4e 2d t</b> <i>COLUMN-
4f20: 4e 41 4d 45 3c 2f 69 3e 3c 62 3e 29 3c 2f 62 3e NAME</i><b>)</b>
4f30: 22 20 69 73 20 6e 6f 74 2e 0a 3c 2f 70 3e 0a 7d " is not..</p>.}
4f40: 0a 0a 53 65 63 74 69 6f 6e 20 49 4e 53 45 52 54 ..Section INSERT
4f50: 20 69 6e 73 65 72 74 0a 0a 53 79 6e 74 61 78 20 insert..Syntax
4f60: 7b 73 71 6c 2d 73 74 61 74 65 6d 65 6e 74 7d 20 {sql-statement}
4f70: 7b 0a 49 4e 53 45 52 54 20 5b 4f 52 20 3c 63 6f {.INSERT [OR <co
4f80: 6e 66 6c 69 63 74 2d 61 6c 67 6f 72 69 74 68 6d nflict-algorithm
4f90: 3e 5d 20 49 4e 54 4f 20 3c 74 61 62 6c 65 2d 6e >] INTO <table-n
4fa0: 61 6d 65 3e 20 5b 28 3c 63 6f 6c 75 6d 6e 2d 6c ame> [(<column-l
4fb0: 69 73 74 3e 29 5d 20 56 41 4c 55 45 53 28 3c 76 ist>)] VALUES(<v
4fc0: 61 6c 75 65 2d 6c 69 73 74 3e 29 20 7c 0a 49 4e alue-list>) |.IN
4fd0: 53 45 52 54 20 5b 4f 52 20 3c 63 6f 6e 66 6c 69 SERT [OR <confli
4fe0: 63 74 2d 61 6c 67 6f 72 69 74 68 6d 3e 5d 20 49 ct-algorithm>] I
4ff0: 4e 54 4f 20 3c 74 61 62 6c 65 2d 6e 61 6d 65 3e NTO <table-name>
5000: 20 5b 28 3c 63 6f 6c 75 6d 6e 2d 6c 69 73 74 3e [(<column-list>
5010: 29 5d 20 3c 73 65 6c 65 63 74 2d 73 74 61 74 65 )] <select-state
5020: 6d 65 6e 74 3e 0a 7d 0a 0a 70 75 74 73 20 7b 0a ment>.}..puts {.
5030: 3c 70 3e 54 68 65 20 49 4e 53 45 52 54 20 73 74 <p>The INSERT st
5040: 61 74 65 6d 65 6e 74 20 63 6f 6d 65 73 20 69 6e atement comes in
5050: 20 74 77 6f 20 62 61 73 69 63 20 66 6f 72 6d 73 two basic forms
5060: 2e 20 20 54 68 65 20 66 69 72 73 74 20 66 6f 72 . The first for
5070: 6d 0a 28 77 69 74 68 20 74 68 65 20 22 56 41 4c m.(with the "VAL
5080: 55 45 53 22 20 6b 65 79 77 6f 72 64 29 20 63 72 UES" keyword) cr
5090: 65 61 74 65 73 20 61 20 73 69 6e 67 6c 65 20 6e eates a single n
50a0: 65 77 20 72 6f 77 20 69 6e 20 61 6e 20 65 78 69 ew row in an exi
50b0: 73 74 69 6e 67 20 74 61 62 6c 65 2e 0a 49 66 20 sting table..If
50c0: 6e 6f 20 63 6f 6c 75 6d 6e 2d 6c 69 73 74 20 69 no column-list i
50d0: 73 20 73 70 65 63 69 66 69 65 64 20 74 68 65 6e s specified then
50e0: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 76 the number of v
50f0: 61 6c 75 65 73 20 6d 75 73 74 0a 62 65 20 74 68 alues must.be th
5100: 65 20 73 61 6d 65 20 61 73 20 74 68 65 20 6e 75 e same as the nu
5110: 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 mber of columns
5120: 69 6e 20 74 68 65 20 74 61 62 6c 65 2e 20 20 49 in the table. I
5130: 66 20 61 20 63 6f 6c 75 6d 6e 2d 6c 69 73 74 0a f a column-list.
5140: 69 73 20 73 70 65 63 69 66 69 65 64 2c 20 74 68 is specified, th
5150: 65 6e 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 en the number of
5160: 20 76 61 6c 75 65 73 20 6d 75 73 74 20 6d 61 74 values must mat
5170: 63 68 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 ch the number of
5180: 0a 73 70 65 63 69 66 69 65 64 20 63 6f 6c 75 6d .specified colum
5190: 6e 73 2e 20 20 43 6f 6c 75 6d 6e 73 20 6f 66 20 ns. Columns of
51a0: 74 68 65 20 74 61 62 6c 65 20 74 68 61 74 20 64 the table that d
51b0: 6f 20 6e 6f 74 20 61 70 70 65 61 72 20 69 6e 20 o not appear in
51c0: 74 68 65 0a 63 6f 6c 75 6d 6e 20 6c 69 73 74 20 the.column list
51d0: 61 72 65 20 66 69 6c 6c 20 77 69 74 68 20 74 68 are fill with th
51e0: 65 20 64 65 66 61 75 6c 74 20 76 61 6c 75 65 2c e default value,
51f0: 20 6f 72 20 77 69 74 68 20 4e 55 4c 4c 20 69 66 or with NULL if
5200: 20 6e 6f 74 0a 64 65 66 61 75 6c 74 20 76 61 6c not.default val
5210: 75 65 20 69 73 20 73 70 65 63 69 66 69 65 64 2e ue is specified.
5220: 0a 3c 2f 70 3e 0a 0a 3c 70 3e 54 68 65 20 73 65 .</p>..<p>The se
5230: 63 6f 6e 64 20 66 6f 72 6d 20 6f 66 20 74 68 65 cond form of the
5240: 20 49 4e 53 45 52 54 20 73 74 61 74 65 6d 65 6e INSERT statemen
5250: 74 20 74 61 6b 65 73 20 69 74 20 64 61 74 61 20 t takes it data
5260: 66 72 6f 6d 20 61 0a 53 45 4c 45 43 54 20 73 74 from a.SELECT st
5270: 61 74 65 6d 65 6e 74 2e 20 20 54 68 65 20 6e 75 atement. The nu
5280: 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 20 mber of columns
5290: 69 6e 20 74 68 65 20 72 65 73 75 6c 74 20 6f 66 in the result of
52a0: 20 74 68 65 0a 53 45 4c 45 43 54 20 6d 75 73 74 the.SELECT must
52b0: 20 65 78 61 63 74 6c 79 20 6d 61 74 63 68 20 74 exactly match t
52c0: 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 63 6f 6c he number of col
52d0: 75 6d 6e 73 20 69 6e 20 74 68 65 20 74 61 62 6c umns in the tabl
52e0: 65 20 69 66 0a 6e 6f 20 63 6f 6c 75 6d 6e 20 6c e if.no column l
52f0: 69 73 74 20 69 73 20 73 70 65 63 69 66 69 65 64 ist is specified
5300: 2c 20 6f 72 20 69 74 20 6d 75 73 74 20 6d 61 74 , or it must mat
5310: 63 68 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 ch the number of
5320: 20 63 6f 6c 75 6d 6e 73 0a 6e 61 6d 65 20 69 6e columns.name in
5330: 20 74 68 65 20 63 6f 6c 75 6d 6e 20 6c 69 73 74 the column list
5340: 2e 20 20 41 20 6e 65 77 20 65 6e 74 72 79 20 69 . A new entry i
5350: 73 20 6d 61 64 65 20 69 6e 20 74 68 65 20 74 61 s made in the ta
5360: 62 6c 65 0a 66 6f 72 20 65 76 65 72 79 20 72 6f ble.for every ro
5370: 77 20 6f 66 20 74 68 65 20 53 45 4c 45 43 54 20 w of the SELECT
5380: 72 65 73 75 6c 74 2e 20 20 54 68 65 20 53 45 4c result. The SEL
5390: 45 43 54 20 6d 61 79 20 62 65 20 73 69 6d 70 6c ECT may be simpl
53a0: 65 0a 6f 72 20 63 6f 6d 70 6f 75 6e 64 2e 20 20 e.or compound.
53b0: 49 66 20 74 68 65 20 53 45 4c 45 43 54 20 73 74 If the SELECT st
53c0: 61 74 65 6d 65 6e 74 20 68 61 73 20 61 6e 20 4f atement has an O
53d0: 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 2c 0a RDER BY clause,.
53e0: 74 68 65 20 4f 52 44 45 52 20 42 59 20 69 73 20 the ORDER BY is
53f0: 69 67 6e 6f 72 65 64 2e 3c 2f 70 3e 0a 0a 3c 70 ignored.</p>..<p
5400: 3e 54 68 65 20 6f 70 74 69 6f 6e 61 6c 20 63 6f >The optional co
5410: 6e 66 6c 69 63 74 2d 63 6c 61 75 73 65 20 61 6c nflict-clause al
5420: 6c 6f 77 73 20 74 68 65 20 73 70 65 63 69 66 69 lows the specifi
5430: 63 61 74 69 6f 6e 20 6f 66 20 61 6e 20 61 6c 74 cation of an alt
5440: 65 72 6e 61 74 69 76 65 0a 63 6f 6e 73 74 72 61 ernative.constra
5450: 69 6e 74 20 63 6f 6e 66 6c 69 63 74 20 72 65 73 int conflict res
5460: 6f 6c 75 74 69 6f 6e 20 61 6c 67 6f 72 69 74 68 olution algorith
5470: 6d 20 74 6f 20 75 73 65 20 64 75 72 69 6e 67 20 m to use during
5480: 74 68 69 73 20 6f 6e 65 20 63 6f 6d 6d 61 6e 64 this one command
5490: 2e 0a 53 65 65 20 74 68 65 20 73 65 63 74 69 6f ..See the sectio
54a0: 6e 20 74 69 74 6c 65 64 0a 3c 61 20 68 72 65 66 n titled.<a href
54b0: 3d 22 23 63 6f 6e 66 6c 69 63 74 22 3e 4f 4e 20 ="#conflict">ON
54c0: 43 4f 4e 46 4c 49 43 54 3c 2f 61 3e 20 66 6f 72 CONFLICT</a> for
54d0: 20 61 64 64 69 74 69 6f 6e 61 6c 20 69 6e 66 6f additional info
54e0: 72 6d 61 74 69 6f 6e 2e 0a 46 6f 72 20 63 6f 6d rmation..For com
54f0: 70 61 74 69 62 69 6c 69 74 79 20 77 69 74 68 20 patibility with
5500: 4d 79 53 51 4c 2c 20 74 68 65 20 70 61 72 73 65 MySQL, the parse
5510: 72 20 61 6c 6c 6f 77 73 20 74 68 65 20 75 73 65 r allows the use
5520: 20 6f 66 20 74 68 65 0a 73 69 6e 67 6c 65 20 6b of the.single k
5530: 65 79 77 6f 72 64 20 22 52 45 50 4c 41 43 45 22 eyword "REPLACE"
5540: 20 61 73 20 61 6e 20 61 6c 69 61 73 20 66 6f 72 as an alias for
5550: 20 22 49 4e 53 45 52 54 20 4f 52 20 52 45 50 4c "INSERT OR REPL
5560: 41 43 45 22 2e 0a 3c 2f 70 3e 0a 7d 0a 0a 53 65 ACE"..</p>.}..Se
5570: 63 74 69 6f 6e 20 7b 4f 4e 20 43 4f 4e 46 4c 49 ction {ON CONFLI
5580: 43 54 20 63 6c 61 75 73 65 7d 20 63 6f 6e 66 6c CT clause} confl
5590: 69 63 74 0a 0a 53 79 6e 74 61 78 20 7b 63 6f 6e ict..Syntax {con
55a0: 66 6c 69 63 74 2d 63 6c 61 75 73 65 7d 20 7b 0a flict-clause} {.
55b0: 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 3c 63 6f 6e ON CONFLICT <con
55c0: 66 6c 69 63 74 2d 61 6c 67 6f 72 69 74 68 6d 3e flict-algorithm>
55d0: 0a 7d 20 7b 63 6f 6e 66 6c 69 63 74 2d 61 6c 67 .} {conflict-alg
55e0: 6f 72 69 74 68 6d 7d 20 7b 0a 52 4f 4c 4c 42 41 orithm} {.ROLLBA
55f0: 43 4b 20 7c 20 41 42 4f 52 54 20 7c 20 46 41 49 CK | ABORT | FAI
5600: 4c 20 7c 20 49 47 4e 4f 52 45 20 7c 20 52 45 50 L | IGNORE | REP
5610: 4c 41 43 45 0a 7d 0a 0a 70 75 74 73 20 7b 0a 3c LACE.}..puts {.<
5620: 70 3e 54 68 65 20 4f 4e 20 43 4f 4e 46 4c 49 43 p>The ON CONFLIC
5630: 54 20 63 6c 61 75 73 65 20 69 73 20 6e 6f 74 20 T clause is not
5640: 61 20 73 65 70 61 72 61 74 65 20 53 51 4c 20 63 a separate SQL c
5650: 6f 6d 6d 61 6e 64 2e 20 20 49 74 20 69 73 20 61 ommand. It is a
5660: 0a 6e 6f 6e 2d 73 74 61 6e 64 61 72 64 20 63 6c .non-standard cl
5670: 61 75 73 65 20 74 68 61 74 20 63 61 6e 20 61 70 ause that can ap
5680: 70 65 61 72 20 69 6e 20 6d 61 6e 79 20 6f 74 68 pear in many oth
5690: 65 72 20 53 51 4c 20 63 6f 6d 6d 61 6e 64 73 2e er SQL commands.
56a0: 0a 49 74 20 69 73 20 67 69 76 65 6e 20 69 74 73 .It is given its
56b0: 20 6f 77 6e 20 73 65 63 74 69 6f 6e 20 69 6e 20 own section in
56c0: 74 68 69 73 20 64 6f 63 75 6d 65 6e 74 20 62 65 this document be
56d0: 63 61 75 73 65 20 69 74 20 69 73 20 6e 6f 74 0a cause it is not.
56e0: 70 61 72 74 20 6f 66 20 73 74 61 6e 64 61 72 64 part of standard
56f0: 20 53 51 4c 20 61 6e 64 20 74 68 65 72 65 66 6f SQL and therefo
5700: 72 65 20 6d 69 67 68 74 20 6e 6f 74 20 62 65 20 re might not be
5710: 66 61 6d 69 6c 69 61 72 2e 3c 2f 70 3e 0a 0a 3c familiar.</p>..<
5720: 70 3e 54 68 65 20 73 79 6e 74 61 78 20 66 6f 72 p>The syntax for
5730: 20 74 68 65 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 the ON CONFLICT
5740: 20 63 6c 61 75 73 65 20 69 73 20 61 73 20 73 68 clause is as sh
5750: 6f 77 6e 20 61 62 6f 76 65 20 66 6f 72 0a 74 68 own above for.th
5760: 65 20 43 52 45 41 54 45 20 54 41 42 4c 45 2c 20 e CREATE TABLE,
5770: 43 52 45 41 54 45 20 49 4e 44 45 58 2c 20 61 6e CREATE INDEX, an
5780: 64 20 42 45 47 49 4e 20 54 52 41 4e 53 41 43 54 d BEGIN TRANSACT
5790: 49 4f 4e 20 63 6f 6d 6d 61 6e 64 73 2e 0a 46 6f ION commands..Fo
57a0: 72 20 74 68 65 20 43 4f 50 59 2c 20 49 4e 53 45 r the COPY, INSE
57b0: 52 54 2c 20 61 6e 64 20 55 50 44 41 54 45 20 63 RT, and UPDATE c
57c0: 6f 6d 6d 61 6e 64 73 2c 20 74 68 65 20 6b 65 79 ommands, the key
57d0: 77 6f 72 64 73 0a 22 4f 4e 20 43 4f 4e 46 4c 49 words."ON CONFLI
57e0: 43 54 22 20 61 72 65 20 72 65 70 6c 61 63 65 64 CT" are replaced
57f0: 20 62 79 20 22 4f 52 22 2c 20 74 6f 20 6d 61 6b by "OR", to mak
5800: 65 20 74 68 65 20 73 79 6e 74 61 78 20 73 65 65 e the syntax see
5810: 6d 20 6d 6f 72 65 0a 6e 61 74 75 72 61 6c 2e 20 m more.natural.
5820: 20 42 75 74 20 74 68 65 20 6d 65 61 6e 69 6e 67 But the meaning
5830: 20 6f 66 20 74 68 65 20 63 6c 61 75 73 65 20 69 of the clause i
5840: 73 20 74 68 65 20 73 61 6d 65 20 65 69 74 68 65 s the same eithe
5850: 72 20 77 61 79 2e 3c 2f 70 3e 0a 0a 3c 70 3e 54 r way.</p>..<p>T
5860: 68 65 20 4f 4e 20 43 4f 4e 46 4c 49 43 54 20 63 he ON CONFLICT c
5870: 6c 61 75 73 65 20 73 70 65 63 69 66 69 65 73 20 lause specifies
5880: 61 6e 20 61 6c 67 6f 72 69 74 68 6d 20 75 73 65 an algorithm use
5890: 64 20 74 6f 20 72 65 73 6f 6c 76 65 0a 63 6f 6e d to resolve.con
58a0: 73 74 72 61 69 6e 74 20 63 6f 6e 66 6c 69 63 74 straint conflict
58b0: 73 2e 20 20 54 68 65 72 65 20 61 72 65 20 66 69 s. There are fi
58c0: 76 65 20 63 68 6f 69 63 65 73 3a 20 52 4f 4c 4c ve choices: ROLL
58d0: 42 41 43 4b 2c 20 41 42 4f 52 54 2c 0a 46 41 49 BACK, ABORT,.FAI
58e0: 4c 2c 20 49 47 4e 4f 52 45 2c 20 61 6e 64 20 52 L, IGNORE, and R
58f0: 45 50 4c 41 43 45 2e 20 54 68 65 20 64 65 66 61 EPLACE. The defa
5900: 75 6c 74 20 61 6c 67 6f 72 69 74 68 6d 20 69 73 ult algorithm is
5910: 20 41 42 4f 52 54 2e 20 20 54 68 69 73 0a 69 73 ABORT. This.is
5920: 20 77 68 61 74 20 74 68 65 79 20 6d 65 61 6e 3a what they mean:
5930: 3c 2f 70 3e 0a 0a 3c 64 6c 3e 0a 3c 64 74 3e 3c </p>..<dl>.<dt><
5940: 62 3e 52 4f 4c 4c 42 41 43 4b 3c 2f 62 3e 3c 2f b>ROLLBACK</b></
5950: 64 74 3e 0a 3c 64 64 3e 3c 70 3e 57 68 65 6e 20 dt>.<dd><p>When
5960: 61 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 6f a constraint vio
5970: 6c 61 74 69 6f 6e 20 6f 63 63 75 72 73 2c 20 61 lation occurs, a
5980: 6e 20 69 6d 6d 65 64 69 61 74 65 20 52 4f 4c 4c n immediate ROLL
5990: 42 41 43 4b 0a 6f 63 63 75 72 73 2c 20 74 68 75 BACK.occurs, thu
59a0: 73 20 65 6e 64 69 6e 67 20 74 68 65 20 63 75 72 s ending the cur
59b0: 72 65 6e 74 20 74 72 61 6e 73 61 63 74 69 6f 6e rent transaction
59c0: 2c 20 61 6e 64 20 74 68 65 20 63 6f 6d 6d 61 6e , and the comman
59d0: 64 20 61 62 6f 72 74 73 0a 77 69 74 68 20 61 20 d aborts.with a
59e0: 72 65 74 75 72 6e 20 63 6f 64 65 20 6f 66 20 53 return code of S
59f0: 51 4c 49 54 45 5f 43 4f 4e 53 54 52 41 49 4e 54 QLITE_CONSTRAINT
5a00: 2e 20 20 49 66 20 6e 6f 20 74 72 61 6e 73 61 63 . If no transac
5a10: 74 69 6f 6e 20 69 73 0a 61 63 74 69 76 65 20 28 tion is.active (
5a20: 6f 74 68 65 72 20 74 68 61 6e 20 74 68 65 20 69 other than the i
5a30: 6d 70 6c 69 65 64 20 74 72 61 6e 73 61 63 74 69 mplied transacti
5a40: 6f 6e 20 74 68 61 74 20 69 73 20 63 72 65 61 74 on that is creat
5a50: 65 64 20 6f 6e 20 65 76 65 72 79 0a 63 6f 6d 6d ed on every.comm
5a60: 61 6e 64 29 20 74 68 65 6e 20 74 68 69 73 20 61 and) then this a
5a70: 6c 67 6f 72 69 74 68 6d 20 77 6f 72 6b 73 20 74 lgorithm works t
5a80: 68 65 20 73 61 6d 65 20 61 73 20 41 42 4f 52 54 he same as ABORT
5a90: 2e 3c 2f 70 3e 3c 2f 64 64 3e 0a 0a 3c 64 74 3e .</p></dd>..<dt>
5aa0: 3c 62 3e 41 42 4f 52 54 3c 2f 62 3e 3c 2f 64 74 <b>ABORT</b></dt
5ab0: 3e 0a 3c 64 64 3e 3c 70 3e 57 68 65 6e 20 61 20 >.<dd><p>When a
5ac0: 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c 61 constraint viola
5ad0: 74 69 6f 6e 20 6f 63 63 75 72 73 2c 20 74 68 65 tion occurs, the
5ae0: 20 63 6f 6d 6d 61 6e 64 20 62 61 63 6b 73 20 6f command backs o
5af0: 75 74 0a 61 6e 79 20 70 72 69 6f 72 20 63 68 61 ut.any prior cha
5b00: 6e 67 65 73 20 69 74 20 6d 69 67 68 74 20 68 61 nges it might ha
5b10: 76 65 20 6d 61 64 65 20 61 6e 64 20 61 62 6f 72 ve made and abor
5b20: 74 73 20 77 69 74 68 20 61 20 72 65 74 75 72 6e ts with a return
5b30: 20 63 6f 64 65 0a 6f 66 20 53 51 4c 49 54 45 5f code.of SQLITE_
5b40: 43 4f 4e 53 54 52 41 49 4e 54 2e 20 20 42 75 74 CONSTRAINT. But
5b50: 20 6e 6f 20 52 4f 4c 4c 42 41 43 4b 20 69 73 20 no ROLLBACK is
5b60: 65 78 65 63 75 74 65 64 20 73 6f 20 63 68 61 6e executed so chan
5b70: 67 65 73 0a 66 72 6f 6d 20 70 72 69 6f 72 20 63 ges.from prior c
5b80: 6f 6d 6d 61 6e 64 73 20 77 69 74 68 69 6e 20 74 ommands within t
5b90: 68 65 20 73 61 6d 65 20 74 72 61 6e 73 61 63 74 he same transact
5ba0: 69 6f 6e 0a 61 72 65 20 70 72 65 73 65 72 76 65 ion.are preserve
5bb0: 64 2e 20 20 54 68 69 73 20 69 73 20 74 68 65 20 d. This is the
5bc0: 64 65 66 61 75 6c 74 20 62 65 68 61 76 69 6f 72 default behavior
5bd0: 2e 3c 2f 70 3e 3c 2f 64 64 3e 0a 0a 3c 64 74 3e .</p></dd>..<dt>
5be0: 3c 62 3e 46 41 49 4c 3c 2f 62 3e 3c 2f 64 74 3e <b>FAIL</b></dt>
5bf0: 0a 3c 64 64 3e 3c 70 3e 57 68 65 6e 20 61 20 63 .<dd><p>When a c
5c00: 6f 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c 61 74 onstraint violat
5c10: 69 6f 6e 20 6f 63 63 75 72 73 2c 20 74 68 65 20 ion occurs, the
5c20: 63 6f 6d 6d 61 6e 64 20 61 62 6f 72 74 73 20 77 command aborts w
5c30: 69 74 68 20 61 0a 72 65 74 75 72 6e 20 63 6f 64 ith a.return cod
5c40: 65 20 53 51 4c 49 54 45 5f 43 4f 4e 53 54 52 41 e SQLITE_CONSTRA
5c50: 49 4e 54 2e 20 20 42 75 74 20 61 6e 79 20 63 68 INT. But any ch
5c60: 61 6e 67 65 73 20 74 6f 20 74 68 65 20 64 61 74 anges to the dat
5c70: 61 62 61 73 65 20 74 68 61 74 0a 74 68 65 20 63 abase that.the c
5c80: 6f 6d 6d 61 6e 64 20 6d 61 64 65 20 70 72 69 6f ommand made prio
5c90: 72 20 74 6f 20 65 6e 63 6f 75 6e 74 65 72 69 6e r to encounterin
5ca0: 67 20 74 68 65 20 63 6f 6e 73 74 72 61 69 6e 74 g the constraint
5cb0: 20 76 69 6f 6c 61 74 69 6f 6e 0a 61 72 65 20 70 violation.are p
5cc0: 72 65 73 65 72 76 65 64 20 61 6e 64 20 61 72 65 reserved and are
5cd0: 20 6e 6f 74 20 62 61 63 6b 65 64 20 6f 75 74 2e not backed out.
5ce0: 20 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 69 For example, i
5cf0: 66 20 61 6e 20 55 50 44 41 54 45 0a 73 74 61 74 f an UPDATE.stat
5d00: 65 6d 65 6e 74 20 65 6e 63 6f 75 6e 74 65 72 65 ement encountere
5d10: 64 20 61 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 d a constraint v
5d20: 69 6f 6c 61 74 69 6f 6e 20 6f 6e 20 74 68 65 20 iolation on the
5d30: 31 30 30 74 68 20 72 6f 77 20 74 68 61 74 0a 69 100th row that.i
5d40: 74 20 61 74 74 65 6d 70 74 73 20 74 6f 20 75 70 t attempts to up
5d50: 64 61 74 65 2c 20 74 68 65 6e 20 74 68 65 20 66 date, then the f
5d60: 69 72 73 74 20 39 39 20 72 6f 77 20 63 68 61 6e irst 99 row chan
5d70: 67 65 73 20 61 72 65 20 70 72 65 73 65 72 76 65 ges are preserve
5d80: 64 0a 62 75 74 20 63 68 61 6e 67 65 73 20 74 6f d.but changes to
5d90: 20 72 6f 77 73 20 31 30 30 20 61 6e 64 20 62 65 rows 100 and be
5da0: 79 6f 6e 64 20 6e 65 76 65 72 20 6f 63 63 75 72 yond never occur
5db0: 2e 3c 2f 70 3e 3c 2f 64 64 3e 0a 0a 3c 64 74 3e .</p></dd>..<dt>
5dc0: 3c 62 3e 49 47 4e 4f 52 45 3c 2f 62 3e 3c 2f 64 <b>IGNORE</b></d
5dd0: 74 3e 0a 3c 64 64 3e 3c 70 3e 57 68 65 6e 20 61 t>.<dd><p>When a
5de0: 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 69 6f 6c constraint viol
5df0: 61 74 69 6f 6e 20 6f 63 63 75 72 73 2c 20 74 68 ation occurs, th
5e00: 65 20 6f 6e 65 20 72 6f 77 20 74 68 61 74 20 63 e one row that c
5e10: 6f 6e 74 61 69 6e 73 0a 74 68 65 20 63 6f 6e 73 ontains.the cons
5e20: 74 72 61 69 6e 74 20 76 69 6f 6c 61 74 69 6f 6e traint violation
5e30: 20 69 73 20 6e 6f 74 20 69 6e 73 65 72 74 65 64 is not inserted
5e40: 20 6f 72 20 63 68 61 6e 67 65 64 2e 20 20 42 75 or changed. Bu
5e50: 74 20 74 68 65 20 63 6f 6d 6d 61 6e 64 0a 63 6f t the command.co
5e60: 6e 74 69 6e 75 65 73 20 65 78 65 63 75 74 69 6e ntinues executin
5e70: 67 20 6e 6f 72 6d 61 6c 6c 79 2e 20 20 4f 74 68 g normally. Oth
5e80: 65 72 20 72 6f 77 73 20 62 65 66 6f 72 65 20 61 er rows before a
5e90: 6e 64 20 61 66 74 65 72 20 74 68 65 20 72 6f 77 nd after the row
5ea0: 20 74 68 61 74 0a 63 6f 6e 74 61 69 6e 65 64 20 that.contained
5eb0: 74 68 65 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 the constraint v
5ec0: 69 6f 6c 61 74 69 6f 6e 20 63 6f 6e 74 69 6e 75 iolation continu
5ed0: 65 20 74 6f 20 62 65 20 69 6e 73 65 72 74 65 64 e to be inserted
5ee0: 20 6f 72 20 75 70 64 61 74 65 64 0a 6e 6f 72 6d or updated.norm
5ef0: 61 6c 6c 79 2e 20 20 4e 6f 20 65 72 72 6f 72 20 ally. No error
5f00: 69 73 20 72 65 74 75 72 6e 65 64 2e 3c 2f 70 3e is returned.</p>
5f10: 3c 2f 64 64 3e 0a 0a 3c 64 74 3e 3c 62 3e 52 45 </dd>..<dt><b>RE
5f20: 50 4c 41 43 45 3c 2f 62 3e 3c 2f 64 74 3e 0a 3c PLACE</b></dt>.<
5f30: 64 64 3e 3c 70 3e 57 68 65 6e 20 61 20 55 4e 49 dd><p>When a UNI
5f40: 51 55 45 20 63 6f 6e 73 74 72 61 69 6e 74 20 76 QUE constraint v
5f50: 69 6f 6c 61 74 69 6f 6e 20 6f 63 63 75 72 73 2c iolation occurs,
5f60: 20 74 68 65 20 70 72 65 2d 65 78 69 73 74 69 6e the pre-existin
5f70: 67 20 72 6f 77 0a 74 68 61 74 20 69 73 20 63 61 g row.that is ca
5f80: 75 73 69 6e 67 20 74 68 65 20 63 6f 6e 73 74 72 using the constr
5f90: 61 69 6e 74 20 76 69 6f 6c 61 74 69 6f 6e 20 69 aint violation i
5fa0: 73 20 72 65 6d 6f 76 65 64 20 70 72 69 6f 72 20 s removed prior
5fb0: 74 6f 20 69 6e 73 65 72 74 69 6e 67 0a 6f 72 20 to inserting.or
5fc0: 75 70 64 61 74 69 6e 67 20 74 68 65 20 63 75 72 updating the cur
5fd0: 72 65 6e 74 20 72 6f 77 2e 20 20 54 68 75 73 20 rent row. Thus
5fe0: 74 68 65 20 69 6e 73 65 72 74 20 6f 72 20 75 70 the insert or up
5ff0: 64 61 74 65 20 61 6c 77 61 79 73 20 6f 63 63 75 date always occu
6000: 72 73 2e 0a 54 68 65 20 63 6f 6d 6d 61 6e 64 20 rs..The command
6010: 63 6f 6e 74 69 6e 75 65 73 20 65 78 65 63 75 74 continues execut
6020: 69 6e 67 20 6e 6f 72 6d 61 6c 6c 79 2e 20 20 4e ing normally. N
6030: 6f 20 65 72 72 6f 72 20 69 73 20 72 65 74 75 72 o error is retur
6040: 6e 65 64 2e 3c 2f 70 3e 0a 3c 70 3e 49 66 20 61 ned.</p>.<p>If a
6050: 20 4e 4f 54 20 4e 55 4c 4c 20 63 6f 6e 73 74 72 NOT NULL constr
6060: 61 69 6e 74 20 76 69 6f 6c 61 74 69 6f 6e 20 6f aint violation o
6070: 63 63 75 72 73 2c 20 74 68 65 20 4e 55 4c 4c 20 ccurs, the NULL
6080: 76 61 6c 75 65 20 69 73 20 72 65 70 6c 61 63 65 value is replace
6090: 64 0a 62 79 20 74 68 65 20 64 65 66 61 75 6c 74 d.by the default
60a0: 20 76 61 6c 75 65 20 66 6f 72 20 74 68 61 74 20 value for that
60b0: 63 6f 6c 75 6d 6e 2e 20 20 49 66 20 74 68 65 20 column. If the
60c0: 63 6f 6c 75 6d 6e 20 68 61 73 20 6e 6f 20 64 65 column has no de
60d0: 66 61 75 6c 74 0a 76 61 6c 75 65 2c 20 74 68 65 fault.value, the
60e0: 6e 20 74 68 65 20 41 42 4f 52 54 20 61 6c 67 6f n the ABORT algo
60f0: 72 69 74 68 6d 20 69 73 20 75 73 65 64 2e 3c 2f rithm is used.</
6100: 70 3e 0a 3c 2f 64 64 3e 0a 3c 2f 64 6c 3e 0a 0a p>.</dd>.</dl>..
6110: 3c 70 3e 0a 54 68 65 20 63 6f 6e 66 6c 69 63 74 <p>.The conflict
6120: 20 72 65 73 6f 6c 75 74 69 6f 6e 20 61 6c 67 6f resolution algo
6130: 72 69 74 68 6d 20 63 61 6e 20 62 65 20 73 70 65 rithm can be spe
6140: 63 69 66 69 65 64 20 69 6e 20 74 68 72 65 65 20 cified in three
6150: 70 6c 61 63 65 73 2c 0a 69 6e 20 6f 72 64 65 72 places,.in order
6160: 20 66 72 6f 6d 20 6c 6f 77 65 73 74 20 74 6f 20 from lowest to
6170: 68 69 67 68 65 73 74 20 70 72 65 63 65 64 65 6e highest preceden
6180: 63 65 3a 0a 3c 2f 70 3e 0a 0a 3c 6f 6c 3e 0a 3c ce:.</p>..<ol>.<
6190: 6c 69 3e 3c 70 3e 0a 4f 6e 20 61 20 42 45 47 49 li><p>.On a BEGI
61a0: 4e 20 54 52 41 4e 53 41 43 54 49 4f 4e 20 63 6f N TRANSACTION co
61b0: 6d 6d 61 6e 64 2e 0a 3c 2f 70 3e 3c 2f 6c 69 3e mmand..</p></li>
61c0: 0a 0a 3c 6c 69 3e 3c 70 3e 0a 4f 6e 20 69 6e 64 ..<li><p>.On ind
61d0: 69 76 69 64 75 61 6c 20 63 6f 6e 73 74 72 61 69 ividual constrai
61e0: 6e 74 73 20 77 69 74 68 69 6e 20 61 20 43 52 45 nts within a CRE
61f0: 41 54 45 20 54 41 42 4c 45 20 6f 72 20 43 52 45 ATE TABLE or CRE
6200: 41 54 45 20 49 4e 44 45 58 0a 73 74 61 74 65 6d ATE INDEX.statem
6210: 65 6e 74 2e 0a 3c 2f 70 3e 3c 2f 6c 69 3e 0a 0a ent..</p></li>..
6220: 3c 6c 69 3e 3c 70 3e 0a 49 6e 20 74 68 65 20 4f <li><p>.In the O
6230: 52 20 63 6c 61 75 73 65 20 6f 66 20 61 20 43 4f R clause of a CO
6240: 50 59 2c 20 49 4e 53 45 52 54 2c 20 6f 72 20 55 PY, INSERT, or U
6250: 50 44 41 54 45 20 63 6f 6d 6d 61 6e 64 2e 0a 3c PDATE command..<
6260: 2f 70 3e 3c 2f 6c 69 3e 0a 3c 2f 6f 6c 3e 0a 0a /p></li>.</ol>..
6270: 3c 70 3e 54 68 65 20 61 6c 67 6f 72 69 74 68 6d <p>The algorithm
6280: 20 73 70 65 63 69 66 69 65 64 20 69 6e 20 74 68 specified in th
6290: 65 20 4f 52 20 63 6c 61 75 73 65 20 6f 66 20 61 e OR clause of a
62a0: 20 43 4f 50 59 2c 20 49 4e 53 45 52 54 2c 20 6f COPY, INSERT, o
62b0: 72 20 55 50 44 41 54 45 0a 6f 76 65 72 72 69 64 r UPDATE.overrid
62c0: 65 73 20 61 6e 79 20 61 6c 67 6f 72 69 74 68 6d es any algorithm
62d0: 20 73 70 65 63 69 66 69 65 64 20 62 79 20 61 20 specified by a
62e0: 43 52 45 41 54 45 20 54 41 42 4c 45 20 6f 72 20 CREATE TABLE or
62f0: 43 52 45 41 54 45 20 49 4e 44 45 58 2e 0a 54 68 CREATE INDEX..Th
6300: 65 20 61 6c 67 6f 72 69 74 68 6d 20 73 70 65 63 e algorithm spec
6310: 69 66 69 65 64 20 77 69 74 68 69 6e 20 61 20 43 ified within a C
6320: 52 45 41 54 45 20 54 41 42 4c 45 20 6f 72 20 43 REATE TABLE or C
6330: 52 45 41 54 45 20 49 4e 44 45 58 20 77 69 6c 6c REATE INDEX will
6340: 2c 20 69 6e 20 74 75 72 6e 2c 0a 6f 76 65 72 72 , in turn,.overr
6350: 69 64 65 20 74 68 65 20 61 6c 67 6f 72 69 74 68 ide the algorith
6360: 6d 20 73 70 65 63 69 66 69 65 64 20 62 79 20 61 m specified by a
6370: 20 42 45 47 49 4e 20 54 52 41 4e 53 41 43 54 49 BEGIN TRANSACTI
6380: 4f 4e 20 63 6f 6d 6d 61 6e 64 2e 0a 49 66 20 6e ON command..If n
6390: 6f 20 61 6c 67 6f 72 69 74 68 6d 20 69 73 20 73 o algorithm is s
63a0: 70 65 63 69 66 69 65 64 20 61 6e 79 77 68 65 72 pecified anywher
63b0: 65 2c 20 74 68 65 20 41 42 4f 52 54 20 61 6c 67 e, the ABORT alg
63c0: 6f 72 69 74 68 6d 20 69 73 20 75 73 65 64 2e 3c orithm is used.<
63d0: 2f 70 3e 0a 0a 7d 0a 23 20 3c 70 3e 46 6f 72 20 /p>..}.# <p>For
63e0: 61 64 64 69 74 69 6f 6e 61 6c 20 69 6e 66 6f 72 additional infor
63f0: 6d 61 74 69 6f 6e 2c 20 73 65 65 20 0a 23 20 3c mation, see .# <
6400: 61 20 68 72 65 66 3d 22 63 6f 6e 66 6c 69 63 74 a href="conflict
6410: 2e 68 74 6d 6c 22 3e 63 6f 6e 66 6c 69 63 74 2e .html">conflict.
6420: 68 74 6d 6c 3c 2f 61 3e 2e 3c 2f 70 3e 0a 0a 0a html</a>.</p>...
6430: 53 65 63 74 69 6f 6e 20 50 52 41 47 4d 41 20 70 Section PRAGMA p
6440: 72 61 67 6d 61 0a 0a 53 79 6e 74 61 78 20 7b 73 ragma..Syntax {s
6450: 71 6c 2d 73 74 61 74 65 6d 65 6e 74 7d 20 7b 0a ql-statement} {.
6460: 50 52 41 47 4d 41 20 3c 6e 61 6d 65 3e 20 3d 20 PRAGMA <name> =
6470: 3c 76 61 6c 75 65 3e 20 7c 0a 50 52 41 47 4d 41 <value> |.PRAGMA
6480: 20 3c 66 75 6e 63 74 69 6f 6e 3e 28 3c 61 72 67 <function>(<arg
6490: 3e 29 0a 7d 0a 0a 70 75 74 73 20 7b 0a 3c 70 3e >).}..puts {.<p>
64a0: 54 68 65 20 50 52 41 47 4d 41 20 63 6f 6d 6d 61 The PRAGMA comma
64b0: 6e 64 20 69 73 20 75 73 65 64 20 74 6f 20 6d 6f nd is used to mo
64c0: 64 69 66 79 20 74 68 65 20 6f 70 65 72 61 74 69 dify the operati
64d0: 6f 6e 20 6f 66 20 74 68 65 20 53 51 4c 69 74 65 on of the SQLite
64e0: 20 6c 69 62 72 61 72 79 2e 0a 54 68 65 20 70 72 library..The pr
64f0: 61 67 6d 61 20 63 6f 6d 6d 61 6e 64 20 69 73 20 agma command is
6500: 65 78 70 65 72 69 6d 65 6e 74 61 6c 20 61 6e 64 experimental and
6510: 20 73 70 65 63 69 66 69 63 20 70 72 61 67 6d 61 specific pragma
6520: 20 73 74 61 74 65 6d 65 6e 74 73 20 6d 61 79 0a statements may.
6530: 72 65 6d 6f 76 65 64 20 6f 72 20 61 64 64 65 64 removed or added
6540: 20 69 6e 20 66 75 74 75 72 65 20 72 65 6c 65 61 in future relea
6550: 73 65 73 20 6f 66 20 53 51 4c 69 74 65 2e 20 20 ses of SQLite.
6560: 55 73 65 20 74 68 69 73 20 63 6f 6d 6d 61 6e 64 Use this command
6570: 0a 77 69 74 68 20 63 61 75 74 69 6f 6e 2e 3c 2f .with caution.</
6580: 70 3e 0a 0a 3c 70 3e 54 68 65 20 63 75 72 72 65 p>..<p>The curre
6590: 6e 74 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f nt implementatio
65a0: 6e 20 73 75 70 70 6f 72 74 73 20 74 68 65 20 66 n supports the f
65b0: 6f 6c 6c 6f 77 69 6e 67 20 70 72 61 67 6d 61 73 ollowing pragmas
65c0: 3a 3c 2f 70 3e 0a 0a 3c 75 6c 3e 0a 3c 6c 69 3e :</p>..<ul>.<li>
65d0: 3c 70 3e 3c 62 3e 50 52 41 47 4d 41 20 63 61 63 <p><b>PRAGMA cac
65e0: 68 65 5f 73 69 7a 65 20 3d 20 3c 2f 62 3e 3c 69 he_size = </b><i
65f0: 3e 4e 75 6d 62 65 72 2d 6f 66 2d 70 61 67 65 73 >Number-of-pages
6600: 3c 2f 69 3e 3c 62 3e 3b 3c 2f 62 3e 3c 2f 70 3e </i><b>;</b></p>
6610: 0a 20 20 20 20 3c 70 3e 43 68 61 6e 67 65 20 74 . <p>Change t
6620: 68 65 20 6d 61 78 69 6d 75 6d 20 6e 75 6d 62 65 he maximum numbe
6630: 72 20 6f 66 20 64 61 74 61 62 61 73 65 20 64 69 r of database di
6640: 73 6b 20 70 61 67 65 73 20 74 68 61 74 20 53 51 sk pages that SQ
6650: 4c 69 74 65 0a 20 20 20 20 77 69 6c 6c 20 68 6f Lite. will ho
6660: 6c 64 20 69 6e 20 6d 65 6d 6f 72 79 20 61 74 20 ld in memory at
6670: 6f 6e 63 65 2e 20 20 45 61 63 68 20 70 61 67 65 once. Each page
6680: 20 75 73 65 73 20 61 62 6f 75 74 20 31 2e 35 4b uses about 1.5K
6690: 20 6f 66 20 52 41 4d 2e 0a 20 20 20 20 54 68 65 of RAM.. The
66a0: 20 64 65 66 61 75 6c 74 20 63 61 63 68 65 20 73 default cache s
66b0: 69 7a 65 20 69 73 20 31 30 30 2e 20 20 49 66 20 ize is 100. If
66c0: 79 6f 75 20 61 72 65 20 64 6f 69 6e 67 20 55 50 you are doing UP
66d0: 44 41 54 45 73 20 6f 72 20 44 45 4c 45 54 45 73 DATEs or DELETEs
66e0: 0a 20 20 20 20 74 68 61 74 20 63 68 61 6e 67 65 . that change
66f0: 20 6d 61 6e 79 20 72 6f 77 73 20 6f 66 20 61 20 many rows of a
6700: 64 61 74 61 62 61 73 65 20 61 6e 64 20 79 6f 75 database and you
6710: 20 64 6f 20 6e 6f 74 20 6d 69 6e 64 20 69 66 20 do not mind if
6720: 53 51 4c 69 74 65 0a 20 20 20 20 75 73 65 73 20 SQLite. uses
6730: 6d 6f 72 65 20 6d 65 6d 6f 72 79 2c 20 79 6f 75 more memory, you
6740: 20 63 61 6e 20 69 6e 63 72 65 61 73 65 20 74 68 can increase th
6750: 65 20 63 61 63 68 65 20 73 69 7a 65 20 66 6f 72 e cache size for
6760: 20 61 20 70 6f 73 73 69 62 6c 65 20 73 70 65 65 a possible spee
6770: 64 0a 20 20 20 20 69 6d 70 72 6f 76 65 6d 65 6e d. improvemen
6780: 74 2e 3c 2f 70 3e 3c 2f 6c 69 3e 0a 0a 3c 6c 69 t.</p></li>..<li
6790: 3e 3c 70 3e 3c 62 3e 50 52 41 47 4d 41 20 63 6f ><p><b>PRAGMA co
67a0: 75 6e 74 5f 63 68 61 6e 67 65 73 20 3d 20 4f 4e unt_changes = ON
67b0: 3b 0a 20 20 20 20 20 20 20 3c 62 72 3e 50 52 41 ;. <br>PRA
67c0: 47 4d 41 20 63 6f 75 6e 74 5f 63 68 61 6e 67 65 GMA count_change
67d0: 73 20 3d 20 4f 46 46 3b 3c 2f 62 3e 3c 2f 70 3e s = OFF;</b></p>
67e0: 0a 20 20 20 20 3c 70 3e 57 68 65 6e 20 6f 6e 2c . <p>When on,
67f0: 20 74 68 65 20 43 4f 55 4e 54 5f 43 48 41 4e 47 the COUNT_CHANG
6800: 45 53 20 70 72 61 67 6d 61 20 63 61 75 73 65 73 ES pragma causes
6810: 20 74 68 65 20 63 61 6c 6c 62 61 63 6b 20 66 75 the callback fu
6820: 6e 63 74 69 6f 6e 20 74 6f 0a 20 20 20 20 62 65 nction to. be
6830: 20 69 6e 76 6f 6b 65 64 20 6f 6e 63 65 20 66 6f invoked once fo
6840: 72 20 65 61 63 68 20 44 45 4c 45 54 45 2c 20 49 r each DELETE, I
6850: 4e 53 45 52 54 2c 20 6f 72 20 55 50 44 41 54 45 NSERT, or UPDATE
6860: 20 6f 70 65 72 61 74 69 6f 6e 2e 20 20 54 68 65 operation. The
6870: 0a 20 20 20 20 61 72 67 75 6d 65 6e 74 20 69 73 . argument is
6880: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 72 the number of r
6890: 6f 77 73 20 74 68 61 74 20 77 65 72 65 20 63 68 ows that were ch
68a0: 61 6e 67 65 64 2e 3c 2f 70 3e 0a 0a 3c 6c 69 3e anged.</p>..<li>
68b0: 3c 70 3e 3c 62 3e 50 52 41 47 4d 41 20 65 6d 70 <p><b>PRAGMA emp
68c0: 74 79 5f 72 65 73 75 6c 74 5f 63 61 6c 6c 62 61 ty_result_callba
68d0: 63 6b 73 20 3d 20 4f 4e 3b 0a 20 20 20 20 20 20 cks = ON;.
68e0: 20 3c 62 72 3e 50 52 41 47 4d 41 20 65 6d 70 74 <br>PRAGMA empt
68f0: 79 5f 72 65 73 75 6c 74 5f 63 61 6c 6c 62 61 63 y_result_callbac
6900: 6b 73 20 3d 20 4f 46 46 3b 3c 2f 62 3e 3c 2f 70 ks = OFF;</b></p
6910: 3e 0a 20 20 20 20 3c 70 3e 57 68 65 6e 20 6f 6e >. <p>When on
6920: 2c 20 74 68 65 20 45 4d 50 54 59 5f 52 45 53 55 , the EMPTY_RESU
6930: 4c 54 5f 43 41 4c 4c 42 41 43 4b 53 20 70 72 61 LT_CALLBACKS pra
6940: 67 6d 61 20 63 61 75 73 65 73 20 74 68 65 20 63 gma causes the c
6950: 61 6c 6c 62 61 63 6b 0a 20 20 20 20 66 75 6e 63 allback. func
6960: 74 69 6f 6e 20 74 6f 20 62 65 20 69 6e 76 6f 6b tion to be invok
6970: 65 64 20 6f 6e 63 65 20 66 6f 72 20 65 61 63 68 ed once for each
6980: 20 71 75 65 72 79 20 74 68 61 74 20 68 61 73 20 query that has
6990: 61 6e 20 65 6d 70 74 79 20 72 65 73 75 6c 74 0a an empty result.
69a0: 20 20 20 20 73 65 74 2e 20 20 54 68 65 20 74 68 set. The th
69b0: 69 72 64 20 22 3c 62 3e 61 72 67 76 3c 2f 62 3e ird "<b>argv</b>
69c0: 22 20 70 61 72 61 6d 65 74 65 72 20 74 6f 20 74 " parameter to t
69d0: 68 65 20 63 61 6c 6c 62 61 63 6b 20 69 73 20 73 he callback is s
69e0: 65 74 20 74 6f 20 4e 55 4c 4c 0a 20 20 20 20 62 et to NULL. b
69f0: 65 63 61 75 73 65 20 74 68 65 72 65 20 69 73 20 ecause there is
6a00: 6e 6f 20 64 61 74 61 20 74 6f 20 72 65 70 6f 72 no data to repor
6a10: 74 2e 20 20 42 75 74 20 74 68 65 20 73 65 63 6f t. But the seco
6a20: 6e 64 20 22 3c 62 3e 61 72 67 63 3c 2f 62 3e 22 nd "<b>argc</b>"
6a30: 20 61 6e 64 0a 20 20 20 20 66 6f 75 72 74 68 20 and. fourth
6a40: 22 3c 62 3e 63 6f 6c 75 6d 6e 4e 61 6d 65 73 3c "<b>columnNames<
6a50: 2f 62 3e 22 20 70 61 72 61 6d 65 74 65 72 73 20 /b>" parameters
6a60: 61 72 65 20 76 61 6c 69 64 20 61 6e 64 20 63 61 are valid and ca
6a70: 6e 20 62 65 20 75 73 65 64 20 74 6f 0a 20 20 20 n be used to.
6a80: 20 64 65 74 65 72 6d 69 6e 65 20 74 68 65 20 6e determine the n
6a90: 75 6d 62 65 72 20 61 6e 64 20 6e 61 6d 65 73 20 umber and names
6aa0: 6f 66 20 74 68 65 20 63 6f 6c 75 6d 6e 73 20 74 of the columns t
6ab0: 68 61 74 20 77 6f 75 6c 64 20 68 61 76 65 20 62 hat would have b
6ac0: 65 65 6e 20 69 6e 0a 20 20 20 20 74 68 65 20 72 een in. the r
6ad0: 65 73 75 6c 74 20 73 65 74 20 68 61 64 20 74 68 esult set had th
6ae0: 65 20 73 65 74 20 6e 6f 74 20 62 65 65 6e 20 65 e set not been e
6af0: 6d 70 74 79 2e 3c 2f 70 3e 0a 0a 3c 6c 69 3e 3c mpty.</p>..<li><
6b00: 70 3e 3c 62 3e 50 52 41 47 4d 41 20 66 75 6c 6c p><b>PRAGMA full
6b10: 5f 63 6f 6c 75 6d 6e 5f 6e 61 6d 65 73 20 3d 20 _column_names =
6b20: 4f 4e 3b 0a 20 20 20 20 20 20 20 3c 62 72 3e 50 ON;. <br>P
6b30: 52 41 47 4d 41 20 66 75 6c 6c 5f 63 6f 6c 75 6d RAGMA full_colum
6b40: 6e 5f 6e 61 6d 65 73 20 3d 20 4f 46 46 3b 3c 2f n_names = OFF;</
6b50: 62 3e 3c 2f 70 3e 0a 20 20 20 20 3c 70 3e 54 68 b></p>. <p>Th
6b60: 65 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 72 e column names r
6b70: 65 70 6f 72 74 65 64 20 69 6e 20 61 6e 20 53 51 eported in an SQ
6b80: 4c 69 74 65 20 63 61 6c 6c 62 61 63 6b 20 61 72 Lite callback ar
6b90: 65 20 6e 6f 72 6d 61 6c 6c 79 20 6a 75 73 74 0a e normally just.
6ba0: 20 20 20 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 the name of
6bb0: 74 68 65 20 63 6f 6c 75 6d 6e 20 69 74 73 65 6c the column itsel
6bc0: 66 2c 20 65 78 63 65 70 74 20 66 6f 72 20 6a 6f f, except for jo
6bd0: 69 6e 73 20 77 68 65 6e 20 22 54 41 42 4c 45 2e ins when "TABLE.
6be0: 43 4f 4c 55 4d 4e 22 0a 20 20 20 20 69 73 20 75 COLUMN". is u
6bf0: 73 65 64 2e 20 20 42 75 74 20 77 68 65 6e 20 66 sed. But when f
6c00: 75 6c 6c 5f 63 6f 6c 75 6d 6e 5f 6e 61 6d 65 73 ull_column_names
6c10: 20 69 73 20 74 75 72 6e 65 64 20 6f 6e 2c 20 63 is turned on, c
6c20: 6f 6c 75 6d 6e 20 6e 61 6d 65 73 20 61 72 65 0a olumn names are.
6c30: 20 20 20 20 61 6c 77 61 79 73 20 72 65 70 6f 72 always repor
6c40: 74 65 64 20 61 73 20 22 54 41 42 4c 45 2e 43 4f ted as "TABLE.CO
6c50: 4c 55 4d 4e 22 20 65 76 65 6e 20 66 6f 72 20 73 LUMN" even for s
6c60: 69 6d 70 6c 65 20 71 75 65 72 69 65 73 2e 3c 2f imple queries.</
6c70: 70 3e 3c 2f 6c 69 3e 0a 0a 3c 6c 69 3e 3c 70 3e p></li>..<li><p>
6c80: 3c 62 3e 50 52 41 47 4d 41 20 69 6e 64 65 78 5f <b>PRAGMA index_
6c90: 69 6e 66 6f 28 3c 2f 62 3e 3c 69 3e 69 6e 64 65 info(</b><i>inde
6ca0: 78 2d 6e 61 6d 65 3c 2f 69 3e 3c 62 3e 29 3b 3c x-name</i><b>);<
6cb0: 2f 62 3e 3c 2f 70 3e 0a 20 20 20 20 3c 70 3e 46 /b></p>. <p>F
6cc0: 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e 20 74 or each column t
6cd0: 68 61 74 20 74 68 65 20 6e 61 6d 65 64 20 69 6e hat the named in
6ce0: 64 65 78 20 72 65 66 65 72 65 6e 63 65 73 2c 20 dex references,
6cf0: 69 6e 76 6f 6b 65 20 74 68 65 20 0a 20 20 20 20 invoke the .
6d00: 63 61 6c 6c 62 61 63 6b 20 66 75 6e 63 74 69 6f callback functio
6d10: 6e 0a 20 20 20 20 6f 6e 63 65 20 77 69 74 68 20 n. once with
6d20: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 information abou
6d30: 74 20 74 68 61 74 20 63 6f 6c 75 6d 6e 2c 20 69 t that column, i
6d40: 6e 63 6c 75 64 69 6e 67 20 74 68 65 20 63 6f 6c ncluding the col
6d50: 75 6d 6e 20 6e 61 6d 65 2c 0a 20 20 20 20 61 6e umn name,. an
6d60: 64 20 74 68 65 20 63 6f 6c 75 6d 6e 20 6e 75 6d d the column num
6d70: 62 65 72 2e 3c 2f 70 3e 0a 0a 3c 6c 69 3e 3c 70 ber.</p>..<li><p
6d80: 3e 3c 62 3e 50 52 41 47 4d 41 20 69 6e 64 65 78 ><b>PRAGMA index
6d90: 5f 6c 69 73 74 28 3c 2f 62 3e 3c 69 3e 74 61 62 _list(</b><i>tab
6da0: 6c 65 2d 6e 61 6d 65 3c 2f 69 3e 3c 62 3e 29 3b le-name</i><b>);
6db0: 3c 2f 62 3e 3c 2f 70 3e 0a 20 20 20 20 3c 70 3e </b></p>. <p>
6dc0: 46 6f 72 20 65 61 63 68 20 69 6e 64 65 78 20 6f For each index o
6dd0: 6e 20 74 68 65 20 6e 61 6d 65 64 20 74 61 62 6c n the named tabl
6de0: 65 2c 20 69 6e 76 6f 6b 65 20 74 68 65 20 63 61 e, invoke the ca
6df0: 6c 6c 62 61 63 6b 20 66 75 6e 63 74 69 6f 6e 0a llback function.
6e00: 20 20 20 20 6f 6e 63 65 20 77 69 74 68 20 69 6e once with in
6e10: 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 formation about
6e20: 74 68 61 74 20 69 6e 64 65 78 2e 20 20 41 72 67 that index. Arg
6e30: 75 6d 65 6e 74 73 20 69 6e 63 6c 75 64 65 20 74 uments include t
6e40: 68 65 0a 20 20 20 20 69 6e 64 65 78 20 6e 61 6d he. index nam
6e50: 65 20 61 6e 64 20 61 20 66 6c 61 67 20 74 6f 20 e and a flag to
6e60: 69 6e 64 69 63 61 74 65 20 77 68 65 74 68 65 72 indicate whether
6e70: 20 6f 72 20 6e 6f 74 20 74 68 65 20 69 6e 64 65 or not the inde
6e80: 78 20 6d 75 73 74 20 62 65 0a 20 20 20 20 75 6e x must be. un
6e90: 69 71 75 65 2e 3c 2f 70 3e 0a 0a 3c 6c 69 3e 3c ique.</p>..<li><
6ea0: 70 3e 3c 62 3e 50 52 41 47 4d 41 20 70 61 72 73 p><b>PRAGMA pars
6eb0: 65 72 5f 74 72 61 63 65 20 3d 20 4f 4e 3b 3c 62 er_trace = ON;<b
6ec0: 72 3e 50 52 41 47 4d 41 20 70 61 72 73 65 72 5f r>PRAGMA parser_
6ed0: 74 72 61 63 65 20 3d 20 4f 46 46 3b 3c 2f 62 3e trace = OFF;</b>
6ee0: 3c 2f 70 3e 0a 20 20 20 20 3c 70 3e 54 75 72 6e </p>. <p>Turn
6ef0: 20 74 72 61 63 69 6e 67 20 6f 66 20 74 68 65 20 tracing of the
6f00: 53 51 4c 20 70 61 72 73 65 72 20 69 6e 73 69 64 SQL parser insid
6f10: 65 20 6f 66 20 74 68 65 0a 20 20 20 20 53 51 4c e of the. SQL
6f20: 69 74 65 20 6c 69 62 72 61 72 79 20 6f 6e 20 61 ite library on a
6f30: 6e 64 20 6f 66 66 2e 20 20 54 68 69 73 20 69 73 nd off. This is
6f40: 20 75 73 65 64 20 66 6f 72 20 64 65 62 75 67 67 used for debugg
6f50: 69 6e 67 2e 0a 20 20 20 20 54 68 69 73 20 6f 6e ing.. This on
6f60: 6c 79 20 77 6f 72 6b 73 20 69 66 20 74 68 65 20 ly works if the
6f70: 6c 69 62 72 61 72 79 20 69 73 20 63 6f 6d 70 69 library is compi
6f80: 6c 65 64 20 77 69 74 68 6f 75 74 20 74 68 65 20 led without the
6f90: 4e 44 45 42 55 47 20 6d 61 63 72 6f 2e 0a 20 20 NDEBUG macro..
6fa0: 20 20 3c 2f 70 3e 3c 2f 6c 69 3e 0a 0a 3c 6c 69 </p></li>..<li
6fb0: 3e 3c 70 3e 3c 62 3e 50 52 41 47 4d 41 20 73 61 ><p><b>PRAGMA sa
6fc0: 6e 69 74 79 5f 63 68 65 63 6b 3b 3c 2f 62 3e 3c nity_check;</b><
6fd0: 2f 70 3e 0a 20 20 20 20 3c 70 3e 54 68 65 20 63 /p>. <p>The c
6fe0: 6f 6d 6d 61 6e 64 20 64 6f 65 73 20 61 6e 20 69 ommand does an i
6ff0: 6e 74 65 67 72 69 74 79 20 63 68 65 63 6b 20 6f ntegrity check o
7000: 66 20 74 68 65 20 65 6e 74 69 72 65 20 64 61 74 f the entire dat
7010: 61 62 61 73 65 2e 20 20 49 74 0a 20 20 20 20 6c abase. It. l
7020: 6f 6f 6b 73 20 66 6f 72 20 6f 75 74 2d 6f 66 2d ooks for out-of-
7030: 6f 72 64 65 72 20 72 65 63 6f 72 64 73 2c 20 6d order records, m
7040: 69 73 73 69 6e 67 20 70 61 67 65 73 2c 20 61 6e issing pages, an
7050: 64 20 6d 61 6c 66 6f 72 6d 65 64 20 72 65 63 6f d malformed reco
7060: 72 64 73 2e 0a 20 20 20 20 49 66 20 61 6e 79 20 rds.. If any
7070: 70 72 6f 62 6c 65 6d 73 20 61 72 65 20 66 6f 75 problems are fou
7080: 6e 64 2c 20 74 68 65 6e 20 61 20 73 69 6e 67 6c nd, then a singl
7090: 65 20 73 74 72 69 6e 67 20 69 73 20 72 65 74 75 e string is retu
70a0: 72 6e 65 64 20 77 68 69 63 68 20 69 73 0a 20 20 rned which is.
70b0: 20 20 61 20 64 65 73 63 72 69 70 74 69 6f 6e 20 a description
70c0: 6f 66 20 61 6c 6c 20 70 72 6f 62 6c 65 6d 73 2e of all problems.
70d0: 20 20 49 66 20 65 76 65 72 79 74 68 69 6e 67 20 If everything
70e0: 69 73 20 69 6e 20 6f 72 64 65 72 2c 20 22 6f 6b is in order, "ok
70f0: 22 20 69 73 0a 20 20 20 20 72 65 74 75 72 6e 65 " is. returne
7100: 64 2e 20 20 54 68 69 73 20 63 6f 6d 6d 61 6e 64 d. This command
7110: 20 69 73 20 75 73 65 64 20 66 6f 72 20 74 65 73 is used for tes
7120: 74 69 6e 67 20 61 6e 64 20 64 65 62 75 67 67 69 ting and debuggi
7130: 6e 67 20 6f 6e 6c 79 20 61 6e 64 0a 20 20 20 20 ng only and.
7140: 69 73 20 6e 6f 74 20 61 76 61 69 6c 61 62 6c 65 is not available
7150: 20 69 66 20 74 68 65 20 6c 69 62 72 61 72 79 20 if the library
7160: 69 73 20 63 6f 6d 70 69 6c 65 64 20 0a 20 20 20 is compiled .
7170: 20 77 69 74 68 20 74 68 65 20 2d 44 4e 44 45 42 with the -DNDEB
7180: 55 47 3d 31 20 63 6f 6d 70 69 6c 65 72 20 6f 70 UG=1 compiler op
7190: 74 69 6f 6e 2e 3c 2f 70 3e 0a 0a 3c 6c 69 3e 3c tion.</p>..<li><
71a0: 70 3e 3c 62 3e 50 52 41 47 4d 41 20 74 61 62 6c p><b>PRAGMA tabl
71b0: 65 5f 69 6e 66 6f 28 3c 2f 62 3e 3c 69 3e 74 61 e_info(</b><i>ta
71c0: 62 6c 65 2d 6e 61 6d 65 3c 2f 69 3e 3c 62 3e 29 ble-name</i><b>)
71d0: 3b 3c 2f 62 3e 3c 2f 70 3e 0a 20 20 20 20 3c 70 ;</b></p>. <p
71e0: 3e 46 6f 72 20 65 61 63 68 20 63 6f 6c 75 6d 6e >For each column
71f0: 20 69 6e 20 74 68 65 20 6e 61 6d 65 64 20 74 61 in the named ta
7200: 62 6c 65 2c 20 69 6e 76 6f 6b 65 20 74 68 65 20 ble, invoke the
7210: 63 61 6c 6c 62 61 63 6b 20 66 75 6e 63 74 69 6f callback functio
7220: 6e 0a 20 20 20 20 6f 6e 63 65 20 77 69 74 68 20 n. once with
7230: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 information abou
7240: 74 20 74 68 61 74 20 63 6f 6c 75 6d 6e 2c 20 69 t that column, i
7250: 6e 63 6c 75 64 69 6e 67 20 74 68 65 20 63 6f 6c ncluding the col
7260: 75 6d 6e 20 6e 61 6d 65 2c 0a 20 20 20 20 64 61 umn name,. da
7270: 74 61 20 74 79 70 65 2c 20 77 68 65 74 68 65 72 ta type, whether
7280: 20 6f 72 20 6e 6f 74 20 74 68 65 20 63 6f 6c 75 or not the colu
7290: 6d 6e 20 63 61 6e 20 62 65 20 4e 55 4c 4c 2c 20 mn can be NULL,
72a0: 61 6e 64 20 74 68 65 20 64 65 66 61 75 6c 74 0a and the default.
72b0: 20 20 20 20 76 61 6c 75 65 20 66 6f 72 20 74 68 value for th
72c0: 65 20 63 6f 6c 75 6d 6e 2e 3c 2f 70 3e 0a 0a 3c e column.</p>..<
72d0: 6c 69 3e 3c 70 3e 3c 62 3e 50 52 41 47 4d 41 20 li><p><b>PRAGMA
72e0: 76 64 62 65 5f 74 72 61 63 65 20 3d 20 4f 4e 3b vdbe_trace = ON;
72f0: 3c 62 72 3e 50 52 41 47 4d 41 20 76 64 62 65 5f <br>PRAGMA vdbe_
7300: 74 72 61 63 65 20 3d 20 4f 46 46 3b 3c 2f 62 3e trace = OFF;</b>
7310: 3c 2f 70 3e 0a 20 20 20 20 3c 70 3e 54 75 72 6e </p>. <p>Turn
7320: 20 74 72 61 63 69 6e 67 20 6f 66 20 74 68 65 20 tracing of the
7330: 76 69 72 74 75 61 6c 20 64 61 74 61 62 61 73 65 virtual database
7340: 20 65 6e 67 69 6e 65 20 69 6e 73 69 64 65 20 6f engine inside o
7350: 66 20 74 68 65 0a 20 20 20 20 53 51 4c 69 74 65 f the. SQLite
7360: 20 6c 69 62 72 61 72 79 20 6f 6e 20 61 6e 64 20 library on and
7370: 6f 66 66 2e 20 20 54 68 69 73 20 69 73 20 75 73 off. This is us
7380: 65 64 20 66 6f 72 20 64 65 62 75 67 67 69 6e 67 ed for debugging
7390: 2e 3c 2f 70 3e 3c 2f 6c 69 3e 0a 3c 2f 75 6c 3e .</p></li>.</ul>
73a0: 0a 0a 3c 70 3e 4e 6f 20 65 72 72 6f 72 20 6d 65 ..<p>No error me
73b0: 73 73 61 67 65 20 69 73 20 67 65 6e 65 72 61 74 ssage is generat
73c0: 65 64 20 69 66 20 61 6e 20 75 6e 6b 6e 6f 77 6e ed if an unknown
73d0: 20 70 72 61 67 6d 61 20 69 73 20 69 73 73 75 65 pragma is issue
73e0: 64 2e 0a 55 6e 6b 6e 6f 77 6e 20 70 72 61 67 6d d..Unknown pragm
73f0: 61 73 20 61 72 65 20 69 67 6e 6f 72 65 64 2e 3c as are ignored.<
7400: 2f 70 3e 0a 7d 0a 0a 53 65 63 74 69 6f 6e 20 52 /p>.}..Section R
7410: 45 50 4c 41 43 45 20 72 65 70 6c 61 63 65 0a 0a EPLACE replace..
7420: 53 79 6e 74 61 78 20 7b 73 71 6c 2d 73 74 61 74 Syntax {sql-stat
7430: 65 6d 65 6e 74 7d 20 7b 0a 52 45 50 4c 41 43 45 ement} {.REPLACE
7440: 20 49 4e 54 4f 20 3c 74 61 62 6c 65 2d 6e 61 6d INTO <table-nam
7450: 65 3e 20 5b 28 20 3c 63 6f 6c 75 6d 6e 2d 6c 69 e> [( <column-li
7460: 73 74 3e 20 29 5d 20 56 41 4c 55 45 53 20 28 20 st> )] VALUES (
7470: 3c 76 61 6c 75 65 2d 6c 69 73 74 3e 20 29 20 7c <value-list> ) |
7480: 0a 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 3c 74 .REPLACE INTO <t
7490: 61 62 6c 65 2d 6e 61 6d 65 3e 20 5b 28 20 3c 63 able-name> [( <c
74a0: 6f 6c 75 6d 6e 2d 6c 69 73 74 3e 20 29 5d 20 3c olumn-list> )] <
74b0: 73 65 6c 65 63 74 2d 73 74 61 74 65 6d 65 6e 74 select-statement
74c0: 3e 0a 7d 0a 0a 70 75 74 73 20 7b 0a 3c 70 3e 54 >.}..puts {.<p>T
74d0: 68 65 20 52 45 50 4c 41 43 45 20 63 6f 6d 6d 61 he REPLACE comma
74e0: 6e 64 20 69 73 20 61 6e 20 61 6c 69 61 73 20 66 nd is an alias f
74f0: 6f 72 20 74 68 65 20 22 49 4e 53 45 52 54 20 4f or the "INSERT O
7500: 52 20 52 45 50 4c 41 43 45 22 20 76 61 72 69 61 R REPLACE" varia
7510: 6e 74 0a 6f 66 20 74 68 65 20 3c 61 20 68 72 65 nt.of the <a hre
7520: 66 3d 22 23 69 6e 73 65 72 74 22 3e 49 4e 53 45 f="#insert">INSE
7530: 52 54 20 63 6f 6d 6d 61 6e 64 3c 2f 61 3e 2e 20 RT command</a>.
7540: 20 54 68 69 73 20 61 6c 69 61 73 20 69 73 20 70 This alias is p
7550: 72 6f 76 69 64 65 64 20 66 6f 72 0a 63 6f 6d 70 rovided for.comp
7560: 61 74 69 62 69 6c 69 74 79 20 77 69 74 68 20 4d atibility with M
7570: 79 53 51 4c 2e 20 20 53 65 65 20 74 68 65 20 0a ySQL. See the .
7580: 3c 61 20 68 72 65 66 3d 22 23 69 6e 73 65 72 74 <a href="#insert
7590: 22 3e 49 4e 53 45 52 54 20 63 6f 6d 6d 61 6e 64 ">INSERT command
75a0: 3c 2f 61 3e 20 64 6f 63 75 6d 65 6e 74 61 74 69 </a> documentati
75b0: 6f 6e 20 66 6f 72 20 61 64 64 69 74 69 6f 6e 61 on for additiona
75c0: 6c 0a 69 6e 66 6f 72 6d 61 74 69 6f 6e 2e 3c 2f l.information.</
75d0: 70 3e 20 20 0a 7d 0a 0a 53 65 63 74 69 6f 6e 20 p> .}..Section
75e0: 53 45 4c 45 43 54 20 73 65 6c 65 63 74 0a 0a 53 SELECT select..S
75f0: 79 6e 74 61 78 20 7b 73 71 6c 2d 73 74 61 74 65 yntax {sql-state
7600: 6d 65 6e 74 7d 20 7b 0a 53 45 4c 45 43 54 20 3c ment} {.SELECT <
7610: 72 65 73 75 6c 74 3e 20 46 52 4f 4d 20 3c 74 61 result> FROM <ta
7620: 62 6c 65 2d 6c 69 73 74 3e 0a 5b 57 48 45 52 45 ble-list>.[WHERE
7630: 20 3c 65 78 70 72 65 73 73 69 6f 6e 3e 5d 0a 5b <expression>].[
7640: 47 52 4f 55 50 20 42 59 20 3c 65 78 70 72 2d 6c GROUP BY <expr-l
7650: 69 73 74 3e 5d 0a 5b 48 41 56 49 4e 47 20 3c 65 ist>].[HAVING <e
7660: 78 70 72 65 73 73 69 6f 6e 3e 5d 0a 5b 3c 63 6f xpression>].[<co
7670: 6d 70 6f 75 6e 64 2d 6f 70 3e 20 3c 73 65 6c 65 mpound-op> <sele
7680: 63 74 3e 5d 2a 0a 5b 4f 52 44 45 52 20 42 59 20 ct>]*.[ORDER BY
7690: 3c 73 6f 72 74 2d 65 78 70 72 2d 6c 69 73 74 3e <sort-expr-list>
76a0: 5d 0a 5b 4c 49 4d 49 54 20 3c 69 6e 74 65 67 65 ].[LIMIT <intege
76b0: 72 3e 20 5b 4f 46 46 53 45 54 20 3c 69 6e 74 65 r> [OFFSET <inte
76c0: 67 65 72 3e 5d 5d 0a 7d 20 7b 72 65 73 75 6c 74 ger>]].} {result
76d0: 7d 20 7b 0a 3c 72 65 73 75 6c 74 2d 63 6f 6c 75 } {.<result-colu
76e0: 6d 6e 3e 20 5b 2c 20 3c 72 65 73 75 6c 74 2d 63 mn> [, <result-c
76f0: 6f 6c 75 6d 6e 3e 5d 2a 0a 7d 20 7b 72 65 73 75 olumn>]*.} {resu
7700: 6c 74 2d 63 6f 6c 75 6d 6e 7d 20 7b 0a 53 54 41 lt-column} {.STA
7710: 52 20 7c 20 3c 65 78 70 72 65 73 73 69 6f 6e 3e R | <expression>
7720: 20 5b 20 5b 41 53 5d 20 3c 73 74 72 69 6e 67 3e [ [AS] <string>
7730: 20 5d 0a 7d 20 7b 74 61 62 6c 65 2d 6c 69 73 74 ].} {table-list
7740: 7d 20 7b 0a 3c 74 61 62 6c 65 3e 20 5b 2c 20 3c } {.<table> [, <
7750: 74 61 62 6c 65 3e 5d 2a 0a 7d 20 7b 74 61 62 6c table>]*.} {tabl
7760: 65 7d 20 7b 0a 3c 74 61 62 6c 65 2d 6e 61 6d 65 e} {.<table-name
7770: 3e 20 5b 41 53 20 3c 61 6c 69 61 73 3e 5d 20 7c > [AS <alias>] |
7780: 0a 28 20 3c 73 65 6c 65 63 74 3e 20 29 20 5b 41 .( <select> ) [A
7790: 53 20 3c 61 6c 69 61 73 3e 5d 0a 7d 20 7b 73 6f S <alias>].} {so
77a0: 72 74 2d 65 78 70 72 2d 6c 69 73 74 7d 20 7b 0a rt-expr-list} {.
77b0: 3c 65 78 70 72 3e 20 5b 3c 73 6f 72 74 2d 6f 72 <expr> [<sort-or
77c0: 64 65 72 3e 5d 20 5b 2c 20 3c 65 78 70 72 3e 20 der>] [, <expr>
77d0: 5b 3c 73 6f 72 74 2d 6f 72 64 65 72 3e 5d 5d 2a [<sort-order>]]*
77e0: 0a 7d 20 7b 73 6f 72 74 2d 6f 72 64 65 72 7d 20 .} {sort-order}
77f0: 7b 0a 41 53 43 20 7c 20 44 45 53 43 0a 7d 20 7b {.ASC | DESC.} {
7800: 63 6f 6d 70 6f 75 6e 64 5f 6f 70 7d 20 7b 0a 55 compound_op} {.U
7810: 4e 49 4f 4e 20 7c 20 55 4e 49 4f 4e 20 41 4c 4c NION | UNION ALL
7820: 20 7c 20 49 4e 54 45 52 53 45 43 54 20 7c 20 45 | INTERSECT | E
7830: 58 43 45 50 54 0a 7d 0a 0a 70 75 74 73 20 7b 0a XCEPT.}..puts {.
7840: 3c 70 3e 54 68 65 20 53 45 4c 45 43 54 20 73 74 <p>The SELECT st
7850: 61 74 65 6d 65 6e 74 20 69 73 20 75 73 65 64 20 atement is used
7860: 74 6f 20 71 75 65 72 79 20 74 68 65 20 64 61 74 to query the dat
7870: 61 62 61 73 65 2e 20 20 54 68 65 0a 72 65 73 75 abase. The.resu
7880: 6c 74 20 6f 66 20 61 20 53 45 4c 45 43 54 20 69 lt of a SELECT i
7890: 73 20 7a 65 72 6f 20 6f 72 20 6d 6f 72 65 20 72 s zero or more r
78a0: 6f 77 73 20 6f 66 20 64 61 74 61 20 77 68 65 72 ows of data wher
78b0: 65 20 65 61 63 68 20 72 6f 77 0a 68 61 73 20 61 e each row.has a
78c0: 20 66 69 78 65 64 20 6e 75 6d 62 65 72 20 6f 66 fixed number of
78d0: 20 63 6f 6c 75 6d 6e 73 2e 20 20 54 68 65 20 6e columns. The n
78e0: 75 6d 62 65 72 20 6f 66 20 63 6f 6c 75 6d 6e 73 umber of columns
78f0: 20 69 6e 20 74 68 65 0a 72 65 73 75 6c 74 20 69 in the.result i
7900: 73 20 73 70 65 63 69 66 69 65 64 20 62 79 20 74 s specified by t
7910: 68 65 20 65 78 70 72 65 73 73 69 6f 6e 20 6c 69 he expression li
7920: 73 74 20 69 6e 20 62 65 74 77 65 65 6e 20 74 68 st in between th
7930: 65 0a 53 45 4c 45 43 54 20 61 6e 64 20 46 52 4f e.SELECT and FRO
7940: 4d 20 6b 65 79 77 6f 72 64 73 2e 20 20 41 6e 79 M keywords. Any
7950: 20 61 72 62 69 74 72 61 72 79 20 65 78 70 72 65 arbitrary expre
7960: 73 73 69 6f 6e 20 63 61 6e 20 62 65 20 75 73 65 ssion can be use
7970: 64 0a 61 73 20 61 20 72 65 73 75 6c 74 2e 20 20 d.as a result.
7980: 49 66 20 61 20 72 65 73 75 6c 74 20 65 78 70 72 If a result expr
7990: 65 73 73 69 6f 6e 20 69 73 20 7d 0a 70 75 74 73 ession is }.puts
79a0: 20 22 5b 4f 70 65 72 61 74 6f 72 20 2a 5d 20 74 "[Operator *] t
79b0: 68 65 6e 20 61 6c 6c 20 63 6f 6c 75 6d 6e 73 20 hen all columns
79c0: 6f 66 20 61 6c 6c 20 74 61 62 6c 65 73 20 61 72 of all tables ar
79d0: 65 20 73 75 62 73 74 69 74 75 74 65 64 22 0a 70 e substituted".p
79e0: 75 74 73 20 7b 66 6f 72 20 74 68 61 74 20 6f 6e uts {for that on
79f0: 65 20 65 78 70 72 65 73 73 69 6f 6e 2e 3c 2f 70 e expression.</p
7a00: 3e 0a 0a 3c 70 3e 54 68 65 20 71 75 65 72 79 20 >..<p>The query
7a10: 69 73 20 65 78 65 63 75 74 65 64 20 61 67 61 69 is executed agai
7a20: 6e 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 74 61 n one or more ta
7a30: 62 6c 65 73 20 73 70 65 63 69 66 69 65 64 20 61 bles specified a
7a40: 66 74 65 72 0a 74 68 65 20 46 52 4f 4d 20 6b 65 fter.the FROM ke
7a50: 79 77 6f 72 64 2e 20 20 49 66 20 6d 6f 72 65 20 yword. If more
7a60: 74 68 61 6e 20 6f 6e 65 20 74 61 62 6c 65 20 69 than one table i
7a70: 73 20 73 70 65 63 69 66 69 65 64 2c 20 74 68 65 s specified, the
7a80: 6e 20 74 68 65 0a 71 75 65 72 79 20 69 73 20 61 n the.query is a
7a90: 67 61 69 6e 73 74 20 74 68 65 20 28 69 6e 6e 65 gainst the (inne
7aa0: 72 29 20 6a 6f 69 6e 20 6f 66 20 74 68 65 20 76 r) join of the v
7ab0: 61 72 69 6f 75 73 20 74 61 62 6c 65 73 2e 20 20 arious tables.
7ac0: 41 20 73 75 62 2d 71 75 65 72 79 0a 69 6e 20 70 A sub-query.in p
7ad0: 61 72 65 6e 74 68 65 73 65 73 20 6d 61 79 20 62 arentheses may b
7ae0: 65 20 73 75 62 73 74 69 74 75 74 65 64 20 66 6f e substituted fo
7af0: 72 20 61 6e 79 20 74 61 62 6c 65 20 6e 61 6d 65 r any table name
7b00: 20 69 6e 20 74 68 65 20 46 52 4f 4d 20 63 6c 61 in the FROM cla
7b10: 75 73 65 2e 0a 3c 2f 70 3e 0a 0a 3c 70 3e 54 68 use..</p>..<p>Th
7b20: 65 20 57 48 45 52 45 20 63 6c 61 75 73 65 20 63 e WHERE clause c
7b30: 61 6e 20 62 65 20 75 73 65 64 20 74 6f 20 6c 69 an be used to li
7b40: 6d 69 74 20 74 68 65 20 6e 75 6d 62 65 72 20 6f mit the number o
7b50: 66 20 72 6f 77 73 20 6f 76 65 72 0a 77 68 69 63 f rows over.whic
7b60: 68 20 74 68 65 20 71 75 65 72 79 20 6f 70 65 72 h the query oper
7b70: 61 74 65 73 2e 20 20 49 6e 20 74 68 65 20 63 75 ates. In the cu
7b80: 72 72 65 6e 74 20 69 6d 70 6c 65 6d 65 6e 74 61 rrent implementa
7b90: 74 69 6f 6e 2c 0a 69 6e 64 69 63 65 73 20 77 69 tion,.indices wi
7ba0: 6c 6c 20 6f 6e 6c 79 20 62 65 20 75 73 65 64 20 ll only be used
7bb0: 74 6f 0a 6f 70 74 69 6d 69 7a 65 20 74 68 65 20 to.optimize the
7bc0: 71 75 65 72 79 20 69 66 20 57 48 45 52 45 20 65 query if WHERE e
7bd0: 78 70 72 65 73 73 69 6f 6e 20 63 6f 6e 74 61 69 xpression contai
7be0: 6e 73 20 65 71 75 61 6c 69 74 79 20 63 6f 6d 70 ns equality comp
7bf0: 61 72 69 73 6f 6e 73 0a 63 6f 6e 6e 65 63 74 65 arisons.connecte
7c00: 64 20 62 79 20 74 68 65 20 41 4e 44 20 6f 70 65 d by the AND ope
7c10: 72 61 74 6f 72 2e 3c 2f 70 3e 0a 0a 3c 70 3e 54 rator.</p>..<p>T
7c20: 68 65 20 47 52 4f 55 50 20 42 59 20 63 6c 61 75 he GROUP BY clau
7c30: 73 65 73 20 63 61 75 73 65 73 20 6f 6e 65 20 6f ses causes one o
7c40: 72 20 6d 6f 72 65 20 72 6f 77 73 20 6f 66 20 74 r more rows of t
7c50: 68 65 20 72 65 73 75 6c 74 20 74 6f 0a 62 65 20 he result to.be
7c60: 63 6f 6d 62 69 6e 65 64 20 69 6e 74 6f 20 61 20 combined into a
7c70: 73 69 6e 67 6c 65 20 72 6f 77 20 6f 66 20 6f 75 single row of ou
7c80: 74 70 75 74 2e 20 20 54 68 69 73 20 69 73 20 65 tput. This is e
7c90: 73 70 65 63 69 61 6c 6c 79 20 75 73 65 66 75 6c specially useful
7ca0: 0a 77 68 65 6e 20 74 68 65 20 72 65 73 75 6c 74 .when the result
7cb0: 20 63 6f 6e 74 61 69 6e 73 20 61 67 67 72 65 67 contains aggreg
7cc0: 61 74 65 20 66 75 6e 63 74 69 6f 6e 73 2e 20 20 ate functions.
7cd0: 54 68 65 20 65 78 70 72 65 73 73 69 6f 6e 73 20 The expressions
7ce0: 69 6e 0a 74 68 65 20 47 52 4f 55 50 20 42 59 20 in.the GROUP BY
7cf0: 63 6c 61 75 73 65 20 64 6f 20 3c 65 6d 3e 6e 6f clause do <em>no
7d00: 74 3c 2f 65 6d 3e 20 68 61 76 65 20 74 6f 20 62 t</em> have to b
7d10: 65 20 65 78 70 72 65 73 73 69 6f 6e 73 20 74 68 e expressions th
7d20: 61 74 0a 61 70 70 65 61 72 20 69 6e 20 74 68 65 at.appear in the
7d30: 20 72 65 73 75 6c 74 2e 20 20 54 68 65 20 48 41 result. The HA
7d40: 56 49 4e 47 20 63 6c 61 75 73 65 20 69 73 20 73 VING clause is s
7d50: 69 6d 69 6c 61 72 20 74 6f 20 57 48 45 52 45 20 imilar to WHERE
7d60: 65 78 63 65 70 74 0a 74 68 61 74 20 48 41 56 49 except.that HAVI
7d70: 4e 47 20 61 70 70 6c 69 65 73 20 61 66 74 65 72 NG applies after
7d80: 20 67 72 6f 75 70 69 6e 67 20 68 61 73 20 6f 63 grouping has oc
7d90: 63 75 72 72 65 64 2e 20 20 54 68 65 20 48 41 56 curred. The HAV
7da0: 49 4e 47 20 65 78 70 72 65 73 73 69 6f 6e 0a 6d ING expression.m
7db0: 61 79 20 72 65 66 65 72 20 74 6f 20 76 61 6c 75 ay refer to valu
7dc0: 65 73 2c 20 65 76 65 6e 20 61 67 67 72 65 67 61 es, even aggrega
7dd0: 74 65 20 66 75 6e 63 74 69 6f 6e 73 2c 20 74 68 te functions, th
7de0: 61 74 20 61 72 65 20 6e 6f 74 20 69 6e 20 74 68 at are not in th
7df0: 65 20 72 65 73 75 6c 74 2e 3c 2f 70 3e 0a 0a 3c e result.</p>..<
7e00: 70 3e 54 68 65 20 4f 52 44 45 52 20 42 59 20 63 p>The ORDER BY c
7e10: 6c 61 75 73 65 20 63 61 75 73 65 73 20 74 68 65 lause causes the
7e20: 20 6f 75 74 70 75 74 20 72 6f 77 73 20 74 6f 20 output rows to
7e30: 62 65 20 73 6f 72 74 65 64 2e 20 20 0a 54 68 65 be sorted. .The
7e40: 20 61 72 67 75 6d 65 6e 74 20 74 6f 20 4f 52 44 argument to ORD
7e50: 45 52 20 42 59 20 69 73 20 61 20 6c 69 73 74 20 ER BY is a list
7e60: 6f 66 20 65 78 70 72 65 73 73 69 6f 6e 73 20 74 of expressions t
7e70: 68 61 74 20 61 72 65 20 75 73 65 64 20 61 73 20 hat are used as
7e80: 74 68 65 0a 6b 65 79 20 66 6f 72 20 74 68 65 20 the.key for the
7e90: 73 6f 72 74 2e 20 20 54 68 65 20 65 78 70 72 65 sort. The expre
7ea0: 73 73 69 6f 6e 73 20 64 6f 20 6e 6f 74 20 68 61 ssions do not ha
7eb0: 76 65 20 74 6f 20 62 65 20 70 61 72 74 20 6f 66 ve to be part of
7ec0: 20 74 68 65 0a 72 65 73 75 6c 74 20 66 6f 72 20 the.result for
7ed0: 61 20 73 69 6d 70 6c 65 20 53 45 4c 45 43 54 2c a simple SELECT,
7ee0: 20 62 75 74 20 69 6e 20 61 20 63 6f 6d 70 6f 75 but in a compou
7ef0: 6e 64 20 53 45 4c 45 43 54 20 65 61 63 68 20 73 nd SELECT each s
7f00: 6f 72 74 0a 65 78 70 72 65 73 73 69 6f 6e 20 6d ort.expression m
7f10: 75 73 74 20 65 78 61 63 74 6c 79 20 6d 61 74 63 ust exactly matc
7f20: 68 20 6f 6e 65 20 6f 66 20 74 68 65 20 72 65 73 h one of the res
7f30: 75 6c 74 20 63 6f 6c 75 6d 6e 73 2e 20 20 45 61 ult columns. Ea
7f40: 63 68 0a 73 6f 72 74 20 65 78 70 72 65 73 73 69 ch.sort expressi
7f50: 6f 6e 20 6d 61 79 20 62 65 20 6f 70 74 69 6f 6e on may be option
7f60: 61 6c 6c 79 20 66 6f 6c 6c 6f 77 65 64 20 62 79 ally followed by
7f70: 20 41 53 43 20 6f 72 20 44 45 53 43 20 74 6f 20 ASC or DESC to
7f80: 73 70 65 63 69 66 79 0a 74 68 65 20 73 6f 72 74 specify.the sort
7f90: 20 6f 72 64 65 72 2e 3c 2f 70 3e 0a 0a 3c 70 3e order.</p>..<p>
7fa0: 54 68 65 20 4c 49 4d 49 54 20 63 6c 61 75 73 65 The LIMIT clause
7fb0: 20 70 6c 61 63 65 73 20 61 6e 20 75 70 70 65 72 places an upper
7fc0: 20 62 6f 75 6e 64 20 6f 6e 20 74 68 65 20 6e 75 bound on the nu
7fd0: 6d 62 65 72 20 6f 66 20 72 6f 77 73 0a 72 65 74 mber of rows.ret
7fe0: 75 72 6e 65 64 20 69 6e 20 74 68 65 20 72 65 73 urned in the res
7ff0: 75 6c 74 2e 20 20 41 20 4c 49 4d 49 54 20 6f 66 ult. A LIMIT of
8000: 20 30 20 69 6e 64 69 63 61 74 65 73 20 6e 6f 20 0 indicates no
8010: 75 70 70 65 72 20 62 6f 75 6e 64 2e 0a 54 68 65 upper bound..The
8020: 20 6f 70 74 69 6f 6e 61 6c 20 4f 46 46 53 45 54 optional OFFSET
8030: 20 66 6f 6c 6c 6f 77 69 6e 67 20 4c 49 4d 49 54 following LIMIT
8040: 20 73 70 65 63 69 66 69 65 73 20 68 6f 77 20 6d specifies how m
8050: 61 6e 79 0a 72 6f 77 73 20 74 6f 20 73 6b 69 70 any.rows to skip
8060: 20 61 74 20 74 68 65 20 62 65 67 69 6e 6e 69 6e at the beginnin
8070: 67 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 20 g of the result
8080: 73 65 74 2e 3c 2f 70 3e 0a 0a 3c 70 3e 41 20 63 set.</p>..<p>A c
8090: 6f 6d 70 6f 75 6e 64 20 53 45 4c 45 43 54 20 69 ompound SELECT i
80a0: 73 20 66 6f 72 6d 65 64 20 66 72 6f 6d 20 74 77 s formed from tw
80b0: 6f 20 6f 72 20 6d 6f 72 65 20 73 69 6d 70 6c 65 o or more simple
80c0: 20 53 45 4c 45 43 54 73 20 63 6f 6e 6e 65 63 74 SELECTs connect
80d0: 65 64 0a 62 79 20 6f 6e 65 20 6f 66 20 74 68 65 ed.by one of the
80e0: 20 6f 70 65 72 61 74 6f 72 73 20 55 4e 49 4f 4e operators UNION
80f0: 2c 20 55 4e 49 4f 4e 20 41 4c 4c 2c 20 49 4e 54 , UNION ALL, INT
8100: 45 52 53 45 43 54 2c 20 6f 72 20 45 58 43 45 50 ERSECT, or EXCEP
8110: 54 2e 20 20 49 6e 0a 61 20 63 6f 6d 70 6f 75 6e T. In.a compoun
8120: 64 20 53 45 4c 45 43 54 2c 20 61 6c 6c 20 74 68 d SELECT, all th
8130: 65 20 63 6f 6e 73 74 69 74 75 65 6e 74 20 53 45 e constituent SE
8140: 4c 45 43 54 73 20 6d 75 73 74 20 73 70 65 63 69 LECTs must speci
8150: 66 79 20 74 68 65 0a 73 61 6d 65 20 6e 75 6d 62 fy the.same numb
8160: 65 72 20 6f 66 20 72 65 73 75 6c 74 20 63 6f 6c er of result col
8170: 75 6d 6e 73 2e 20 20 54 68 65 72 65 20 6d 61 79 umns. There may
8180: 20 62 65 20 6f 6e 6c 79 20 61 20 73 69 6e 67 6c be only a singl
8190: 65 20 4f 52 44 45 52 20 42 59 0a 63 6c 61 75 73 e ORDER BY.claus
81a0: 65 20 61 74 20 74 68 65 20 65 6e 64 20 6f 66 20 e at the end of
81b0: 74 68 65 20 63 6f 6d 70 6f 75 6e 64 20 53 45 4c the compound SEL
81c0: 45 43 54 2e 20 20 54 68 65 20 55 4e 49 4f 4e 20 ECT. The UNION
81d0: 61 6e 64 20 55 4e 49 4f 4e 20 41 4c 4c 0a 6f 70 and UNION ALL.op
81e0: 65 72 61 74 6f 72 73 20 63 6f 6d 62 69 6e 65 20 erators combine
81f0: 74 68 65 20 72 65 73 75 6c 74 73 20 6f 66 20 74 the results of t
8200: 68 65 20 53 45 4c 45 43 54 73 20 74 6f 20 74 68 he SELECTs to th
8210: 65 20 72 69 67 68 74 20 61 6e 64 20 6c 65 66 74 e right and left
8220: 20 69 6e 74 6f 0a 61 20 73 69 6e 67 6c 65 20 62 into.a single b
8230: 69 67 20 74 61 62 6c 65 2e 20 20 54 68 65 20 64 ig table. The d
8240: 69 66 66 65 72 65 6e 63 65 20 69 73 20 74 68 61 ifference is tha
8250: 74 20 69 6e 20 55 4e 49 4f 4e 20 61 6c 6c 20 72 t in UNION all r
8260: 65 73 75 6c 74 20 72 6f 77 73 0a 61 72 65 20 64 esult rows.are d
8270: 69 73 74 69 6e 63 74 20 77 68 65 72 65 20 69 6e istinct where in
8280: 20 55 4e 49 4f 4e 20 41 4c 4c 20 74 68 65 72 65 UNION ALL there
8290: 20 6d 61 79 20 62 65 20 64 75 70 6c 69 63 61 74 may be duplicat
82a0: 65 73 2e 0a 54 68 65 20 49 4e 54 45 52 53 45 43 es..The INTERSEC
82b0: 54 20 6f 70 65 72 61 74 6f 72 20 74 61 6b 65 73 T operator takes
82c0: 20 74 68 65 20 69 6e 74 65 72 73 65 63 74 69 6f the intersectio
82d0: 6e 20 6f 66 20 74 68 65 20 72 65 73 75 6c 74 73 n of the results
82e0: 20 6f 66 20 74 68 65 0a 6c 65 66 74 20 61 6e 64 of the.left and
82f0: 20 72 69 67 68 74 20 53 45 4c 45 43 54 73 2e 20 right SELECTs.
8300: 20 45 58 43 45 50 54 20 74 61 6b 65 73 20 74 68 EXCEPT takes th
8310: 65 20 72 65 73 75 6c 74 20 6f 66 20 6c 65 66 74 e result of left
8320: 20 53 45 4c 45 43 54 20 61 66 74 65 72 0a 72 65 SELECT after.re
8330: 6d 6f 76 69 6e 67 20 74 68 65 20 72 65 73 75 6c moving the resul
8340: 74 73 20 6f 66 20 74 68 65 20 72 69 67 68 74 20 ts of the right
8350: 53 45 4c 45 43 54 2e 20 20 57 68 65 6e 20 74 68 SELECT. When th
8360: 72 65 65 20 61 72 65 20 6d 6f 72 65 20 53 45 4c ree are more SEL
8370: 45 43 54 73 0a 61 72 65 20 63 6f 6e 6e 65 63 74 ECTs.are connect
8380: 65 64 20 69 6e 74 6f 20 61 20 63 6f 6d 70 6f 75 ed into a compou
8390: 6e 64 2c 20 74 68 65 79 20 67 72 6f 75 70 20 66 nd, they group f
83a0: 72 6f 6d 20 6c 65 66 74 20 74 6f 20 72 69 67 68 rom left to righ
83b0: 74 2e 3c 2f 70 3e 0a 7d 0a 0a 53 65 63 74 69 6f t.</p>.}..Sectio
83c0: 6e 20 55 50 44 41 54 45 20 75 70 64 61 74 65 0a n UPDATE update.
83d0: 0a 53 79 6e 74 61 78 20 7b 73 71 6c 2d 73 74 61 .Syntax {sql-sta
83e0: 74 65 6d 65 6e 74 7d 20 7b 0a 55 50 44 41 54 45 tement} {.UPDATE
83f0: 20 5b 20 4f 52 20 3c 63 6f 6e 66 6c 69 63 74 2d [ OR <conflict-
8400: 61 6c 67 6f 72 69 74 68 6d 3e 20 5d 20 3c 74 61 algorithm> ] <ta
8410: 62 6c 65 2d 6e 61 6d 65 3e 0a 53 45 54 20 3c 61 ble-name>.SET <a
8420: 73 73 69 67 6e 6d 65 6e 74 3e 20 5b 2c 20 3c 61 ssignment> [, <a
8430: 73 73 69 67 6e 6d 65 6e 74 3e 5d 20 0a 5b 57 48 ssignment>] .[WH
8440: 45 52 45 20 3c 65 78 70 72 65 73 73 69 6f 6e 3e ERE <expression>
8450: 5d 0a 7d 20 7b 61 73 73 69 67 6e 6d 65 6e 74 7d ].} {assignment}
8460: 20 7b 0a 3c 63 6f 6c 75 6d 6e 2d 6e 61 6d 65 3e {.<column-name>
8470: 20 3d 20 3c 65 78 70 72 65 73 73 69 6f 6e 3e 0a = <expression>.
8480: 7d 0a 0a 70 75 74 73 20 7b 0a 3c 70 3e 54 68 65 }..puts {.<p>The
8490: 20 55 50 44 41 54 45 20 73 74 61 74 65 6d 65 6e UPDATE statemen
84a0: 74 20 69 73 20 75 73 65 64 20 74 6f 20 63 68 61 t is used to cha
84b0: 6e 67 65 20 74 68 65 20 76 61 6c 75 65 20 6f 66 nge the value of
84c0: 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 0a 73 65 6c columns in .sel
84d0: 65 63 74 65 64 20 72 6f 77 73 20 6f 66 20 61 20 ected rows of a
84e0: 74 61 62 6c 65 2e 20 20 45 61 63 68 20 61 73 73 table. Each ass
84f0: 69 67 6e 6d 65 6e 74 20 69 6e 20 61 6e 20 55 50 ignment in an UP
8500: 44 41 54 45 20 73 70 65 63 69 66 69 65 73 0a 61 DATE specifies.a
8510: 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 20 74 6f 20 column name to
8520: 74 68 65 20 6c 65 66 74 20 6f 66 20 74 68 65 20 the left of the
8530: 65 71 75 61 6c 73 20 73 69 67 6e 20 61 6e 64 20 equals sign and
8540: 61 6e 20 61 72 62 69 74 72 61 72 79 20 65 78 70 an arbitrary exp
8550: 72 65 73 73 69 6f 6e 0a 74 6f 20 74 68 65 20 72 ression.to the r
8560: 69 67 68 74 2e 20 20 54 68 65 20 65 78 70 72 65 ight. The expre
8570: 73 73 69 6f 6e 73 20 6d 61 79 20 75 73 65 20 74 ssions may use t
8580: 68 65 20 76 61 6c 75 65 73 20 6f 66 20 6f 74 68 he values of oth
8590: 65 72 20 63 6f 6c 75 6d 6e 73 2e 0a 41 6c 6c 20 er columns..All
85a0: 65 78 70 72 65 73 73 69 6f 6e 73 20 61 72 65 20 expressions are
85b0: 65 76 61 6c 75 61 74 65 64 20 62 65 66 6f 72 65 evaluated before
85c0: 20 61 6e 79 20 61 73 73 69 67 6e 6d 65 6e 74 73 any assignments
85d0: 20 61 72 65 20 6d 61 64 65 2e 0a 41 20 57 48 45 are made..A WHE
85e0: 52 45 20 63 6c 61 75 73 65 20 63 61 6e 20 62 65 RE clause can be
85f0: 20 75 73 65 64 20 74 6f 20 72 65 73 74 72 69 63 used to restric
8600: 74 20 77 68 69 63 68 20 72 6f 77 73 20 61 72 65 t which rows are
8610: 20 75 70 64 61 74 65 64 2e 3c 2f 70 3e 0a 0a 3c updated.</p>..<
8620: 70 3e 54 68 65 20 6f 70 74 69 6f 6e 61 6c 20 63 p>The optional c
8630: 6f 6e 66 6c 69 63 74 2d 63 6c 61 75 73 65 20 61 onflict-clause a
8640: 6c 6c 6f 77 73 20 74 68 65 20 73 70 65 63 69 66 llows the specif
8650: 69 63 61 74 69 6f 6e 20 6f 66 20 61 6e 20 61 6c ication of an al
8660: 74 65 72 6e 61 74 69 76 65 0a 63 6f 6e 73 74 72 ternative.constr
8670: 61 69 6e 74 20 63 6f 6e 66 6c 69 63 74 20 72 65 aint conflict re
8680: 73 6f 6c 75 74 69 6f 6e 20 61 6c 67 6f 72 69 74 solution algorit
8690: 68 6d 20 74 6f 20 75 73 65 20 64 75 72 69 6e 67 hm to use during
86a0: 20 74 68 69 73 20 6f 6e 65 20 63 6f 6d 6d 61 6e this one comman
86b0: 64 2e 0a 53 65 65 20 74 68 65 20 73 65 63 74 69 d..See the secti
86c0: 6f 6e 20 74 69 74 6c 65 64 0a 3c 61 20 68 72 65 on titled.<a hre
86d0: 66 3d 22 23 63 6f 6e 66 6c 69 63 74 22 3e 4f 4e f="#conflict">ON
86e0: 20 43 4f 4e 46 4c 49 43 54 3c 2f 61 3e 20 66 6f CONFLICT</a> fo
86f0: 72 20 61 64 64 69 74 69 6f 6e 61 6c 20 69 6e 66 r additional inf
8700: 6f 72 6d 61 74 69 6f 6e 2e 3c 2f 70 3e 0a 7d 0a ormation.</p>.}.
8710: 0a 53 65 63 74 69 6f 6e 20 56 41 43 55 55 4d 20 .Section VACUUM
8720: 76 61 63 75 75 6d 0a 0a 53 79 6e 74 61 78 20 7b vacuum..Syntax {
8730: 73 71 6c 2d 73 74 61 74 65 6d 65 6e 74 7d 20 7b sql-statement} {
8740: 0a 56 41 43 55 55 4d 20 5b 3c 69 6e 64 65 78 2d .VACUUM [<index-
8750: 6f 72 2d 74 61 62 6c 65 2d 6e 61 6d 65 3e 5d 0a or-table-name>].
8760: 7d 0a 0a 70 75 74 73 20 7b 0a 3c 70 3e 54 68 65 }..puts {.<p>The
8770: 20 56 41 43 55 55 4d 20 63 6f 6d 6d 61 6e 64 20 VACUUM command
8780: 69 73 20 61 6e 20 53 51 4c 69 74 65 20 65 78 74 is an SQLite ext
8790: 65 6e 73 69 6f 6e 20 6d 6f 64 65 6c 6c 65 64 20 ension modelled
87a0: 61 66 74 65 72 20 61 20 73 69 6d 69 6c 61 72 0a after a similar.
87b0: 63 6f 6d 6d 61 6e 64 20 66 6f 75 6e 64 20 69 6e command found in
87c0: 20 50 6f 73 74 67 72 65 53 51 4c 2e 20 20 49 66 PostgreSQL. If
87d0: 20 56 41 43 55 55 4d 20 69 73 20 69 6e 76 6f 6b VACUUM is invok
87e0: 65 64 20 77 69 74 68 20 74 68 65 20 6e 61 6d 65 ed with the name
87f0: 20 6f 66 20 61 0a 74 61 62 6c 65 20 6f 72 20 69 of a.table or i
8800: 6e 64 65 78 20 74 68 65 6e 20 69 74 20 69 73 20 ndex then it is
8810: 73 75 70 70 6f 73 65 20 74 6f 20 63 6c 65 61 6e suppose to clean
8820: 20 75 70 20 74 68 65 20 6e 61 6d 65 64 20 74 61 up the named ta
8830: 62 6c 65 20 6f 72 20 69 6e 64 65 78 2e 0a 49 6e ble or index..In
8840: 20 76 65 72 73 69 6f 6e 20 31 2e 30 20 6f 66 20 version 1.0 of
8850: 53 51 4c 69 74 65 2c 20 74 68 65 20 56 41 43 55 SQLite, the VACU
8860: 55 4d 20 63 6f 6d 6d 61 6e 64 20 77 6f 75 6c 64 UM command would
8870: 20 69 6e 76 6f 6b 65 20 0a 3c 62 3e 67 64 62 6d invoke .<b>gdbm
8880: 5f 72 65 6f 72 67 61 6e 69 7a 65 28 29 3c 2f 62 _reorganize()</b
8890: 3e 20 74 6f 20 63 6c 65 61 6e 20 75 70 20 74 68 > to clean up th
88a0: 65 20 62 61 63 6b 65 6e 64 20 64 61 74 61 62 61 e backend databa
88b0: 73 65 20 66 69 6c 65 2e 0a 42 65 67 69 6e 6e 69 se file..Beginni
88c0: 6e 67 20 77 69 74 68 20 76 65 72 73 69 6f 6e 20 ng with version
88d0: 32 2e 30 20 6f 66 20 53 51 4c 69 74 65 2c 20 47 2.0 of SQLite, G
88e0: 44 42 4d 20 69 73 20 6e 6f 20 6c 6f 6e 67 65 72 DBM is no longer
88f0: 20 75 73 65 64 20 66 6f 72 0a 74 68 65 20 64 61 used for.the da
8900: 74 61 62 61 73 65 20 62 61 63 6b 65 6e 64 20 61 tabase backend a
8910: 6e 64 20 56 41 43 55 55 4d 20 68 61 73 20 62 65 nd VACUUM has be
8920: 63 6f 6d 65 20 61 20 6e 6f 2d 6f 70 2e 0a 3c 2f come a no-op..</
8930: 70 3e 0a 7d 0a 0a 0a 70 75 74 73 20 7b 0a 3c 70 p>.}...puts {.<p
8940: 3e 3c 68 72 20 2f 3e 3c 2f 70 3e 0a 3c 70 3e 3c ><hr /></p>.<p><
8950: 61 20 68 72 65 66 3d 22 69 6e 64 65 78 2e 68 74 a href="index.ht
8960: 6d 6c 22 3e 3c 69 6d 67 20 73 72 63 3d 22 2f 67 ml"><img src="/g
8970: 6f 62 61 63 6b 2e 6a 70 67 22 20 62 6f 72 64 65 oback.jpg" borde
8980: 72 3d 30 20 2f 3e 0a 42 61 63 6b 20 74 6f 20 74 r=0 />.Back to t
8990: 68 65 20 53 51 4c 69 74 65 20 48 6f 6d 65 20 50 he SQLite Home P
89a0: 61 67 65 3c 2f 61 3e 0a 3c 2f 70 3e 0a 0a 3c 2f age</a>.</p>..</
89b0: 62 6f 64 79 3e 3c 2f 68 74 6d 6c 3e 7d 0a body></html>}.