/usr/share/doc/sqlite-doc/lang.html is in sqlite-doc 2.8.17-7fakesync1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 | <html>
<head>
<title>Query Language Understood By SQLite</title>
</head>
<body bgcolor=white>
<h1 align=center>
SQL As Understood By SQLite
</h1>
<p align=center>
(This page was last modified on 2004/04/23 17:04:45 UTC)
</p>
<p>The SQLite library understands most of the standard SQL
language. But it does <a href="omitted.html">omit some features</a>
while at the same time
adding a few features of its own. This document attempts to
describe percisely what parts of the SQL language SQLite does
and does not support. A list of <a href="#keywords">keywords</a> is
given at the end.</p>
<p>In all of the syntax diagrams that follow, literal text is shown in
bold blue. Non-terminal symbols are shown in italic red. Operators
that are part of the syntactic markup itself are shown in black roman.</p>
<p>This document is just an overview of the SQL syntax implemented
by SQLite. Many low-level productions are omitted. For detailed information
on the language that SQLite understands, refer to the source code and
the grammar file "parse.y".</p>
<p>SQLite implements the follow syntax:</p>
<p><ul>
<li><a href="#attach">ATTACH DATABASE</a></li>
<li><a href="#transaction">BEGIN TRANSACTION</a></li>
<li><a href="#comment">comment</a></li>
<li><a href="#transaction">COMMIT TRANSACTION</a></li>
<li><a href="#copy">COPY</a></li>
<li><a href="#createindex">CREATE INDEX</a></li>
<li><a href="#createtable">CREATE TABLE</a></li>
<li><a href="#createtrigger">CREATE TRIGGER</a></li>
<li><a href="#createview">CREATE VIEW</a></li>
<li><a href="#delete">DELETE</a></li>
<li><a href="#detach">DETACH DATABASE</a></li>
<li><a href="#dropindex">DROP INDEX</a></li>
<li><a href="#droptable">DROP TABLE</a></li>
<li><a href="#droptrigger">DROP TRIGGER</a></li>
<li><a href="#dropview">DROP VIEW</a></li>
<li><a href="#transaction">END TRANSACTION</a></li>
<li><a href="#explain">EXPLAIN</a></li>
<li><a href="#expr">expression</a></li>
<li><a href="#insert">INSERT</a></li>
<li><a href="#conflict">ON CONFLICT clause</a></li>
<li><a href="#pragma">PRAGMA</a></li>
<li><a href="#replace">REPLACE</a></li>
<li><a href="#transaction">ROLLBACK TRANSACTION</a></li>
<li><a href="#select">SELECT</a></li>
<li><a href="#update">UPDATE</a></li>
<li><a href="#vacuum">VACUUM</a></li>
</ul></p>
<p>Details on the implementation of each command are provided in
the sequel.</p>
<hr />
<a name="attach"></a>
<h1>ATTACH DATABASE</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">ATTACH </font></b>[<b><font color="#2c2cf0">DATABASE</font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">database-filename</font></i><b><font color="#2c2cf0"> AS </font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The ATTACH DATABASE statement adds a preexisting database
file to the current database connection. If the filename contains
punctuation characters it must be quoted. The names 'main' and
'temp' refer to the main database and the database used for
temporary tables. These cannot be detached. Attached databases
are removed using the <a href="#detach">DETACH DATABASE</a>
statement.</p>
<p>You can read from and write to an attached database, but you cannot
alter the schema of an attached database. You can only CREATE and
DROP in the original database.</p>
<p>You cannot create a new table with the same name as a table in
an attached database, but you can attach a database which contains
tables whose names are duplicates of tables in the main database. It is
also permissible to attach the same database file multiple times.</p>
<p>Tables in an attached database can be referred to using the syntax
<i>database-name.table-name</i>. If an attached table doesn't have
a duplicate table name in the main database, it doesn't require a
database name prefix. When a database is attached, all of its
tables which don't have duplicate names become the 'default' table
of that name. Any tables of that name attached afterwards require the table
prefix. If the 'default' table of a given name is detached, then
the last table of that name attached becomes the new default.</p>
<p>When there are attached databases, transactions are not atomic.
Transactions continue to be atomic within each individual
database file. But if your machine crashes in the middle
of a COMMIT where you have updated two or more database
files, some of those files might get the changes where others
might not.</p>
<p>There is a compile-time limit of 10 attached database files.</p>
<p>Executing a BEGIN TRANSACTION statement locks all database
files, so this feature cannot (currently) be used to increase
concurrancy.</p>
<hr />
<a name="transaction"></a>
<h1>BEGIN TRANSACTION</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">BEGIN </font></b>[<b><font color="#2c2cf0">TRANSACTION </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">name</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">ON CONFLICT </font></b><i><font color="#ff3434">conflict-algorithm</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
</table>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">END </font></b>[<b><font color="#2c2cf0">TRANSACTION </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">name</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
</table>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">COMMIT </font></b>[<b><font color="#2c2cf0">TRANSACTION </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">name</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
</table>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">ROLLBACK </font></b>[<b><font color="#2c2cf0">TRANSACTION </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">name</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>Beginning in version 2.0, SQLite supports transactions with
rollback and atomic commit. See <a href="#attach">ATTACH</a> for
an exception when there are attached databases.</p>
<p>The optional transaction name is ignored. SQLite currently
doesn't allow nested transactions. Attempting to start a new
transaction inside another is an error.</p>
<p>
No changes can be made to the database except within a transaction.
Any command that changes the database (basically, any SQL command
other than SELECT) will automatically start a transaction if
one is not already in effect. Automatically started transactions
are committed at the conclusion of the command.
</p>
<p>
Transactions can be started manually using the BEGIN
command. Such transactions usually persist until the next
COMMIT or ROLLBACK command. But a transaction will also
ROLLBACK if the database is closed or if an error occurs
and the ROLLBACK conflict resolution algorithm is specified.
See the documention on the <a href="#conflict">ON CONFLICT</a>
clause for additional information about the ROLLBACK
conflict resolution algorithm.
</p>
<p>
The optional ON CONFLICT clause at the end of a BEGIN statement
can be used to changed the default conflict resolution algorithm.
The normal default is ABORT. If an alternative is specified by
the ON CONFLICT clause of a BEGIN, then that alternative is used
as the default for all commands within the transaction. The default
algorithm is overridden by ON CONFLICT clauses on individual
constraints within the CREATE TABLE or CREATE INDEX statements
and by the OR clauses on COPY, INSERT, and UPDATE commands.
</p>
<hr />
<a name="comment"></a>
<h1>comment</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">comment</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">SQL-comment</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">C-comment</font></i><b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">SQL-comment</font></i> ::=</td>
<td><b><font color="#2c2cf0">-- </font></b><i><font color="#ff3434">single-line</font></i><b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">C-comment</font></i> ::=</td>
<td><b><font color="#2c2cf0">/<big>*</big> </font></b><i><font color="#ff3434">multiple-lines</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"><big>*</big>/</font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p> Comments aren't SQL commands, but can occur in SQL queries. They are
treated as whitespace by the parser. They can begin anywhere whitespace
can be found, including inside expressions that span multiple lines.
</p>
<p> SQL comments only extend to the end of the current line.</p>
<p> C comments can span any number of lines. If there is no terminating
delimiter, they extend to the end of the input. This is not treated as
an error. A new SQL statement can begin on a line after a multiline
comment ends. C comments can be embedded anywhere whitespace can occur,
including inside expressions, and in the middle of other SQL statements.
C comments do not nest. SQL comments inside a C comment will be ignored.
</p>
<hr />
<a name="copy"></a>
<h1>COPY</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">COPY </font></b>[<b><font color="#2c2cf0"> OR </font></b><i><font color="#ff3434">conflict-algorithm</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> FROM </font></b><i><font color="#ff3434">filename</font></i><b><font color="#2c2cf0"><br>
</font></b>[<b><font color="#2c2cf0"> USING DELIMITERS </font></b><i><font color="#ff3434">delim</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The COPY command is an extension used to load large amounts of
data into a table. It is modeled after a similar command found
in PostgreSQL. In fact, the SQLite COPY command is specifically
designed to be able to read the output of the PostgreSQL dump
utility <b>pg_dump</b> so that data can be easily transferred from
PostgreSQL into SQLite.</p>
<p>The table-name is the name of an existing table which is to
be filled with data. The filename is a string or identifier that
names a file from which data will be read. The filename can be
the <b>STDIN</b> to read data from standard input.</p>
<p>Each line of the input file is converted into a single record
in the table. Columns are separated by tabs. If a tab occurs as
data within a column, then that tab is preceded by a baskslash "\"
character. A baskslash in the data appears as two backslashes in
a row. The optional USING DELIMITERS clause can specify a delimiter
other than tab.</p>
<p>If a column consists of the character "\N", that column is filled
with the value NULL.</p>
<p>The optional conflict-clause allows the specification of an alternative
constraint conflict resolution algorithm to use for this one command.
See the section titled
<a href="#conflict">ON CONFLICT</a> for additional information.</p>
<p>When the input data source is STDIN, the input can be terminated
by a line that contains only a baskslash and a dot:
"<font color="#2c2cf0"><big>\.</big></font>".</p>
<hr />
<a name="createindex"></a>
<h1>CREATE INDEX</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">CREATE </font></b>[<b><font color="#2c2cf0">UNIQUE</font></b>]<b><font color="#2c2cf0"> INDEX </font></b><i><font color="#ff3434">index-name</font></i><b><font color="#2c2cf0"> <br>
ON </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> <big>(</big> </font></b><i><font color="#ff3434">column-name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"><big>,</big> </font></b><i><font color="#ff3434">column-name</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b><big>*</big><b><font color="#2c2cf0"> <big>)</big><br>
</font></b>[<b><font color="#2c2cf0"> ON CONFLICT </font></b><i><font color="#ff3434">conflict-algorithm</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">column-name</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"> ASC </font></b><big>|</big><b><font color="#2c2cf0"> DESC </font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The CREATE INDEX command consists of the keywords "CREATE INDEX" followed
by the name of the new index, the keyword "ON", the name of a previously
created table that is to be indexed, and a parenthesized list of names of
columns in the table that are used for the index key.
Each column name can be followed by one of the "ASC" or "DESC" keywords
to indicate sort order, but the sort order is ignored in the current
implementation. Sorting is always done in ascending order.</p>
<p>There are no arbitrary limits on the number of indices that can be
attached to a single table, nor on the number of columns in an index.</p>
<p>If the UNIQUE keyword appears between CREATE and INDEX then duplicate
index entries are not allowed. Any attempt to insert a duplicate entry
will result in an error.</p>
<p>The optional conflict-clause allows the specification of an alternative
default constraint conflict resolution algorithm for this index.
This only makes sense if the UNIQUE keyword is used since otherwise
there are not constraints on the index. The default algorithm is
ABORT. If a COPY, INSERT, or UPDATE statement specifies a particular
conflict resolution algorithm, that algorithm is used in place of
the default algorithm specified here.
See the section titled
<a href="#conflict">ON CONFLICT</a> for additional information.</p>
<p>The exact text
of each CREATE INDEX statement is stored in the <b>sqlite_master</b>
or <b>sqlite_temp_master</b> table, depending on whether the table
being indexed is temporary. Everytime the database is opened,
all CREATE INDEX statements
are read from the <b>sqlite_master</b> table and used to regenerate
SQLite's internal representation of the index layout.</p>
<p>Indexes cannot be added on tables in attached databases.
Indexes are removed with the <a href="#dropindex">DROP INDEX</a>
command.</p>
<hr />
<a name="createtable"></a>
<h1>CREATE TABLE</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-command</font></i> ::=</td>
<td><b><font color="#2c2cf0">CREATE </font></b>[<b><font color="#2c2cf0">TEMP </font></b><big>|</big><b><font color="#2c2cf0"> TEMPORARY</font></b>]<b><font color="#2c2cf0"> TABLE </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> <big>(</big><br>
</font></b><i><font color="#ff3434">column-def</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"><big>,</big> </font></b><i><font color="#ff3434">column-def</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b><big>*</big><b><font color="#2c2cf0"><br>
</font></b>[<b><font color="#2c2cf0"><big>,</big> </font></b><i><font color="#ff3434">constraint</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b><big>*</big><b><font color="#2c2cf0"><br>
<big>)</big></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-command</font></i> ::=</td>
<td><b><font color="#2c2cf0">CREATE </font></b>[<b><font color="#2c2cf0">TEMP </font></b><big>|</big><b><font color="#2c2cf0"> TEMPORARY</font></b>]<b><font color="#2c2cf0"> TABLE </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> AS </font></b><i><font color="#ff3434">select-statement</font></i><b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">column-def</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">type</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"></font></b>[<b><font color="#2c2cf0">CONSTRAINT </font></b><i><font color="#ff3434">name</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">column-constraint</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b><big>*</big><b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">type</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">typename</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">typename</font></i><b><font color="#2c2cf0"> <big>(</big> </font></b><i><font color="#ff3434">number</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">typename</font></i><b><font color="#2c2cf0"> <big>(</big> </font></b><i><font color="#ff3434">number</font></i><b><font color="#2c2cf0"> <big>,</big> </font></b><i><font color="#ff3434">number</font></i><b><font color="#2c2cf0"> <big>)</big></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">column-constraint</font></i> ::=</td>
<td><b><font color="#2c2cf0">NOT NULL </font></b>[<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">conflict-clause</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
PRIMARY KEY </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">sort-order</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">conflict-clause</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
UNIQUE </font></b>[<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">conflict-clause</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
CHECK <big>(</big> </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b>[<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">conflict-clause</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
DEFAULT </font></b><i><font color="#ff3434">value</font></i><b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">constraint</font></i> ::=</td>
<td><b><font color="#2c2cf0">PRIMARY KEY <big>(</big> </font></b><i><font color="#ff3434">column-list</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b>[<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">conflict-clause</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
UNIQUE <big>(</big> </font></b><i><font color="#ff3434">column-list</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b>[<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">conflict-clause</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
CHECK <big>(</big> </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b>[<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">conflict-clause</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">conflict-clause</font></i> ::=</td>
<td><b><font color="#2c2cf0">ON CONFLICT </font></b><i><font color="#ff3434">conflict-algorithm</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>A CREATE TABLE statement is basically the keywords "CREATE TABLE"
followed by the name of a new table and a parenthesized list of column
definitions and constraints. The table name can be either an identifier
or a string. Tables names that begin with "<b>sqlite_</b>" are reserved
for use by the engine.</p>
<p>Each column definition is the name of the column followed by the
datatype for that column, then one or more optional column constraints.
SQLite is <a href="datatypes.html">typeless</a>.
The datatype for the column does not restrict what data may be put
in that column.
All information is stored as null-terminated strings.
The UNIQUE constraint causes an index to be created on the specified
columns. This index must contain unique keys.
The DEFAULT constraint
specifies a default value to use when doing an INSERT.
</p>
<p>Specifying a PRIMARY KEY normally just creates a UNIQUE index
on the primary key. However, if primary key is on a single column
that has datatype INTEGER, then that column is used internally
as the actual key of the B-Tree for the table. This means that the column
may only hold unique integer values. (Except for this one case,
SQLite ignores the datatype specification of columns and allows
any kind of data to be put in a column regardless of its declared
datatype.) If a table does not have an INTEGER PRIMARY KEY column,
then the B-Tree key will be a automatically generated integer. The
B-Tree key for a row can always be accessed using one of the
special names "<b>ROWID</b>", "<b>OID</b>", or "<b>_ROWID_</b>".
This is true regardless of whether or not there is an INTEGER
PRIMARY KEY.</p>
<p>If the "TEMP" or "TEMPORARY" keyword occurs in between "CREATE"
and "TABLE" then the table that is created is only visible to the
process that opened the database and is automatically deleted when
the database is closed. Any indices created on a temporary table
are also temporary. Temporary tables and indices are stored in a
separate file distinct from the main database file.</p>
<p>The optional conflict-clause following each constraint
allows the specification of an alternative default
constraint conflict resolution algorithm for that constraint.
The default is abort ABORT. Different constraints within the same
table may have different default conflict resolution algorithms.
If an COPY, INSERT, or UPDATE command specifies a different conflict
resolution algorithm, then that algorithm is used in place of the
default algorithm specified in the CREATE TABLE statement.
See the section titled
<a href="#conflict">ON CONFLICT</a> for additional information.</p>
<p>CHECK constraints are ignored in the current implementation.
Support for CHECK constraints may be added in the future. As of
version 2.3.0, NOT NULL, PRIMARY KEY, and UNIQUE constraints all
work.</p>
<p>There are no arbitrary limits on the number
of columns or on the number of constraints in a table.
The total amount of data in a single row is limited to about
1 megabytes. (This limit can be increased to 16MB by changing
a single #define in the source code and recompiling.)</p>
<p>The CREATE TABLE AS form defines the table to be
the result set of a query. The names of the table columns are
the names of the columns in the result.</p>
<p>The exact text
of each CREATE TABLE statement is stored in the <b>sqlite_master</b>
table. Everytime the database is opened, all CREATE TABLE statements
are read from the <b>sqlite_master</b> table and used to regenerate
SQLite's internal representation of the table layout.
If the original command was a CREATE TABLE AS then then an equivalent
CREATE TABLE statement is synthesized and store in <b>sqlite_master</b>
in place of the original command.
The text of CREATE TEMPORARY TABLE statements are stored in the
<b>sqlite_temp_master</b> table.
</p>
<p>Tables are removed using the <a href="#droptable">DROP TABLE</a>
statement. Non-temporary tables in an attached database cannot be
dropped.</p>
<hr />
<a name="createtrigger"></a>
<h1>CREATE TRIGGER</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">CREATE </font></b>[<b><font color="#2c2cf0">TEMP </font></b><big>|</big><b><font color="#2c2cf0"> TEMPORARY</font></b>]<b><font color="#2c2cf0"> TRIGGER </font></b><i><font color="#ff3434">trigger-name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"> BEFORE </font></b><big>|</big><b><font color="#2c2cf0"> AFTER </font></b>]<b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">database-event</font></i><b><font color="#2c2cf0"> ON </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">trigger-action</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">CREATE </font></b>[<b><font color="#2c2cf0">TEMP </font></b><big>|</big><b><font color="#2c2cf0"> TEMPORARY</font></b>]<b><font color="#2c2cf0"> TRIGGER </font></b><i><font color="#ff3434">trigger-name</font></i><b><font color="#2c2cf0"> INSTEAD OF<br>
</font></b><i><font color="#ff3434">database-event</font></i><b><font color="#2c2cf0"> ON </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">view-name</font></i><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">trigger-action</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">database-event</font></i> ::=</td>
<td><b><font color="#2c2cf0">DELETE </font></b><big>|</big><b><font color="#2c2cf0"> <br>
INSERT </font></b><big>|</big><b><font color="#2c2cf0"> <br>
UPDATE </font></b><big>|</big><b><font color="#2c2cf0"> <br>
UPDATE OF </font></b><i><font color="#ff3434">column-list</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">trigger-action</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b>[<b><font color="#2c2cf0"> FOR EACH ROW </font></b><big>|</big><b><font color="#2c2cf0"> FOR EACH STATEMENT </font></b>]<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"> WHEN </font></b><i><font color="#ff3434">expression</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"> <br>
BEGIN <br>
</font></b><i><font color="#ff3434">trigger-step</font></i><b><font color="#2c2cf0"> ; </font></b>[<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">trigger-step</font></i><b><font color="#2c2cf0"> ; </font></b>]<b><font color="#2c2cf0"></font></b><big>*</big><b><font color="#2c2cf0"><br>
END</font></b></td></tr>
</table>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">trigger-step</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">update-statement</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">insert-statement</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"> <br>
</font></b><i><font color="#ff3434">delete-statement</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">select-statement</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The CREATE TRIGGER statement is used to add triggers to the
database schema. Triggers are database operations (the <i>trigger-action</i>)
that are automatically performed when a specified database event (the
<i>database-event</i>) occurs. </p>
<p>A trigger may be specified to fire whenever a DELETE, INSERT or UPDATE of a
particular database table occurs, or whenever an UPDATE of one or more
specified columns of a table are updated.</p>
<p>At this time SQLite supports only FOR EACH ROW triggers, not FOR EACH
STATEMENT triggers. Hence explicitly specifying FOR EACH ROW is optional. FOR
EACH ROW implies that the SQL statements specified as <i>trigger-steps</i>
may be executed (depending on the WHEN clause) for each database row being
inserted, updated or deleted by the statement causing the trigger to fire.</p>
<p>Both the WHEN clause and the <i>trigger-steps</i> may access elements of
the row being inserted, deleted or updated using references of the form
"NEW.<i>column-name</i>" and "OLD.<i>column-name</i>", where
<i>column-name</i> is the name of a column from the table that the trigger
is associated with. OLD and NEW references may only be used in triggers on
<i>trigger-event</i>s for which they are relevant, as follows:</p>
<table border=0 cellpadding=10>
<tr>
<td valign="top" align="right" width=120><i>INSERT</i></td>
<td valign="top">NEW references are valid</td>
</tr>
<tr>
<td valign="top" align="right" width=120><i>UPDATE</i></td>
<td valign="top">NEW and OLD references are valid</td>
</tr>
<tr>
<td valign="top" align="right" width=120><i>DELETE</i></td>
<td valign="top">OLD references are valid</td>
</tr>
</table>
</p>
<p>If a WHEN clause is supplied, the SQL statements specified as <i>trigger-steps</i> are only executed for rows for which the WHEN clause is true. If no WHEN clause is supplied, the SQL statements are executed for all rows.</p>
<p>The specified <i>trigger-time</i> determines when the <i>trigger-steps</i>
will be executed relative to the insertion, modification or removal of the
associated row.</p>
<p>An ON CONFLICT clause may be specified as part of an UPDATE or INSERT
<i>trigger-step</i>. However if an ON CONFLICT clause is specified as part of
the statement causing the trigger to fire, then this conflict handling
policy is used instead.</p>
<p>Triggers are automatically dropped when the table that they are
associated with is dropped.</p>
<p>Triggers may be created on views, as well as ordinary tables, by specifying
INSTEAD OF in the CREATE TRIGGER statement. If one or more ON INSERT, ON DELETE
or ON UPDATE triggers are defined on a view, then it is not an error to execute
an INSERT, DELETE or UPDATE statement on the view, respectively. Thereafter,
executing an INSERT, DELETE or UPDATE on the view causes the associated
triggers to fire. The real tables underlying the view are not modified
(except possibly explicitly, by a trigger program).</p>
<p><b>Example:</b></p>
<p>Assuming that customer records are stored in the "customers" table, and
that order records are stored in the "orders" table, the following trigger
ensures that all associated orders are redirected when a customer changes
his or her address:</p>
<blockquote><pre>
CREATE TRIGGER update_customer_address UPDATE OF address ON customers
BEGIN
UPDATE orders SET address = new.address WHERE customer_name = old.name;
END;
</pre></blockquote>
<p>With this trigger installed, executing the statement:</p>
<blockquote><pre>
UPDATE customers SET address = '1 Main St.' WHERE name = 'Jack Jones';
</pre></blockquote>
<p>causes the following to be automatically executed:</p>
<blockquote><pre>
UPDATE orders SET address = '1 Main St.' WHERE customer_name = 'Jack Jones';
</pre></blockquote>
<p>Note that currently, triggers may behave oddly when created on tables
with INTEGER PRIMARY KEY fields. If a BEFORE trigger program modifies the
INTEGER PRIMARY KEY field of a row that will be subsequently updated by the
statement that causes the trigger to fire, then the update may not occur.
The workaround is to declare the table with a PRIMARY KEY column instead
of an INTEGER PRIMARY KEY column.</p>
<p>A special SQL function RAISE() may be used within a trigger-program, with the following syntax</p>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">raise-function</font></i> ::=</td>
<td><b><font color="#2c2cf0">RAISE <big>(</big> ABORT<big>,</big> </font></b><i><font color="#ff3434">error-message</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"> <br>
RAISE <big>(</big> FAIL<big>,</big> </font></b><i><font color="#ff3434">error-message</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"> <br>
RAISE <big>(</big> ROLLBACK<big>,</big> </font></b><i><font color="#ff3434">error-message</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"> <br>
RAISE <big>(</big> IGNORE <big>)</big></font></b></td></tr>
</table>
<p>When one of the first three forms is called during trigger-program execution, the specified ON CONFLICT processing is performed (either ABORT, FAIL or
ROLLBACK) and the current query terminates. An error code of SQLITE_CONSTRAINT is returned to the user, along with the specified error message.</p>
<p>When RAISE(IGNORE) is called, the remainder of the current trigger program,
the statement that caused the trigger program to execute and any subsequent
trigger programs that would of been executed are abandoned. No database
changes are rolled back. If the statement that caused the trigger program
to execute is itself part of a trigger program, then that trigger program
resumes execution at the beginning of the next step.
</p>
<p>Triggers are removed using the <a href="#droptrigger">DROP TRIGGER</a>
statement. Non-temporary triggers cannot be added on a table in an
attached database.</p>
<hr />
<a name="createview"></a>
<h1>CREATE VIEW</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-command</font></i> ::=</td>
<td><b><font color="#2c2cf0">CREATE </font></b>[<b><font color="#2c2cf0">TEMP </font></b><big>|</big><b><font color="#2c2cf0"> TEMPORARY</font></b>]<b><font color="#2c2cf0"> VIEW </font></b><i><font color="#ff3434">view-name</font></i><b><font color="#2c2cf0"> AS </font></b><i><font color="#ff3434">select-statement</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The CREATE VIEW command assigns a name to a pre-packaged
<a href="#select">SELECT</a>
statement. Once the view is created, it can be used in the FROM clause
of another SELECT in place of a table name.
</p>
<p>You cannot COPY, DELETE, INSERT or UPDATE a view. Views are read-only
in SQLite. However, in many cases you can use a <a href="#trigger">
TRIGGER</a> on the view to accomplish the same thing. Views are removed
with the <a href="#dropview">DROP VIEW</a>
command. Non-temporary views cannot be created on tables in an attached
database.</p>
<hr />
<a name="delete"></a>
<h1>DELETE</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">DELETE FROM </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">WHERE </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The DELETE command is used to remove records from a table.
The command consists of the "DELETE FROM" keywords followed by
the name of the table from which records are to be removed.
</p>
<p>Without a WHERE clause, all rows of the table are removed.
If a WHERE clause is supplied, then only those rows that match
the expression are removed.</p>
<hr />
<a name="detach"></a>
<h1>DETACH DATABASE</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-command</font></i> ::=</td>
<td><b><font color="#2c2cf0">DETACH </font></b>[<b><font color="#2c2cf0">DATABASE</font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>This statement detaches an additional database connection previously
attached using the <a href="#attach">ATTACH DATABASE</a> statement. It
is possible to have the same database file attached multiple times using
different names, and detaching one connection to a file will leave the
others intact.</p>
<p>This statement will fail if SQLite is in the middle of a transaction.</p>
<hr />
<a name="dropindex"></a>
<h1>DROP INDEX</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-command</font></i> ::=</td>
<td><b><font color="#2c2cf0">DROP INDEX </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">index-name</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The DROP INDEX statement removes an index added with the <a href="#createindex">
CREATE INDEX</a> statement. The index named is completely removed from
the disk. The only way to recover the index is to reenter the
appropriate CREATE INDEX command. Non-temporary indexes on tables in
an attached database cannot be dropped.</p>
<p>The DROP INDEX statement does not reduce the size of the database
file. Empty space in the database is retained for later INSERTs. To
remove free space in the database, use the <a href="#vacuum">VACUUM</a>
command.</p>
<hr />
<a name="droptable"></a>
<h1>DROP TABLE</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-command</font></i> ::=</td>
<td><b><font color="#2c2cf0">DROP TABLE </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The DROP TABLE statement removes a table added with the <a href=
"#createtable">CREATE TABLE</a> statement. The name specified is the
table name. It is completely removed from the database schema and the
disk file. The table can not be recovered. All indices associated
with the table are also deleted. Non-temporary tables in an attached
database cannot be dropped.</p>
<p>The DROP TABLE statement does not reduce the size of the database
file. Empty space in the database is retained for later INSERTs. To
remove free space in the database, use the <a href="#vacuum">VACUUM</a>
command.</p>
<hr />
<a name="droptrigger"></a>
<h1>DROP TRIGGER</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">DROP TRIGGER </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">trigger-name</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The DROP TRIGGER statement removes a trigger created by the
<a href="#createtrigger">CREATE TRIGGER</a> statement. The trigger is
deleted from the database schema. Note that triggers are automatically
dropped when the associated table is dropped. Non-temporary triggers
cannot be dropped on attached tables.</p>
<hr />
<a name="dropview"></a>
<h1>DROP VIEW</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-command</font></i> ::=</td>
<td><b><font color="#2c2cf0">DROP VIEW </font></b><i><font color="#ff3434">view-name</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The DROP VIEW statement removes a view created by the <a href=
"#createview">CREATE VIEW</a> statement. The name specified is the
view name. It is removed from the database schema, but no actual data
in the underlying base tables is modified. Non-temporary views in
attached databases cannot be dropped.</p>
<hr />
<a name="explain"></a>
<h1>EXPLAIN</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">EXPLAIN </font></b><i><font color="#ff3434">sql-statement</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The EXPLAIN command modifier is a non-standard extension. The
idea comes from a similar command found in PostgreSQL, but the operation
is completely different.</p>
<p>If the EXPLAIN keyword appears before any other SQLite SQL command
then instead of actually executing the command, the SQLite library will
report back the sequence of virtual machine instructions it would have
used to execute the command had the EXPLAIN keyword not been present.
For additional information about virtual machine instructions see
the <a href="arch.html">architecture description</a> or the documentation
on <a href="opcode.html">available opcodes</a> for the virtual machine.</p>
<hr />
<a name="expr"></a>
<h1>expression</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">expr</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">binary-op</font></i><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">like-op</font></i><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">unary-op</font></i><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
<big>(</big> </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">column-name</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> <big>.</big> </font></b><i><font color="#ff3434">column-name</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> <big>.</big> </font></b><i><font color="#ff3434">column-name</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">literal-value</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">function-name</font></i><b><font color="#2c2cf0"> <big>(</big> </font></b><i><font color="#ff3434">expr-list</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"> <big>*</big> <big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> ISNULL </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> NOTNULL </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">NOT</font></b>]<b><font color="#2c2cf0"> BETWEEN </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> AND </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">NOT</font></b>]<b><font color="#2c2cf0"> IN <big>(</big> </font></b><i><font color="#ff3434">value-list</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">NOT</font></b>]<b><font color="#2c2cf0"> IN <big>(</big> </font></b><i><font color="#ff3434">select-statement</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"><br>
</font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">NOT</font></b>]<b><font color="#2c2cf0"> IN </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
<big>(</big> </font></b><i><font color="#ff3434">select-statement</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"><br>
CASE </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> </font></b>(<b><font color="#2c2cf0"> WHEN </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> THEN </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b>)+<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">ELSE </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> END</font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">like-op</font></i> ::=</td>
<td><b><font color="#2c2cf0">LIKE </font></b><big>|</big><b><font color="#2c2cf0"> GLOB </font></b><big>|</big><b><font color="#2c2cf0"> NOT LIKE </font></b><big>|</big><b><font color="#2c2cf0"> NOT GLOB</font></b></td></tr>
</table>
<p>This section is different from the others. Most other sections of
this document talks about a particular SQL command. This section does
not talk about a standalone command but about "expressions" which are
subcomponents of most other commands.</p>
<p>SQLite understands the following binary operators, in order from
highest to lowest precedence:</p>
<blockquote><pre>
<font color="#2c2cf0"><big>||
* / %
+ -
<< >> & |
< <= > >=
= == != <> </big>IN
AND
OR</font>
</pre></blockquote>
<p>Supported unary operaters are these:</p>
<blockquote><pre>
<font color="#2c2cf0"><big>- + ! ~</big></font>
</pre></blockquote>
<p>Any SQLite value can be used as part of an expression.
For arithmetic operations, integers are treated as integers.
Strings are first converted to real numbers using <b>atof()</b>.
For comparison operators, numbers compare as numbers and strings
compare using the <b>strcmp()</b> function.
Note that there are two variations of the equals and not equals
operators. Equals can be either
<font color="#2c2cf0"><big>=</big></font> or <font color="#2c2cf0"><big>==</big></font>.
The non-equals operator can be either
<font color="#2c2cf0"><big>!=</big></font> or <font color="#2c2cf0"><big><></big></font>.
The <font color="#2c2cf0"><big>||</big></font> operator is "concatenate" - it joins together
the two strings of its operands.
The operator <font color="#2c2cf0"><big>%</big></font> outputs the remainder of its left
operand modulo its right operand.</p>
<a name="like"></a>
<p>The LIKE operator does a wildcard comparision. The operand
to the right contains the wildcards.
A percent symbol <font color="#2c2cf0"><big>%</big></font> in the right operand
matches any sequence of zero or more characters on the left.
An underscore <font color="#2c2cf0"><big>_</big></font> on the right
matches any single character on the left.
The LIKE operator is
not case sensitive and will match upper case characters on one
side against lower case characters on the other.
(A bug: SQLite only understands upper/lower case for 7-bit Latin
characters. Hence the LIKE operator is case sensitive for
8-bit iso8859 characters or UTF-8 characters. For example,
the expression <b>'a' LIKE 'A'</b> is TRUE but
<b>'æ' LIKE 'Æ'</b> is FALSE.). The infix
LIKE operator is identical the user function <a href="#likeFunc">
like(<i>X</i>,<i>Y</i>)</a>.
</p>
<a name="glob"></a>
<p>The GLOB operator is similar to LIKE but uses the Unix
file globbing syntax for its wildcards. Also, GLOB is case
sensitive, unlike LIKE. Both GLOB and LIKE may be preceded by
the NOT keyword to invert the sense of the test. The infix GLOB
operator is identical the user function <a href="#globFunc">
glob(<i>X</i>,<i>Y</i>)</a>.</p>
<p>A column name can be any of the names defined in the CREATE TABLE
statement or one of the following special identifiers: "<b>ROWID</b>",
"<b>OID</b>", or "<b>_ROWID_</b>".
These special identifiers all describe the
unique random integer key (the "row key") associated with every
row of every table.
The special identifiers only refer to the row key if the CREATE TABLE
statement does not define a real column with the same name. Row keys
act like read-only columns. A row key can be used anywhere a regular
column can be used, except that you cannot change the value
of a row key in an UPDATE or INSERT statement.
"SELECT * ..." does not return the row key.</p>
<p>SELECT statements can appear in expressions as either the
right-hand operand of the IN operator or as a scalar quantity.
In both cases, the SELECT should have only a single column in its
result. Compound SELECTs (connected with keywords like UNION or
EXCEPT) are allowed.
A SELECT in an expression is evaluated once before any other processing
is performed, so none of the expressions within the select itself can
refer to quantities in the containing expression.</p>
<p>When a SELECT is the right operand of the IN operator, the IN
operator returns TRUE if the result of the left operand is any of
the values generated by the select. The IN operator may be preceded
by the NOT keyword to invert the sense of the test.</p>
<p>When a SELECT appears within an expression but is not the right
operand of an IN operator, then the first row of the result of the
SELECT becomes the value used in the expression. If the SELECT yields
more than one result row, all rows after the first are ignored. If
the SELECT yeilds no rows, then the value of the SELECT is NULL.</p>
<p>Both simple and aggregate functions are supported. A simple
function can be used in any expression. Simple functions return
a result immediately based on their inputs. Aggregate functions
may only be used in a SELECT statement. Aggregate functions compute
their result across all rows of the result set.</p>
<p>The functions shown below are available by default. Additional
functions may be written in C and added to the database engine using
the <a href="c_interface.html#cfunc">sqlite_create_function()</a>
API.</p>
<table border=0 cellpadding=10>
<tr>
<td valign="top" align="right" width=120>abs(<i>X</i>)</td>
<td valign="top">Return the absolute value of argument <i>X</i>.</td>
</tr>
<tr>
<td valign="top" align="right">coalesce(<i>X</i>,<i>Y</i>,...)</td>
<td valign="top">Return a copy of the first non-NULL argument. If
all arguments are NULL then NULL is returned. There must be at least
2 arguments.</td>
</tr>
<tr>
<a name="globFunc"></a>
<td valign="top" align="right">glob(<i>X</i>,<i>Y</i>)</td>
<td valign="top">This function is used to implement the
"<b>Y GLOB X</b>" syntax of SQLite. The
<a href="c_interface.html#cfunc">sqlite_create_function()</a>
interface can
be used to override this function and thereby change the operation
of the <a href="#glob">GLOB</a> operator.</td>
</tr>
<tr>
<td valign="top" align="right">ifnull(<i>X</i>,<i>Y</i>)</td>
<td valign="top">Return a copy of the first non-NULL argument. If
both arguments are NULL then NULL is returned. This behaves the same as
<b>coalesce()</b> above.</td>
</tr>
<tr>
<td valign="top" align="right">last_insert_rowid()</td>
<td valign="top">Return the ROWID of the last row insert from this
connection to the database. This is the same value that would be returned
from the <b>sqlite_last_insert_rowid()</b> API function.</td>
</tr>
<tr>
<td valign="top" align="right">length(<i>X</i>)</td>
<td valign="top">Return the string length of <i>X</i> in characters.
If SQLite is configured to support UTF-8, then the number of UTF-8
characters is returned, not the number of bytes.</td>
</tr>
<tr>
<a name="likeFunc"></a>
<td valign="top" align="right">like(<i>X</i>,<i>Y</i>)</td>
<td valign="top">This function is used to implement the
"<b>Y LIKE X</b>" syntax of SQL. The
<a href="c_interface.html#cfunc">sqlite_create_function()</a>
interface can
be used to override this function and thereby change the operation
of the <a href="#like">LIKE</a> operator.</td>
</tr>
<tr>
<td valign="top" align="right">lower(<i>X</i>)</td>
<td valign="top">Return a copy of string <i>X</i> will all characters
converted to lower case. The C library <b>tolower()</b> routine is used
for the conversion, which means that this function might not
work correctly on UTF-8 characters.</td>
</tr>
<tr>
<td valign="top" align="right">max(<i>X</i>,<i>Y</i>,...)</td>
<td valign="top">Return the argument with the maximum value. Arguments
may be strings in addition to numbers. The maximum value is determined
by the usual sort order. Note that <b>max()</b> is a simple function when
it has 2 or more arguments but converts to an aggregate function if given
only a single argument.</td>
</tr>
<tr>
<td valign="top" align="right">min(<i>X</i>,<i>Y</i>,...)</td>
<td valign="top">Return the argument with the minimum value. Arguments
may be strings in addition to numbers. The mminimum value is determined
by the usual sort order. Note that <b>min()</b> is a simple function when
it has 2 or more arguments but converts to an aggregate function if given
only a single argument.</td>
</tr>
<tr>
<td valign="top" align="right">nullif(<i>X</i>,<i>Y</i>)</td>
<td valign="top">Return the first argument if the arguments are different,
otherwise return NULL.</td>
</tr>
<tr>
<td valign="top" align="right">random(*)</td>
<td valign="top">Return a random integer between -2147483648 and
+2147483647.</td>
</tr>
<tr>
<td valign="top" align="right">round(<i>X</i>)<br>round(<i>X</i>,<i>Y</i>)</td>
<td valign="top">Round off the number <i>X</i> to <i>Y</i> digits to the
right of the decimal point. If the <i>Y</i> argument is omitted, 0 is
assumed.</td>
</tr>
<tr>
<td valign="top" align="right">soundex(<i>X</i>)</td>
<td valign="top">Compute the soundex encoding of the string <i>X</i>.
The string "?000" is returned if the argument is NULL.
This function is omitted from SQLite by default.
It is only available the -DSQLITE_SOUNDEX=1 compiler option
is used when SQLite is built.</td>
</tr>
<tr>
<td valign="top" align="right">sqlite_version(*)</td>
<td valign="top">Return the version string for the SQLite library
that is running. Example: "2.8.0"</td>
</tr>
<tr>
<td valign="top" align="right">substr(<i>X</i>,<i>Y</i>,<i>Z</i>)</td>
<td valign="top">Return a substring of input string <i>X</i> that begins
with the <i>Y</i>-th character and which is <i>Z</i> characters long.
The left-most character of <i>X</i> is number 1. If <i>Y</i> is negative
the the first character of the substring is found by counting from the
right rather than the left. If SQLite is configured to support UTF-8,
then characters indices refer to actual UTF-8 characters, not bytes.</td>
</tr>
<tr>
<td valign="top" align="right">typeof(<i>X</i>)</td>
<td valign="top">Return the type of the expression <i>X</i>. The only
return values are "numeric" and "text". SQLite's type handling is
explained in <a href="datatypes.html">Datatypes in SQLite</a>.</td>
</tr>
<tr>
<td valign="top" align="right">upper(<i>X</i>)</td>
<td valign="top">Return a copy of input string <i>X</i> converted to all
upper-case letters. The implementation of this function uses the C library
routine <b>toupper()</b> which means it may not work correctly on
UTF-8 strings.</td>
</tr>
</table>
<p>
The following aggregate functions are available by default. Additional
aggregate functions written in C may be added using the
<a href="c_interface.html#cfunc">sqlite_create_aggregate()</a> API.</p>
<table border=0 cellpadding=10>
<tr>
<td valign="top" align="right" width=120>avg(<i>X</i>)</td>
<td valign="top">Return the average value of all <i>X</i> within a group.</td>
</tr>
<tr>
<td valign="top" align="right">count(<i>X</i>)<br>count(*)</td>
<td valign="top">The first form return a count of the number of times
that <i>X</i> is not NULL in a group. The second form (with no argument)
returns the total number of rows in the group.</td>
</tr>
<tr>
<td valign="top" align="right">max(<i>X</i>)</td>
<td valign="top">Return the maximum value of all values in the group.
The usual sort order is used to determine the maximum.</td>
</tr>
<tr>
<td valign="top" align="right">min(<i>X</i>)</td>
<td valign="top">Return the minimum value of all values in the group.
The usual sort order is used to determine the minimum.</td>
</tr>
<tr>
<td valign="top" align="right">sum(<i>X</i>)</td>
<td valign="top">Return the numeric sum of all values in the group.</td>
</tr>
</table>
<hr />
<a name="insert"></a>
<h1>INSERT</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">INSERT </font></b>[<b><font color="#2c2cf0">OR </font></b><i><font color="#ff3434">conflict-algorithm</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> INTO </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"><big>(</big></font></b><i><font color="#ff3434">column-list</font></i><b><font color="#2c2cf0"><big>)</big></font></b>]<b><font color="#2c2cf0"> VALUES<big>(</big></font></b><i><font color="#ff3434">value-list</font></i><b><font color="#2c2cf0"><big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"><br>
INSERT </font></b>[<b><font color="#2c2cf0">OR </font></b><i><font color="#ff3434">conflict-algorithm</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> INTO </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"><big>(</big></font></b><i><font color="#ff3434">column-list</font></i><b><font color="#2c2cf0"><big>)</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">select-statement</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The INSERT statement comes in two basic forms. The first form
(with the "VALUES" keyword) creates a single new row in an existing table.
If no column-list is specified then the number of values must
be the same as the number of columns in the table. If a column-list
is specified, then the number of values must match the number of
specified columns. Columns of the table that do not appear in the
column list are filled with the default value, or with NULL if not
default value is specified.
</p>
<p>The second form of the INSERT statement takes it data from a
SELECT statement. The number of columns in the result of the
SELECT must exactly match the number of columns in the table if
no column list is specified, or it must match the number of columns
name in the column list. A new entry is made in the table
for every row of the SELECT result. The SELECT may be simple
or compound. If the SELECT statement has an ORDER BY clause,
the ORDER BY is ignored.</p>
<p>The optional conflict-clause allows the specification of an alternative
constraint conflict resolution algorithm to use during this one command.
See the section titled
<a href="#conflict">ON CONFLICT</a> for additional information.
For compatibility with MySQL, the parser allows the use of the
single keyword <a href="#replace">REPLACE</a> as an alias for "INSERT OR REPLACE".
</p>
<hr />
<a name="conflict"></a>
<h1>ON CONFLICT clause</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">conflict-clause</font></i> ::=</td>
<td><b><font color="#2c2cf0">ON CONFLICT </font></b><i><font color="#ff3434">conflict-algorithm</font></i><b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">conflict-algorithm</font></i> ::=</td>
<td><b><font color="#2c2cf0">ROLLBACK </font></b><big>|</big><b><font color="#2c2cf0"> ABORT </font></b><big>|</big><b><font color="#2c2cf0"> FAIL </font></b><big>|</big><b><font color="#2c2cf0"> IGNORE </font></b><big>|</big><b><font color="#2c2cf0"> REPLACE</font></b></td></tr>
</table>
<p>The ON CONFLICT clause is not a separate SQL command. It is a
non-standard clause that can appear in many other SQL commands.
It is given its own section in this document because it is not
part of standard SQL and therefore might not be familiar.</p>
<p>The syntax for the ON CONFLICT clause is as shown above for
the CREATE TABLE, CREATE INDEX, and BEGIN TRANSACTION commands.
For the COPY, INSERT, and UPDATE commands, the keywords
"ON CONFLICT" are replaced by "OR", to make the syntax seem more
natural. But the meaning of the clause is the same either way.</p>
<p>The ON CONFLICT clause specifies an algorithm used to resolve
constraint conflicts. There are five choices: ROLLBACK, ABORT,
FAIL, IGNORE, and REPLACE. The default algorithm is ABORT. This
is what they mean:</p>
<dl>
<dt><b>ROLLBACK</b></dt>
<dd><p>When a constraint violation occurs, an immediate ROLLBACK
occurs, thus ending the current transaction, and the command aborts
with a return code of SQLITE_CONSTRAINT. If no transaction is
active (other than the implied transaction that is created on every
command) then this algorithm works the same as ABORT.</p></dd>
<dt><b>ABORT</b></dt>
<dd><p>When a constraint violation occurs, the command backs out
any prior changes it might have made and aborts with a return code
of SQLITE_CONSTRAINT. But no ROLLBACK is executed so changes
from prior commands within the same transaction
are preserved. This is the default behavior.</p></dd>
<dt><b>FAIL</b></dt>
<dd><p>When a constraint violation occurs, the command aborts with a
return code SQLITE_CONSTRAINT. But any changes to the database that
the command made prior to encountering the constraint violation
are preserved and are not backed out. For example, if an UPDATE
statement encountered a constraint violation on the 100th row that
it attempts to update, then the first 99 row changes are preserved
but changes to rows 100 and beyond never occur.</p></dd>
<dt><b>IGNORE</b></dt>
<dd><p>When a constraint violation occurs, the one row that contains
the constraint violation is not inserted or changed. But the command
continues executing normally. Other rows before and after the row that
contained the constraint violation continue to be inserted or updated
normally. No error is returned.</p></dd>
<dt><b>REPLACE</b></dt>
<dd><p>When a UNIQUE constraint violation occurs, the pre-existing rows
that are causing the constraint violation are removed prior to inserting
or updating the current row. Thus the insert or update always occurs.
The command continues executing normally. No error is returned.
If a NOT NULL constraint violation occurs, the NULL value is replaced
by the default value for that column. If the column has no default
value, then the ABORT algorithm is used.</p>
<p>When this conflict resolution strategy deletes rows in order to
statisfy a constraint, it does not invoke delete triggers on those
rows. But that may change in a future release.</p>
</dd>
</dl>
<p>
The conflict resolution algorithm can be specified in three places,
in order from lowest to highest precedence:
</p>
<ol>
<li><p>
On individual constraints within a CREATE TABLE or CREATE INDEX
statement.
</p></li>
<li><p>
On a BEGIN TRANSACTION command.
</p></li>
<li><p>
In the OR clause of a COPY, INSERT, or UPDATE command.
</p></li>
</ol>
<p>The algorithm specified in the OR clause of a COPY, INSERT, or UPDATE
overrides any algorithm specified on the BEGIN TRANSACTION command and
the algorithm specified on the BEGIN TRANSACTION command overrides the
algorithm specified in the a CREATE TABLE or CREATE INDEX.
If no algorithm is specified anywhere, the ABORT algorithm is used.</p>
<hr />
<a name="pragma"></a>
<h1>PRAGMA</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">PRAGMA </font></b><i><font color="#ff3434">name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">= </font></b><i><font color="#ff3434">value</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
PRAGMA </font></b><i><font color="#ff3434">function</font></i><b><font color="#2c2cf0"><big>(</big></font></b><i><font color="#ff3434">arg</font></i><b><font color="#2c2cf0"><big>)</big></font></b></td></tr>
</table>
<p>The PRAGMA command is used to modify the operation of the SQLite library.
The pragma command is experimental and specific pragma statements may be
removed or added in future releases of SQLite. Use this command
with caution.</p>
<p>The pragmas that take an integer <b><i>value</i></b> also accept
symbolic names. The strings "<b>on</b>", "<b>true</b>", and "<b>yes</b>"
are equivalent to <b>1</b>. The strings "<b>off</b>", "<b>false</b>",
and "<b>no</b>" are equivalent to <b>0</b>. These strings are case-
insensitive, and do not require quotes. An unrecognized string will be
treated as <b>1</b>, and will not generate an error. When the <i>value</i>
is returned it is as an integer.</p>
<p>The current implementation supports the following pragmas:</p>
<ul>
<a name="pragma_cache_size"></a>
<li><p><b>PRAGMA cache_size;
<br>PRAGMA cache_size = </b><i>Number-of-pages</i><b>;</b></p>
<p>Query or change the maximum number of database disk pages that SQLite
will hold in memory at once. Each page uses about 1.5K of memory.
The default cache size is 2000. If you are doing UPDATEs or DELETEs
that change many rows of a database and you do not mind if SQLite
uses more memory, you can increase the cache size for a possible speed
improvement.</p>
<p>When you change the cache size using the cache_size pragma, the
change only endures for the current session. The cache size reverts
to the default value when the database is closed and reopened. Use
the <a href="#pragma_default_cache_size"><b>default_cache_size</b></a>
pragma to check the cache size permanently.</p></li>
<li><p><b>PRAGMA count_changes = ON; </b>(1)<b>
<br>PRAGMA count_changes = OFF;</b> (0)</p>
<p>When on, the COUNT_CHANGES pragma causes the callback function to
be invoked once for each DELETE, INSERT, or UPDATE operation. The
argument is the number of rows that were changed.</p>
<p>This pragma may be removed from future versions of SQLite.
Consider using the <b>sqlite_changes()</b> API function instead.</p></li>
<li><p><b>PRAGMA database_list;</b></p>
<p>For each open database, invoke the callback function once with
information about that database. Arguments include the index and
the name the datbase was attached with. The first row will be for
the main database. The second row will be for the database used to
store temporary tables.</p></li>
<a name="pragma_default_cache_size"></a>
<li><p><b>PRAGMA default_cache_size;
<br>PRAGMA default_cache_size = </b><i>Number-of-pages</i><b>;</b></p>
<p>Query or change the maximum number of database disk pages that SQLite
will hold in memory at once. Each page uses 1K on disk and about 1.5K in memory.
This pragma works like the <a href="#pragma_cache_size"><b>cache_size</b></a>
pragma with the additional
feature that it changes the cache size persistently. With this pragma,
you can set the cache size once and that setting is retained and reused
everytime you reopen the database.</p></li>
<a name="pragma_default_synchronous"></a>
<li><p><b>PRAGMA default_synchronous;
<br>PRAGMA default_synchronous = FULL; </b>(2)<b>
<br>PRAGMA default_synchronous = NORMAL; </b>(1)<b>
<br>PRAGMA default_synchronous = OFF; </b>(0)</p>
<p>Query or change the setting of the "synchronous" flag in
the database. The first (query) form will return the setting as an
integer. When synchronous is FULL (2), the SQLite database engine will
pause at critical moments to make sure that data has actually been
written to the disk surface before continuing. This ensures that if
the operating system crashes or if there is a power failure, the database
will be uncorrupted after rebooting. FULL synchronous is very
safe, but it is also slow.
When synchronous is NORMAL (1, the default), the SQLite database
engine will still pause at the most critical moments, but less often
than in FULL mode. There is a very small (though non-zero) chance that
a power failure at just the wrong time could corrupt the database in
NORMAL mode. But in practice, you are more likely to suffer
a catastrophic disk failure or some other unrecoverable hardware
fault. So NORMAL is the default mode.
With synchronous OFF (0), SQLite continues without pausing
as soon as it has handed data off to the operating system.
If the application running SQLite crashes, the data will be safe, but
the database might become corrupted if the operating system
crashes or the computer loses power before that data has been written
to the disk surface. On the other hand, some
operations are as much as 50 or more times faster with synchronous OFF.
</p>
<p>This pragma changes the synchronous mode persistently. Once changed,
the mode stays as set even if the database is closed and reopened. The
<a href="#pragma_synchronous"><b>synchronous</b></a> pragma does the same
thing but only applies the setting to the current session.</p></li>
<a name="pragma_default_temp_store"></a>
<li><p><b>PRAGMA default_temp_store;
<br>PRAGMA default_temp_store = DEFAULT; </b>(0)<b>
<br>PRAGMA default_temp_store = MEMORY; </b>(2)<b>
<br>PRAGMA default_temp_store = FILE;</b> (1)</p>
<p>Query or change the setting of the "<b>temp_store</b>" flag stored in
the database. When temp_store is DEFAULT (0), the compile-time value
of the symbol TEMP_STORE is used for the temporary database.
When temp_store is MEMORY (2), an in-memory database is used.
When temp_store is FILE (1), a temporary database file on disk will be used.
It is possible for the library compile-time symbol TEMP_STORE to override
this setting. The following table summarizes this:</p>
<table cellpadding="2">
<tr><th>TEMP_STORE</th><th>temp_store</th><th>temp database location</th></tr>
<tr><td align="center">0</td><td align="center"><em>any</em></td><td align="center">file</td></tr>
<tr><td align="center">1</td><td align="center">0</td><td align="center">file</td></tr>
<tr><td align="center">1</td><td align="center">1</td><td align="center">file</td></tr>
<tr><td align="center">1</td><td align="center">2</td><td align="center">memory</td></tr>
<tr><td align="center">2</td><td align="center">0</td><td align="center">memory</td></tr>
<tr><td align="center">2</td><td align="center">1</td><td align="center">file</td></tr>
<tr><td align="center">2</td><td align="center">2</td><td align="center">memory</td></tr>
<tr><td align="center">3</td><td align="center"><em>any</em></td><td align="center">memory</td></tr>
</table>
<p>This pragma changes the temp_store mode for whenever the database
is opened in the future. The temp_store mode for the current session
is unchanged. Use the
<a href="#pragma_temp_store"><b>temp_store</b></a> pragma to change the
temp_store mode for the current session.</p></li>
<a name="pragma_empty_result_callbacks"></a>
<li><p><b>PRAGMA empty_result_callbacks = ON; </b>(1)<b>
<br>PRAGMA empty_result_callbacks = OFF;</b> (0)</p>
<p>When on, the EMPTY_RESULT_CALLBACKS pragma causes the callback
function to be invoked once for each query that has an empty result
set. The third "<b>argv</b>" parameter to the callback is set to NULL
because there is no data to report. But the second "<b>argc</b>" and
fourth "<b>columnNames</b>" parameters are valid and can be used to
determine the number and names of the columns that would have been in
the result set had the set not been empty.</p></li>
<li><p><b>PRAGMA foreign_key_list(</b><i>table-name</i><b>);</b></p>
<p>For each foreign key that references a column in the argument
table, invoke the callback function with information about that
foreign key. The callback function will be invoked once for each
column in each foreign key.</p></li>
<li><p><b>PRAGMA full_column_names = ON; </b>(1)<b>
<br>PRAGMA full_column_names = OFF;</b> (0)</p>
<p>The column names reported in an SQLite callback are normally just
the name of the column itself, except for joins when "TABLE.COLUMN"
is used. But when full_column_names is turned on, column names are
always reported as "TABLE.COLUMN" even for simple queries.</p></li>
<li><p><b>PRAGMA index_info(</b><i>index-name</i><b>);</b></p>
<p>For each column that the named index references, invoke the
callback function
once with information about that column, including the column name,
and the column number.</p></li>
<li><p><b>PRAGMA index_list(</b><i>table-name</i><b>);</b></p>
<p>For each index on the named table, invoke the callback function
once with information about that index. Arguments include the
index name and a flag to indicate whether or not the index must be
unique.</p></li>
<li><p><b>PRAGMA integrity_check;</b></p>
<p>The command does an integrity check of the entire database. It
looks for out-of-order records, missing pages, malformed records, and
corrupt indices.
If any problems are found, then a single string is returned which is
a description of all problems. If everything is in order, "ok" is
returned.</p></li>
<li><p><b>PRAGMA parser_trace = ON; </b>(1)<b>
<br>PRAGMA parser_trace = OFF;</b> (0)</p>
<p>Turn tracing of the SQL parser inside of the
SQLite library on and off. This is used for debugging.
This only works if the library is compiled without the NDEBUG macro.
</p></li>
<a name="pragma_show_datatypes"></a>
<li><p><b>PRAGMA show_datatypes = ON; </b>(1)<b>
<br>PRAGMA show_datatypes = OFF;</b> (0)</p>
<p>When turned on, the SHOW_DATATYPES pragma causes extra entries containing
the names of <a href="datatypes.html">datatypes</a> of columns to be
appended to the 4th ("columnNames") argument to <b>sqlite_exec()</b>
callbacks. When
turned off, the 4th argument to callbacks contains only the column names.
The datatype for table columns is taken from the CREATE TABLE statement
that defines the table. Columns with an unspecified datatype have a
datatype of "NUMERIC" and the results of expression have a datatype of
either "TEXT" or "NUMERIC" depending on the expression.
The following chart illustrates the difference for the query
"SELECT 'xyzzy', 5, NULL AS empty ":</p>
<blockquote><table border=0>
<tr><th>show_datatypes=OFF</th><th width=30></th>
<th>show_datatypes=ON</th></tr>
<tr><td valign="top">
azCol[0] = "xyzzy";<br>
azCol[1] = "5";<br>
azCol[2] = "empty";<br>
azCol[3] = 0;
</td><td></td><td valign="top">
azCol[0] = "xyzzy";<br>
azCol[1] = "5";<br>
azCol[2] = "empty";<br>
azCol[3] = "TEXT";<br>
azCol[4] = "NUMERIC";<br>
azCol[5] = "TEXT";<br>
azCol[6] = 0;
</td></table></blockquote></li>
<a name="pragma_synchronous"></a>
<li><p><b>PRAGMA synchronous;
<br>PRAGMA synchronous = FULL; </b>(2)<b>
<br>PRAGMA synchronous = NORMAL; </b>(1)<b>
<br>PRAGMA synchronous = OFF;</b> (0)</p>
<p>Query or change the setting of the "synchronous" flag affecting
the database for the duration of the current database connection.
The synchronous flag reverts to its default value when the database
is closed and reopened. For additional information on the synchronous
flag, see the description of the <a href="#pragma_default_synchronous">
<b>default_synchronous</b></a> pragma.</p>
</li>
<li><p><b>PRAGMA table_info(</b><i>table-name</i><b>);</b></p>
<p>For each column in the named table, invoke the callback function
once with information about that column, including the column name,
data type, whether or not the column can be NULL, and the default
value for the column.</p></li>
<a name="pragma_temp_store"></a>
<li><p><b>PRAGMA temp_store;
<br>PRAGMA temp_store = DEFAULT; </b>(0)<b>
<br>PRAGMA temp_store = MEMORY; </b>(2)<b>
<br>PRAGMA temp_store = FILE;</b> (1)</p>
<p>Query or change the setting of the "temp_store" flag affecting
the database for the duration of the current database connection.
The temp_store flag reverts to its default value when the database
is closed and reopened. For additional information on the temp_store
flag, see the description of the <a href="#pragma_default_temp_store">
<b>default_temp_store</b></a> pragma. Note that it is possible for
the library compile-time options to override this setting. </p>
<p>When the temp_store setting is changed, all existing temporary
tables, indices, triggers, and viewers are immediately deleted.
</p>
</li>
<a name="pragma_vdbe_trace"></a>
<li><p><b>PRAGMA vdbe_trace = ON; </b>(1)<b>
<br>PRAGMA vdbe_trace = OFF;</b> (0)</p>
<p>Turn tracing of the virtual database engine inside of the
SQLite library on and off. This is used for debugging. See the
<a href="vdbe.html#trace">VDBE documentation</a> for more
information.</p></li>
</ul>
<p>No error message is generated if an unknown pragma is issued.
Unknown pragmas are ignored.</p>
<hr />
<a name="replace"></a>
<h1>REPLACE</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">REPLACE INTO </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"><big>(</big> </font></b><i><font color="#ff3434">column-list</font></i><b><font color="#2c2cf0"> <big>)</big></font></b>]<b><font color="#2c2cf0"> VALUES <big>(</big> </font></b><i><font color="#ff3434">value-list</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b><big>|</big><b><font color="#2c2cf0"><br>
REPLACE INTO </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"><big>(</big> </font></b><i><font color="#ff3434">column-list</font></i><b><font color="#2c2cf0"> <big>)</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">select-statement</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The REPLACE command is an alias for the "INSERT OR REPLACE" variant
of the <a href="#insert">INSERT</a> command. This alias is provided for
compatibility with MySQL. See the
<a href="#insert">INSERT</a> command documentation for additional
information.</p>
<hr />
<a name="select"></a>
<h1>SELECT</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">SELECT </font></b>[<b><font color="#2c2cf0">ALL </font></b><big>|</big><b><font color="#2c2cf0"> DISTINCT</font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">result</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">FROM </font></b><i><font color="#ff3434">table-list</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"><br>
</font></b>[<b><font color="#2c2cf0">WHERE </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"><br>
</font></b>[<b><font color="#2c2cf0">GROUP BY </font></b><i><font color="#ff3434">expr-list</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"><br>
</font></b>[<b><font color="#2c2cf0">HAVING </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"><br>
</font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">compound-op</font></i><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">select</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b><big>*</big><b><font color="#2c2cf0"><br>
</font></b>[<b><font color="#2c2cf0">ORDER BY </font></b><i><font color="#ff3434">sort-expr-list</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"><br>
</font></b>[<b><font color="#2c2cf0">LIMIT </font></b><i><font color="#ff3434">integer</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"></font></b>(<b><font color="#2c2cf0"> OFFSET </font></b><big>|</big><b><font color="#2c2cf0"> <big>,</big> </font></b>)<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">integer</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">result</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">result-column</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"><big>,</big> </font></b><i><font color="#ff3434">result-column</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b><big>*</big><b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">result-column</font></i> ::=</td>
<td><b><font color="#2c2cf0"><big>*</big> </font></b><big>|</big><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> <big>.</big> <big>*</big> </font></b><big>|</big><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">AS</font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">string</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">table-list</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">table</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">join-op</font></i><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table</font></i><b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">join-args</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b><big>*</big><b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">table</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">AS </font></b><i><font color="#ff3434">alias</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> </font></b><big>|</big><b><font color="#2c2cf0"><br>
<big>(</big> </font></b><i><font color="#ff3434">select</font></i><b><font color="#2c2cf0"> <big>)</big> </font></b>[<b><font color="#2c2cf0">AS </font></b><i><font color="#ff3434">alias</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">join-op</font></i> ::=</td>
<td><b><font color="#2c2cf0"><big>,</big> </font></b><big>|</big><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">NATURAL</font></b>]<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">LEFT </font></b><big>|</big><b><font color="#2c2cf0"> RIGHT </font></b><big>|</big><b><font color="#2c2cf0"> FULL</font></b>]<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">OUTER </font></b><big>|</big><b><font color="#2c2cf0"> INNER </font></b><big>|</big><b><font color="#2c2cf0"> CROSS</font></b>]<b><font color="#2c2cf0"> JOIN</font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">join-args</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b>[<b><font color="#2c2cf0">ON </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0">USING <big>(</big> </font></b><i><font color="#ff3434">id-list</font></i><b><font color="#2c2cf0"> <big>)</big></font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">sort-expr-list</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">sort-order</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"><big>,</big> </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">sort-order</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b><big>*</big><b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">sort-order</font></i> ::=</td>
<td><b><font color="#2c2cf0">ASC </font></b><big>|</big><b><font color="#2c2cf0"> DESC</font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">compound_op</font></i> ::=</td>
<td><b><font color="#2c2cf0">UNION </font></b><big>|</big><b><font color="#2c2cf0"> UNION ALL </font></b><big>|</big><b><font color="#2c2cf0"> INTERSECT </font></b><big>|</big><b><font color="#2c2cf0"> EXCEPT</font></b></td></tr>
</table>
<p>The SELECT statement is used to query the database. The
result of a SELECT is zero or more rows of data where each row
has a fixed number of columns. The number of columns in the
result is specified by the expression list in between the
SELECT and FROM keywords. Any arbitrary expression can be used
as a result. If a result expression is
<font color="#2c2cf0"><big>*</big></font> then all columns of all tables are substituted
for that one expression. If the expression is the name of
a table followed by <font color="#2c2cf0"><big>.*</big></font> then the result is all columns
in that one table.</p>
<p>The DISTINCT keyword causes a subset of result rows to be returned,
in which each result row is different. NULL values are not treated as
distinct from eachother. The default behavior is that all result rows
be returned, which can be made explicit with the keyword ALL.</p>
<p>The query is executed against one or more tables specified after
the FROM keyword. If multiple tables names are separated by commas,
then the query is against the cross join of the various tables.
The full SQL-92 join syntax can also be used to specify joins.
A sub-query
in parentheses may be substituted for any table name in the FROM clause.
The entire FROM clause may be omitted, in which case the result is a
single row consisting of the values of the expression list.
</p>
<p>The WHERE clause can be used to limit the number of rows over
which the query operates.</p>
<p>The GROUP BY clauses causes one or more rows of the result to
be combined into a single row of output. This is especially useful
when the result contains aggregate functions. The expressions in
the GROUP BY clause do <em>not</em> have to be expressions that
appear in the result. The HAVING clause is similar to WHERE except
that HAVING applies after grouping has occurred. The HAVING expression
may refer to values, even aggregate functions, that are not in the result.</p>
<p>The ORDER BY clause causes the output rows to be sorted.
The argument to ORDER BY is a list of expressions that are used as the
key for the sort. The expressions do not have to be part of the
result for a simple SELECT, but in a compound SELECT each sort
expression must exactly match one of the result columns. Each
sort expression may be optionally followed by ASC or DESC to specify
the sort order.</p>
<p>The LIMIT clause places an upper bound on the number of rows
returned in the result. A negative LIMIT indicates no upper bound.
The optional OFFSET following LIMIT specifies how many
rows to skip at the beginning of the result set.
In a compound query, the LIMIT clause may only appear on the
final SELECT statement.
The limit is applied to the entire query not
to the individual SELECT statement to which it is attached.
</p>
<p>A compound SELECT is formed from two or more simple SELECTs connected
by one of the operators UNION, UNION ALL, INTERSECT, or EXCEPT. In
a compound SELECT, all the constituent SELECTs must specify the
same number of result columns. There may be only a single ORDER BY
clause at the end of the compound SELECT. The UNION and UNION ALL
operators combine the results of the SELECTs to the right and left into
a single big table. The difference is that in UNION all result rows
are distinct where in UNION ALL there may be duplicates.
The INTERSECT operator takes the intersection of the results of the
left and right SELECTs. EXCEPT takes the result of left SELECT after
removing the results of the right SELECT. When three are more SELECTs
are connected into a compound, they group from left to right.</p>
<hr />
<a name="update"></a>
<h1>UPDATE</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">UPDATE </font></b>[<b><font color="#2c2cf0"> OR </font></b><i><font color="#ff3434">conflict-algorithm</font></i><b><font color="#2c2cf0"> </font></b>]<b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">database-name</font></i><b><font color="#2c2cf0"> <big>.</big></font></b>]<b><font color="#2c2cf0"> </font></b><i><font color="#ff3434">table-name</font></i><b><font color="#2c2cf0"><br>
SET </font></b><i><font color="#ff3434">assignment</font></i><b><font color="#2c2cf0"> </font></b>[<b><font color="#2c2cf0"><big>,</big> </font></b><i><font color="#ff3434">assignment</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b><big>*</big><b><font color="#2c2cf0"><br>
</font></b>[<b><font color="#2c2cf0">WHERE </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
<tr><td align="right" valign="top">
<i><font color="#ff3434">assignment</font></i> ::=</td>
<td><b><font color="#2c2cf0"></font></b><i><font color="#ff3434">column-name</font></i><b><font color="#2c2cf0"> <big>=</big> </font></b><i><font color="#ff3434">expr</font></i><b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The UPDATE statement is used to change the value of columns in
selected rows of a table. Each assignment in an UPDATE specifies
a column name to the left of the equals sign and an arbitrary expression
to the right. The expressions may use the values of other columns.
All expressions are evaluated before any assignments are made.
A WHERE clause can be used to restrict which rows are updated.</p>
<p>The optional conflict-clause allows the specification of an alternative
constraint conflict resolution algorithm to use during this one command.
See the section titled
<a href="#conflict">ON CONFLICT</a> for additional information.</p>
<hr />
<a name="vacuum"></a>
<h1>VACUUM</h1>
<table cellpadding="10">
<tr><td align="right" valign="top">
<i><font color="#ff3434">sql-statement</font></i> ::=</td>
<td><b><font color="#2c2cf0">VACUUM </font></b>[<b><font color="#2c2cf0"></font></b><i><font color="#ff3434">index-or-table-name</font></i><b><font color="#2c2cf0"></font></b>]<b><font color="#2c2cf0"></font></b></td></tr>
</table>
<p>The VACUUM command is an SQLite extension modelled after a similar
command found in PostgreSQL. If VACUUM is invoked with the name of a
table or index then it is suppose to clean up the named table or index.
In version 1.0 of SQLite, the VACUUM command would invoke
<b>gdbm_reorganize()</b> to clean up the backend database file.</p>
<p>
VACUUM became a no-op when the GDBM backend was removed from
SQLITE in version 2.0.0.
VACUUM was reimplimented in version 2.8.1.
The index or table name argument is now ignored.
</p>
<p>When an object (table, index, or trigger) is dropped from the
database, it leaves behind empty space. This makes the database
file larger than it needs to be, but can speed up inserts. In time
inserts and deletes can leave the database file structure fragmented,
which slows down disk access to the database contents.
The VACUUM command cleans
the database by copying its contents to a temporary database file and
reloading the original database file from the copy. This eliminates
free pages, aligns table data to be contiguous, and otherwise cleans
up the database file structure.</p>
<p>This command will fail if there is an active transaction. This
command has no effect on an in-memory database.</p>
<hr />
<a name="keywords"></a>
<h1>SQLite keywords</h1>
<p>The following keywords are used by SQLite. Most are either reserved
words in SQL-92 or were listed as potential reserved words. Those which
aren't are shown in italics. Not all of these words are actually used
by SQLite. Keywords are not reserved in SQLite. Any keyword can be used
as an identifier for SQLite objects (columns, databases, indexes, tables,
triggers, views, ...) but must generally be enclosed by brackets or
quotes to avoid confusing the parser. Keyword matching in SQLite is
case-insensitive.</p>
<p>Keywords can be used as identifiers in three ways:</p>
<table>
<tr> <td width=12%> 'keyword'
<td>Interpreted as a literal string if it occurs in a legal string
context, otherwise as an identifier.
<tr> <td> "keyword"
<td>Interpreted as an identifier if it matches a known identifier
and occurs in a legal identifier context, otherwise as a string.
<tr> <td> [keyword]
<td> Always interpreted as an identifer. (This notation is used
by MS Access and SQL Server.)
</table>
<h2>Fallback Keywords</h2>
<p>These keywords can be used as identifiers for SQLite objects without
delimiters.</p>
<p>
<i>ABORT</i>
AFTER
ASC
<i>ATTACH</i>
BEFORE
BEGIN
DEFERRED
CASCADE
<i>CLUSTER</i>
<i>CONFLICT</i>
<i>COPY</i>
CROSS
<i>DATABASE</i>
<i>DELIMITERS</i>
DESC
<i>DETACH</i>
EACH
END
<i>EXPLAIN</i>
<i>FAIL</i>
FOR
FULL
IGNORE
IMMEDIATE
INITIALLY
INNER
<i>INSTEAD</i>
KEY
LEFT
MATCH
NATURAL
OF
<i>OFFSET</i>
OUTER
<i>PRAGMA</i>
<i>RAISE</i>
<i>REPLACE</i>
RESTRICT
RIGHT
<i>ROW</i>
<i>STATEMENT</i>
<i>TEMP</i>
TEMPORARY
TRIGGER
<i>VACUUM</i>
VIEW
</p>
<h2>Normal keywords</h2>
<p>These keywords can be used as identifiers for SQLite objects, but
must be enclosed in brackets or quotes for SQLite to recognize them as
an identifier.</p>
<p>
ALL
AND
AS
BETWEEN
BY
CASE
CHECK
COLLATE
COMMIT
CONSTRAINT
CREATE
DEFAULT
DEFERRABLE
DELETE
DISTINCT
DROP
ELSE
EXCEPT
FOREIGN
FROM
<i>GLOB</i>
GROUP
HAVING
IN
<i>INDEX</i>
INSERT
INTERSECT
INTO
IS
<i>ISNULL</i>
JOIN
LIKE
LIMIT
NOT
<i>NOTNULL</i>
NULL
ON
OR
ORDER
PRIMARY
REFERENCES
ROLLBACK
SELECT
SET
TABLE
THEN
TRANSACTION
UNION
UNIQUE
UPDATE
USING
VALUES
WHEN
WHERE
</p>
<h2>Special words</h2>
<p>The following are not keywords in SQLite, but are used as names of
system objects. They can be used as an identifier for a different
type of object.</p>
<p>
<i>_ROWID_</i>
<i>MAIN</i>
OID
<i>ROWID</i>
<i>SQLITE_MASTER</i>
<i>SQLITE_TEMP_MASTER</i>
</p>
<p><hr /></p>
<p><a href="index.html"><img src="/goback.jpg" border=0 />
Back to the SQLite Home Page</a>
</p>
</body></html>
|