From f8565825622a1ed48bdaa835968a1137b2ffa593 Mon Sep 17 00:00:00 2001
From: drh
+In SQLite, every row of every table has an integer ROWID.
+The ROWID for each row is unique among all rows in the same table.
+In SQLite version 2.8 the ROWID is a 32-bit signed integer.
+Version 3.0 of SQLite expanded the ROWID to be a 64-bit signed integer.
+
+You can access the ROWID of an SQLite table using one the special column
+names ROWID, _ROWID_, or OID.
+Except if you declare an ordinary table column to use one of those special
+names, then the use of that name will refer to the declared column not
+to the internal ROWID.
+
+If a table contains a column of type INTEGER PRIMARY KEY, then that
+column becomes an alias for the ROWID. You can then access the ROWID
+using any of four different names, the original three names described above
+or the name given to the INTEGER PRIMARY KEY column. All these names are
+aliases for one another and work equally well in any context.
+
+When a new row is inserted into an SQLite table, the ROWID can either
+be specified as part of the INSERT statement or it can be assigned
+automatically by the database engine. To specify a ROWID manually,
+just include it in the list of values to be inserted. For example:
+
+If no ROWID is specified on the insert, an appropriate ROWID is created
+automatically. The usual algorithm is to give the newly created row
+a ROWID that is one larger than the largest ROWID in the table prior
+to the insert. If the table is initially empty, then a ROWID of 1 is
+used. If the largest ROWID is equal to the largest possible integer
+(9223372036854775807 in SQLite version 3.0 and later) then the database
+engine starts picking candidate ROWIDs at random until it finds one
+that is not previously used.
+
+The normal ROWID selection algorithm described above
+will generate monotonically increasing
+unique ROWIDs as long as you never use the maximum ROWID value and you never
+delete the entry in the table with the largest ROWID.
+If you ever delete rows or if you ever create a row with the maximum possible
+ROWID, then ROWIDs from previously deleted rows might be reused when creating
+new rows and newly created ROWIDs might not be in strictly accending order.
+
+If a column has the type INTEGER PRIMARY KEY AUTOINCREMENT then a slightly
+different ROWID selection algorithm is used.
+The ROWID chosen for the new row is one larger than the largest ROWID
+that has ever before existed in that same table. If the table has never
+before contained any data, then a ROWID of 1 is used. If the table
+has previously held a row with the largest possible ROWID, then new INSERTs
+are not allowed and any attempt to insert a new row will fail with an
+SQLITE_FULL error.
+
+SQLite keeps track of the largest ROWID that a table has ever held using
+the special SQLITE_SEQUENCE table. The SQLITE_SEQUENCE table is created
+and initialized automatically whenever a normal table that contains an
+AUTOINCREMENT column is created. The content of the SQLITE_SEQUENCE table
+can be modified using ordinary UPDATE, INSERT, and DELETE statements.
+But making modifications to this table will likely perturb the AUTOINCREMENT
+key generation algorithm. Make sure you know what you are doing before
+you undertake such changes.
+
+The behavior implemented by the AUTOINCREMENT keyword is subtly different
+from the default behavior. With AUTOINCREMENT, rows with automatically
+selected ROWIDs are guaranteed to have ROWIDs that have never been used
+before by the same table in the same database. And the automatically generated
+ROWIDs are guaranteed to be monotonically increasing. These are important
+properties in certain applications. But if your application does not
+need these properties, you should probably stay with the default behavior
+since the use of AUTOINCREMENT requires additional work to be done
+as each row is inserted and thus causes INSERTs to run a little slower.
+}
+footer $rcsid
diff --git a/www/lang.tcl b/www/lang.tcl
index 8f8e421203..57d43effad 100644
--- a/www/lang.tcl
+++ b/www/lang.tcl
@@ -1,7 +1,7 @@
#
-# Run this Tcl script to generate the sqlite.html file.
+# Run this Tcl script to generate the lang-*.html files.
#
-set rcsid {$Id: lang.tcl,v 1.79 2004/11/20 08:17:18 danielk1977 Exp $}
+set rcsid {$Id: lang.tcl,v 1.80 2004/11/21 01:02:01 drh Exp $}
source common.tcl
if {[llength $argv]>0} {
@@ -12,15 +12,15 @@ if {[llength $argv]>0} {
header {Query Language Understood by SQLite}
puts {
- The SQLite library understands most of the standard SQL
language. But it does omit some features
while at the same time
adding a few features of its own. This document attempts to
describe precisely what parts of the SQL language SQLite does
-and does not support. A list of keywords is
-given at the end.SQLite Autoincrement
+
+
+
+
+CREATE TABLE test1(a INT, b TEXT);
+INSERT INTO test1(rowid, a, b) VALUES(123, 5, 'hello');
+
The AUTOINCREMENT Keyword
+
+SQL As Understood By SQLite
+SQL As Understood By SQLite
In all of the syntax diagrams that follow, literal text is shown in bold blue. Non-terminal symbols are shown in italic red. Operators @@ -122,7 +122,9 @@ proc Section {name label} { rename footer_standard footer } set ::section_file [open [file join $outputdir lang_$label.html] w] - header "SQL command \"$name\"" + header "Query Language Understood by SQLite: $name" + puts "
Specifying a PRIMARY KEY normally just creates a UNIQUE index -on the primary key. However, if primary key is on a single column +on the corresponding columns. 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, @@ -503,7 +505,11 @@ 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 "ROWID", "OID", or "_ROWID_". This is true regardless of whether or not there is an INTEGER -PRIMARY KEY.
+PRIMARY KEY. An INTEGER PRIMARY KEY column man also include the +keyword AUTOINCREMENT. The AUTOINCREMENT keyword modified the way +that B-Tree keys are automatically generated. Additional detail +on automatic B-Tree key generation is available +separately.If the "TEMP" or "TEMPORARY" keyword occurs in between "CREATE" and "TABLE" then the table that is created is only visible to the @@ -798,8 +804,7 @@ puts { with the CREATE INDEX 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.
+appropriate CREATE INDEX command.The DROP INDEX statement does not reduce the size of the database file. Empty space in the database is retained for later INSERTs. To @@ -1543,192 +1548,219 @@ is auto-vacuum mode, enabled using the auto_vacuum pragma.
} +# A list of keywords. A asterisk occurs after the keyword if it is on +# the fallback list. +# +set keyword_list [lsort { + ABORT* + AFTER* + ALL + ALTER + AND + AS + ASC* + ATTACH* + AUTOINCREMENT + BEFORE* + BEGIN* + BETWEEN + BY + CASCADE* + CASE + CHECK + COLLATE + COMMIT + CONFLICT* + CONSTRAINT + CREATE + CROSS + CURRENT_DATE* + CURRENT_TIME* + CURRENT_TIMESTAMP* + DATABASE* + DEFAULT + DEFERRED* + DEFERRABLE + DELETE + DESC* + DETACH* + DISTINCT + DROP + END* + EACH* + ELSE + ESCAPE + EXCEPT + EXCLUSIVE* + EXPLAIN* + FAIL* + FOR* + FOREIGN + FROM + FULL + GLOB* + GROUP + HAVING + IGNORE* + IMMEDIATE* + IN + INDEX + INITIALLY* + INNER + INSERT + INSTEAD* + INTERSECT + INTO + IS + ISNULL + JOIN + KEY* + LEFT + LIKE* + LIMIT + MATCH* + NATURAL + NOT + NOTNULL + NULL + OF* + OFFSET* + ON + OR + ORDER + OUTER + PRAGMA* + PRIMARY + RAISE* + REFERENCES + REINDEX* + RENAME* + REPLACE* + RESTRICT* + RIGHT + ROLLBACK + ROW* + SELECT + SET + STATEMENT* + TABLE + TEMP* + TEMPORARY* + THEN + TO + TRANSACTION + TRIGGER* + UNION + UNIQUE + UPDATE + USING + VACUUM* + VALUES + VIEW* + WHEN + WHERE +}] + + Section {SQLite keywords} keywords puts { -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.
+The SQL standard specifies a huge number of keywords which may not +be used as the names of tables, indices, columns, or databases. The +list is so long that few people can remember them all. For most SQL +code, your safest bet is to never use any English language word as the +name of a user-defined object.
-Keywords can be used as identifiers in three ways:
+If you want to use a keyword as a name, you need to quote it. There +are three ways of quoting keywords in SQLite:
++
+ --
+'keyword' - Interpreted as a literal string if it occurs in a legal string - context, otherwise as an identifier. - "keyword" - Interpreted as an identifier if it matches a known identifier - and occurs in a legal identifier context, otherwise as a string. - [keyword] - Always interpreted as an identifier. (This notation is used - by MS Access and SQL Server.) + + 'keyword' + A keyword in single quotes is interpreted as a literal string + if it occurs in a context where a string literal is allowed, otherwise + it is understood as an identifier. + "keyword" + A keyword in double-quotes is interpreted as an identifier if + it matches a known identifier. Otherwise it is interpreted as a + string literal. [keyword] + A keyword enclosed in square brackets is always understood as + an identifier. This is not standard SQL. This quoting mechanism + is used by MS Access and SQL Server and is included in SQLite for + compatibility.
Quoted keywords are unaesthetic. +To help you avoid them, SQLite allows many keywords to be used unquoted +as the names of databases, tables, indices, triggers, views, and/or columns. +In the list of keywords that follows, those that can be used as identifiers +are shown in an italic font. Keywords that must be quoted in order to be +used as identifiers are shown in bold.
-These keywords can be used as identifiers for SQLite objects without -delimiters.
-} ++SQLite adds new keywords from time to time when it take on new features. +So to prevent you code from being broken by future enhancements, you should +normally quote any indentifier that is an English language word, even if +you do not have to. +
-proc keyword_list {x} { - puts "" - foreach k $x { - if {[string index $k 0]=="*"} { - set nonstandard 1 - set k [string range $k 1 end] - } else { - set nonstandard 0 - } - if {$nonstandard} { - puts "$k " - } else { - puts "$k " - } +
+The following are the keywords currently recognized by SQLite: +
+ ++-+
+ +} + +set n [llength $keyword_list] +set nCol 5 +set nRow [expr {($n+$nCol-1)/$nCol}] +set i 0 +foreach word $keyword_list { + if {[string index $word end]=="*"} { + set word [string range $word 0 end-1] + set font i + } else { + set font b } - puts "\n" + if {$i==$nRow} { + puts " " + set i 1 + } else { + incr i + } + puts "<$font>$word$font>
" } -keyword_list { - *ABORT - AFTER - ASC - *ATTACH - BEFORE - BEGIN - DEFERRED - CASCADE - *CLUSTER - *CONFLICT - *COPY - CROSS - *DATABASE - *DELIMITERS - DESC - *DETACH - EACH - END - EXPLAIN - *EXPLAIN - *FAIL - FOR - FULL - IGNORE - IMMEDIATE - INITIALLY - INNER - *INSTEAD - KEY - LEFT - MATCH - NATURAL - OF - *OFFSET - OUTER - *PRAGMA - *RAISE - *REPLACE - RESTRICT - RIGHT - *ROW - *STATEMENT - *TEMP - TEMPORARY - TRIGGER - *VACUUM - VIEW -} puts { +
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.
-} - -keyword_list { - ALL - AND - AS - BETWEEN - BY - CASE - CHECK - COLLATE - COMMIT - CONSTRAINT - CREATE - DEFAULT - DEFERRABLE - DELETE - DISTINCT - DROP - ELSE - EXCEPT - ESCAPE - FOREIGN - FROM - *GLOB - GROUP - HAVING - IN - *INDEX - INSERT - INTERSECT - INTO - IS - *ISNULL - JOIN - LIKE - LIMIT - NOT - *NOTNULL - NULL - ON - OR - ORDER - PRIMARY - REFERENCES - ROLLBACK - SELECT - SET - TABLE - THEN - TRANSACTION - UNION - UNIQUE - UPDATE - USING - VALUES - WHEN - WHERE -} - -puts { -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.
-} -keyword_list { - *_ROWID_ - *MAIN - OID - *ROWID - *SQLITE_MASTER - *SQLITE_TEMP_MASTER ++ _ROWID_} footer $rcsid if {[string length $outputdir]} { footer $rcsid } - -- 2.47.3
+ MAIN
+ OID
+ ROWID
+ SQLITE_MASTER
+ SQLITE_SEQUENCE
+ SQLITE_TEMP_MASTER
+ TEMP
+