You are on page 1of 1

16 Chapter 1: Creating

Run the following command in ISQL to determine that ( x + y + z ) returns an


'int':
SELECT EXPRTYPE ( 'SELECT ( x + y + z ) FROM t', 1 );
Now the computed column can be added, together with a clustered index to
improve the BETWEEN range query:
CREATE TABLE t (
pkey INTEGER NOT NULL DEFAULT AUTOINCREMENT,
x INTEGER,
y INTEGER,
z INTEGER,
xyz INTEGER COMPUTE ( x + y + z ),
PRIMARY KEY ( pkey ) );

CREATE CLUSTERED INDEX xyz ON t ( xyz );

SELECT * FROM t WHERE ( x + y + z ) BETWEEN 1501 AND 1510;


The SELECT may now use the new index even though the column xyz doesnt
appear in the WHERE clause.

Note: The index may be used, or it may not, depending on conditions in the
data and choices made by the query optimizer. It is difficult, if not impossible, to
predict exactly what the query optimizer will actually do in any given situation,
but the point of this example is that the computed column makes it possible for
the index to be used.

For more information about clustered indexes, see Section 10.7, CREATE
INDEX.

1.8 DEFAULT Values


DEFAULT values are assigned whenever an explicit value is not provided when
a row is inserted. Some special default values are also applied when the row is
updated.
<default_value> ::= NULL
| AUTOINCREMENT
| GLOBAL AUTOINCREMENT
| GLOBAL AUTOINCREMENT "(" <partition_size> ")"
| <string_literal>
| [ "-" ] <number_literal>
| <special_literal>
| <special_update_default>
| <constant_function_call>
| "(" <constant_expression> ")"
<partition_size> ::= integer literal in the range 1 to 4611686018427387903
<string_literal> ::= a sequence of characters enclosed in single quotes
<number_literal> ::= integer, exact numeric or float numeric literal
DEFAULT NULL is the default DEFAULT, so to speak. It means this column
will be set to NULL if no value is given.

You might also like