home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / misc / sqldb.lzh / sqldb / doc / sqldb_sqlrefman.doc < prev    next >
Encoding:
Text File  |  1992-08-28  |  8.6 KB  |  362 lines

  1. 0.0
  2. SQLdb SQL reference manual.  Everything in this manual applies only to SQLdb 
  3. and any resemblence to other SQL dialects is purely coincidental.
  4.  
  5. 1.0
  6. -----------------
  7. |SIMPLE ELEMENTS|
  8. -----------------
  9.  
  10. 1.1
  11. dbname:        SQL identifier
  12.  
  13. table:        SQL identifier
  14.  
  15. column:        SQL identifier
  16.  
  17. alias:        SQL identifier
  18.  
  19. colalias:    SQL identifier
  20.  
  21. cursor:        SQL identifier
  22.  
  23. index:        SQL identifier
  24.  
  25. An SQL identifier is composed of a letter followed by zero or more characters
  26. from the set of numbers, letters, '_', '#'.  Thus, A#_o1ne is a legal 
  27. indentifier, while _a#45 is not.
  28.  
  29. An SQL identifier cannot be a valid SQL keyword.
  30.  
  31. 1.2
  32. literal:    number or string enclosed in quotes
  33.  
  34.     1234        integer literal
  35.     0.345        float literal
  36.     'hello'        string literal
  37.     '12/21/70'    date literal
  38.     '14:45:37'    time literal
  39.  
  40. 1.3
  41. data-type:    FLOAT | SMALLINT | INTEGER | DATE | TIME | CHAR ( integer )
  42.  
  43.     FLOAT        floating point, range IEEE float
  44.     SMALLINT    small integer, range signed short
  45.     INTEGER        large integer, range signed int
  46.     DATE        date mo/da/yr
  47.     TIME        time hr:mn:sc
  48.     CHAR        fixed length character string
  49.  
  50. 2.0
  51. -----------------
  52. |DATA DEFINITION|
  53. -----------------
  54.  
  55. 2.1
  56. CREATE DATABASE dbname
  57.  
  58. Creates and opens specified database.  CREATE TABLE is valid only with an open 
  59. database.  Any tables that are CREATEd are added to the open database.  Command
  60. fails if a database is already open.
  61.     
  62. 2.2
  63. OPEN DATABASE dbname
  64.  
  65. Opens specified database.  Any tables that are CREATEd while database is open 
  66. are added.  Command fails if a database is already open.
  67.  
  68. 2.3
  69. CLOSE DATABASE 
  70.  
  71. Closes database.  All tables in the database are closed as well.
  72.  
  73. 2.4
  74. CREATE TABLE table ( table-def-item-list )
  75.  
  76. This statement will create the specified table.  If a table already exists,
  77. it will be overwritten.  The table will be OPENed after creation.
  78.  
  79. 2.5
  80. CREATE INDEX index ON table (order-ref-list)
  81.  
  82. This statement will create an index on the specified table.  The table must
  83. be OPENed first.
  84.  
  85. 3.0
  86. ----------
  87. |DATA I/O|
  88. ----------
  89.  
  90. 3.1
  91. LOAD TABLE table
  92.  
  93. This statement will open the specified table and load the rows into RAM.  You
  94. must CREATE TABLE before you can LOAD TABLE.  There must not be any indexes
  95. on a table that you LOAD.  This command will probably go away in the future
  96. unless I hear a compelling reason to keep it.
  97.  
  98. 3.2
  99. OPEN TABLE table
  100.  
  101. This statement will open the specified table.  You must CREATE TABLE before you
  102. can OPEN TABLE.
  103.  
  104. 3.3
  105. CLOSE TABLE table
  106.  
  107. This statement will close the specified table.  It writes any changes to the
  108. table to disk.  All user tables must be closed before you may exit SQLdb.
  109.  
  110. 3.4
  111. DROP TABLE table
  112.  
  113. This statement will delete the specified table.  The table must be OPENed
  114. first.
  115.  
  116. 4.0
  117. -------------------------
  118. |BASIC DATA MANIPULATION|
  119. -------------------------
  120.  
  121. 4.1
  122. query-spec:    SELECT [DISTINCT] { select-item-list | * }
  123.             FROM table-ref-list
  124.             [ WHERE search-condition ]
  125.             [ GROUP BY group-ref-list [ HAVING search-condition ] ]
  126.             [ ORDER BY order-ref-list ]
  127.             [ OUTPUT TO file-name ]
  128.  
  129. This statement is used to retrieve information from the database.  It is
  130. made up of several clauses, which are explained in the following sections.
  131.  
  132. If DISTINCT is specified, then all duplicate rows will be removed from the
  133. result table.
  134.  
  135. 4.1.1 FROM clause
  136.  
  137. This clause specifies which tables SQLdb is supposed to gather information
  138. from.
  139.  
  140. 4.1.2 WHERE clause
  141.  
  142. This clause is used by several other statements, and is used to restrict
  143. the set of rows to be operated on.  A WHERE clause succeeds if the 
  144. search-condition evaluate to true.
  145.  
  146. 4.1.3 GROUP BY clause
  147. 4.1.3.1
  148.  
  149. 4.1.3.2 HAVING clause
  150.  
  151. 4.1.4 ORDER BY clause
  152.  
  153. 4.1.5 OUTPUT TO clause
  154.  
  155. This command will send the normal query output to specified filename.
  156.  
  157. 4.2
  158. subquery:    \[ query-spec \]
  159.  
  160. 4.3
  161. INSERT INTO table [ ( column-list ) ]
  162.     { VALUES ( insert-item-list ) | query-spec }
  163.  
  164. This statement is used to place information in a table.  The column list is 
  165. optional.  If it is supplied, each value is placed in the corresponding
  166. column in the column-list.  Otherwise, the column-list default to all columns
  167. in the table.  Any missing values are treated as AMARKs.
  168.  
  169. If a query is supplied instead of a value list, the query is executed and all
  170. rows in the result will be inserted into the table.
  171.  
  172. 4.4
  173. DELETE FROM table [ WHERE search-condition ]
  174.  
  175. This statement is used to delete rows that satisfy the optional WHERE clause.
  176. If the WHERE clause is omitted, all rows in the table are deleted.
  177.  
  178. 4.5
  179. UPDATE table SET assignment-list [ WHERE search-condition ]
  180.  
  181. This statement is used to modify existing rows that satisfy the optional WHERE
  182. clause.  If the WHERE clause is omitted, all rows in the table are modified.
  183.  
  184. 5.0
  185. -------------------------
  186. |CURSOR BASED STATEMENTS|
  187. -------------------------
  188.  
  189. The following statements can be type interactively, but they are intended to 
  190. be used through an ARexx port.
  191.  
  192. 5.1
  193. DECLARE cursor CURSOR FOR query-expr
  194.  
  195. This statement will create and define a cursor.
  196.  
  197. 5.2
  198. OPEN cursor
  199.  
  200. This statement will execute a previously DECLAREd cursor's query-expr.  You
  201. must CLOSE an OPENed cursor.
  202.  
  203. 5.3
  204. CLOSE cursor
  205.  
  206. This statement will close and remove an existing cursor.  A cursor that has
  207. been CLOSEd must be re-DECLAREd and OPENed.
  208.  
  209. 5.4
  210.  
  211. FETCH { COLUMNS | FIRST | LAST | PREVIOUS | NEXT |
  212.     ABSOLUTE integer | RELATIVE integer } OF cursor-name
  213.  
  214. This statement will retrieve the specified row or column list, of the table 
  215. created by the cursor's query-expr.
  216.  
  217. 6.0
  218. -------------------
  219. |SEARCH CONDITIONS|
  220. -------------------
  221.  
  222. 6.1
  223. search-condition:    search-item | search-item { AND | OR } search-item
  224.  
  225. Each search-item evaluates to a true, false, AMARK, or IMARK.  This is a
  226. four value logic system.
  227.  
  228. AND| F  A  I  T        OR| F  A  I  T
  229. ---------------        --------------
  230.  F | F  F  F  F        F | F  A  F  T
  231.  A | F  A  I  A        A | A  A  A  T
  232.  I | F  I  I  I        I | F  A  I  T
  233.  T | F  A  I  T        T | T  T  T  T
  234.  
  235. 6.2
  236. search-item:        { search-test | { NOT | MAYBE_A | MAYBE_I | MAYBE } ( search-condition ) }
  237.  
  238. The logical operators NOT, MAYBE_A, MAYBE_I, MAYBE are defined below:
  239.  
  240.     P |NOT P   P | MAYBE_I P   P | MAYBE_A P   P | MAYBE P
  241.     --------   -------------   -------------   -----------
  242.     t | f       t | f       t | f       t | f
  243.     a | a      a | f           a | t       a | t
  244.     i | i      i | t        i | f       i | t
  245.       f | t      f | f        f | f       f | f
  246.  
  247. 6.3
  248. search-test:        comparison-test | like-test | set-test |
  249.             quantified-test | existence-test
  250.  
  251. 6.4
  252. comparison-test:    expr { = | <> | < | <= | > | >= } { expr | subquery }
  253.  
  254. 6.5
  255. like-test:        column-ref [ NOT ] LIKE 
  256.                 string-pattern [ ESCAPE charstr ]
  257.  
  258. A string pattern is a string literal.  The '%' is a wildcard to match
  259. 0 or more characters, and the '_' is a wildcard to match one character.
  260. The escape character, if specified, will turn a '%' or '_' into a normal
  261. character.  
  262.  
  263.     Example:  foo LIKE 'ab#%c' ESCAPE '#' will match the string 'ab%c'.
  264.  
  265. 6.6
  266. set-test:        expr [ NOT ] IN { \( literal-list \) | subquery }
  267.  
  268. 6.7
  269. quantified-test:    expr { = | <> | < | <= | > | >= } { ALL | ANY | SOME } subquery
  270.  
  271. 6.8
  272. existence-test:        [ NOT ] EXISTS subquery
  273.  
  274. This evaluates to true if table resulting from subquery has at least one row
  275. in it.
  276.  
  277. 7.0
  278. -------------
  279. |EXPRESSIONS|
  280. -------------
  281.  
  282. 7.1
  283. expr:        function | expr2
  284.  
  285. This definition means that you cannot nest functions, and functions must
  286. appear by themselves.  Thus, AVG(4*(7-5)) is a valid expr, but MIN(col1)*3 is 
  287. not.
  288.  
  289. 7.2
  290. expr2:        expr-item | expr-item { + | - | * | / } expr-item
  291.  
  292. The four operators have equal precedence.  Use parentheses to force a 
  293. particular evaluation order.
  294.  
  295. 7.3
  296. expr-item:    value | column-ref | ( expr2 )
  297.  
  298. 7.4
  299. value:        literal | AMARK | IMARK | NULL
  300.  
  301. 7.5
  302. function:    { AVG | MAX | MIN | SUM | COUNT } ( expr2 )
  303.  
  304. Functions can only be applied to numeric (FLOAT, SMALLINT, INTEGER) columns.
  305.  
  306.     AVG        average of all values in an expression
  307.     MAX        maximum value in an expression
  308.     MIN        minimum value in an expression
  309.     SUM        total of values in an expression
  310.     COUNT        number of values (rows)
  311.  
  312. 8.0
  313. --------------------
  314. |STATEMENT ELEMENTS|
  315. --------------------
  316.  
  317. assignment:    column = expr
  318.  
  319. insert-item:    value
  320.  
  321. select-item:    expr [AS colalias]
  322.  
  323. Column aliases can be used to reference an expression later in the 
  324. select-item-list.
  325.  
  326.     Example:  SELECT col1,col1 AS foocol, foocol*2 AS bleh FROM footab;
  327.  
  328.     col1  foocol  bleh
  329.     ----  ------  ----
  330.     1     1       2
  331.     3     3       6
  332.  
  333. table-ref:    table [ alias ]
  334.  
  335. column-ref:    [ { table | alias } . ] column
  336.  
  337. group-ref:    column-ref | number
  338.  
  339. order-ref:    group-ref [ { ASC | DESC } ]
  340.  
  341. table-def-item:    column-def
  342.  
  343. column-def:    column data-type
  344.  
  345.  
  346. 9.0
  347. ------
  348. |MISC|
  349. ------
  350.  
  351. 9.1
  352. DISPLAY TABLE table;
  353.  
  354. This statement will display information about specified table.  The table
  355. must have been OPENed or LOADed.
  356.  
  357. 9.2
  358. DISPLAY DATABASE;
  359.  
  360. This statement will display the names of all OPENed or LOADed tables.
  361.  
  362.