Unidata: Unidata SQL Commands Reference
Unidata: Unidata SQL Commands Reference
Unidata: Unidata SQL Commands Reference
Version 5.2
June 2000
Part No. 000-6869
Published by Informix Press Informix Corporation
4100 Bohannon Drive
Menlo Park, CA 94025-1032
© 2000 Informix Corporation. All rights reserved. The following are trademarks of Informix Corporation or its affiliates,
one or more of which may be registered in the United States or other jurisdictions:
Answers OnLineTM; ArdentTM; AxielleTM; C-ISAM; Client SDKTM; CloudconnectorTM; CloudscapeTM; CloudsyncTM;
CloudviewTM; DataBlade; Data DirectorTM; Data MineTM; Data Mine BuilderTM; DataStage; Decision FastStartTM;
Decision for Telecommunications Campaign ManagementTM; Decision FrontierTM; Decision Solution SuiteTM;
DecisionscapeTM; DialogueTM; Dynamic Scalable ArchitectureTM; Dynamic ServerTM; Dynamic Server.2000TM;
Dynamic ServerTM, Developer EditionTM; Dynamic ServerTM with Advanced Decision Support OptionTM;
Dynamic ServerTM with Extended Parallel OptionTM; Dynamic ServerTM with MetaCube ROLAP Option;
Dynamic ServerTM with Universal Data OptionTM; Dynamic ServerTM with Web Integration OptionTM;
Dynamic ServerTM, Workgroup EditionTM; Dynamic Virtual MachineTM; Encrypt.CSMTM; Enterprise Decision ServerTM;
E-stageTM; FormationTM; Formation ArchitectTM; Formation Flow EngineTM; Foundation.2000TM;
Frameworks for Business IntelligenceTM; Frameworks TechnologyTM; Gold Mine Data Access; i.DecideTM;
i.Financial ServicesTM; i.FoundationTM; i.IntelligenceTM; i.ReachTM; i.SellTM; Illustra; Informix; Informix 4GL;
Informix COM AdapterTM; Informix Enterprise Command CenterTM; Informix Extended Parallel ServerTM;
Informix Informed DecisionsTM; Informix InquireSM; Informix Internet Foundation.2000TM; InformixLink;
InformiXMLTM; Informix Red Brick Decision ServerTM; Informix Session ProxyTM; Informix VistaTM; InfoShelfTM;
Installation AssistantTM; InterforumTM; I-SpyTM; IterationsTM; J/FoundationTM; LUCIDTM; MaxConnectTM; Media360TM;
MediazationTM; MetaArchitectTM; MetaBrokerTM; MetaCube; MetaHubTM; MetaStageTM; NewEraTM; O2 & DesignTM;
O2 Technology & DesignTM; Object TranslatorTM; Office ConnectTM; ON-BarTM; OnLine Dynamic ServerTM;
OnLine/Secure Dynamic ServerTM; OpenCase; OrcaTM; PaVERTM; Prism; Prism & DesignTM; RedBack; RedBeanTM;
RedBeans & DesignTM; Red Brick and Design; Red Brick Data MineTM; Red Brick Decision ServerTM;
Red Brick Mine BuilderTM; Red Brick DecisionscapeTM; Red Brick ReadyTM; Red Brick Systems;
Regency Support; Rely on Red BrickSM; RISQL; Server AdministratorTM; Solution DesignSM; STARindexTM;
STARjoinTM; SuperTerm; SuperView; SureStartTM; SystemBuilderTM; TARGETindexTM; TARGETjoinTM;
The Data Warehouse Company; UniData; UniData & Design; UniVerse; Universal Data Warehouse BlueprintTM;
Universal Database ComponentsTM; Universal Web ConnectTM; ViewPoint; Virtual Table InterfaceTM; VisionaryTM;
Web Integration SuiteTM; XML DataPortTM; Zero Defect Data. The Informix logo is registered with the United States
Patent and Trademark Office. The DataBlade logo is registered with the United States Patent and Trademark Office.
Software and documentation acquired by or for the US Government are provided with rights as follows:
(1) if for civilian agency use, with rights as restricted by vendor’s standard license, as prescribed in FAR 12.212; (2) if for
Dept. of Defense use, with rights as restricted by vendor’s standard license, unless superseded by a negotiated vendor
license, as prescribed in DFARS 227.7202. Any whole or partial reproduction of software or documentation marked with
this legend must reproduce this legend.
DELETE ...................................................................................................79
DROP INDEX ..........................................................................................83
DROP SUBTABLE ..................................................................................84
DROP TABLE ..........................................................................................85
DROP VIEW ............................................................................................87
EXIT .........................................................................................................89
GRANT .....................................................................................................90
INSERT ....................................................................................................94
LISTDICT .................................................................................................99
LOCK TABLE ........................................................................................101
QUIT .......................................................................................................103
REVOKE ................................................................................................104
ROLLBACK ...........................................................................................107
SELECT ..................................................................................................108
SET .........................................................................................................130
SHOW .....................................................................................................143
SQL .........................................................................................................146
TTITLE ...................................................................................................147
UPDATE .................................................................................................155
Index
This chapter provides complete descriptions of all commands in the UniData implementation of
Structured Query Language (SQL).
UniData SQL commands can be entered from the sql prompt or by encoding a series of SQL
statements in an ASCII text file (UniSQL script) with your system editor. You can then execute the
script from the operating system prompt. This provides the capability of reusing a series of
UniData SQL statements.
Table Commands:
• CREATE TABLE
• ALTER TABLE
• DROP TABLE
Indexing Commands:
• CREATE INDEX
• DROP INDEX
View Commands:
• CREATE VIEW
• DROP VIEW
Subtable Commands:
• CREATE SUBTABLE
• DROP SUBTABLE
Privilege Commands:
• GRANT
• REVOKE
ALTER TABLE
Syntax
ALTER TABLE table_name {ADD | MODIFY | DELETE}
(attribute_definition [,attribute_definition...])
ALTER TABLE table_name MODULO m[,n]
Description
Use the ALTER TABLE command to add, modify, or delete attribute definitions in a table or to
change the modulo for a table.
You cannot modify subtables with ALTER TABLE; you must delete and re-create them.
Note
attribute_definition syntax is fully described in “Appendix A - Defining Attributes.” When you
use ALTER TABLE to modify or delete attribute_location, UniData SQL changes the dictionary
entry for the attribute, which may make one or more attributes inaccessible (changing attribute
location, for example). If you later add back the attribute at the same location, the data again
becomes accessible.
Keywords
The following table describes keywords you can use with ALTER TABLE.
Keyword Description
ADD Add an attribute definition to a table.
MODIFY Change the definition of an attribute in a table.
DELETE Delete an attribute definition from a table.
MODULO Change the modulo size/block size of a table. Controls
the size of the table by assigning block size and number
of blocks to store the data.
The parameters for ALTER TABLE are described under CREATE TABLE. Exceptions and
additions to these descriptions are noted in the following sections.
Parameters
table_name is the name of the table to be modified. For a description of attribute_definition, see
“Appendix A - Defining Attributes.”
Screen Example
Parameters
For a description of table_name, see CREATE TABLE. For a description of attribute_definition,
see “Appendix A - Defining Attributes.”
• If you add an existing association name to an attribute definition, UniData SQL adds the
attribute name to the phrase of the PH attribute.
• If you remove the association name from an attribute definition, UniData SQL deletes that
attribute name from the phrase of the associated PH attribute. If you remove the
association name and it is not used in any other attribute definitions, UniData SQL deletes
the association attribute (PH) from the dictionary.
Screen Example
Note
ALTER TABLE DELETE deletes the attribute definition, making the data inaccessible. If you
later add an attribute at the same location, the data again becomes accessible.
table_name is the name of the table to be modified. For a description of attribute_definition, see
“Appendix A - Defining Attributes.”
Screen Example
In the following example, the @ID is deleted from the ORDERS table, making the data in that
attribute inaccessible. Notice that the @ID can be deleted because an alias exists in the ORDERS
file for this attribute; the data are still accessible through this alias.
Screen Example
Then, when the @ID is added back at the same location, the data is again accessible through that
attribute name.
Screen Example
Parameters
table_name is the name of the table to be modified. For instructions on setting MODULO, see
CREATE TABLE.
Example
Screen Example
AUTO COMMIT
Syntax
AUTO COMMIT [ ON | OFF ]
Description
AUTO COMMIT ON causes each statement to commit immediately. AUTO COMMIT gives
application developers and users enhanced transaction control capabilities.
Note
AUTO COMMIT is a transaction processing (TP) command. The Recoverable File System (RFS)
must be in use for transaction processing to work. In the absence of RFS, TP commands are
ignored. UniData for Windows NT or Windows 2000 does not support RFS.
If you execute the AUTO COMMIT command in a non-RFS environment, UniData does not issue
an error message, but the command does not perform the expected function.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
ON Each UniData SQL statement is immediately committed, releasing all locks.
OFF Several statements can be combined into one transaction.
Tip - Use the OFF parameter if you want to be able to commit or roll back a
set of statements as a single unit.
no option Displays the current setting of AUTO COMMIT.
Note
Unlike SET TRANSACTION, which sets options that apply to the next transaction only, AUTO
COMMIT affects all subsequent transactions until UniData SQL encounters another AUTO
COMMIT statement.
Example
The following example demonstrates the use of AUTO COMMIT to display or change its status:
Screen Example
BREAK
Syntax
BREAK ON
{[attribute_name [“text” | VALUE] [NODUP | DUPL]
| expression ["text" | VALUE] [NODUP | DUPL] ]
| ROW [BSKIP n] [SKIP n | [SKIP] PAGE]
| REPORT [BSKIP n] [SKIP n | [SKIP] PAGE] }...
Description
The BREAK command activates actions established by the COLUMN and COMPUTE
commands, and adds printer directives to take place at the break.
Both BREAK and COMPUTE must specify the same “ON” level, such as “ON REPORT” or
“ON fld1.”
A break may be associated with any of the following:
• A change in value of a specified attribute
• The end of a record
• The end of a report
BREAK actions include the following:
• Skip a number of lines
• Execute a page break
• Print out messages
Note
Only one break command can be in effect at one time. The last break command overrides the
preceding one.
Parameters
The following table describes each parameter of the syntax.
Parameters Description
ON Breaks when the value of the attribute or expression changes.
attribute_name An attribute name on which to execute break commands.
expression Any combination of attribute names, constants, arithmetic
operators, and UniData SQL functions that together select
data. Expressions must be enclosed in quotation marks, and
keywords must be entered in uppercase.
“text” Displays text at break. text must be enclosed in quotation
marks.
VALUE Displays the value of attribute_name or expression.
NODUP Default. Prints only unique values.
DUPL Prints duplicate values.
ROW Breaks after every record.
REPORT Breaks at the end of the report.
BSKIP n Skips n lines before printing the break line.
SKIP n Skips n lines after printing the break line.
SKIP PAGE Skips to a new page after printing the break line. The keyword
SKIP is optional.
no parameter Displays the current break definition.
BREAK Options
Example
The following example demonstrates the BREAK ON command, used to separate report
information into a readable format. The break is set on PROD_NAME. Notice that the rows are
also ordered by PROD_NAME so that all products of the same name are listed together.
Screen Example
...
BTITLE
Syntax
BTITLE [ print_clause | OFF | ON]
print_clause syntax:
{COL [n] | LEFT | CENTER | RIGHT}
[ “text”]
[FORMAT format | [TAB [n] ] old_val | “text”]...
Description
The BTITLE command establishes a footer for printed and displayed reports created by SELECT
statements. You can specify any number of constants and variables. These parameters are executed
in the order in which they are defined. You can apply any number of BTITLE options to one or
more attributes. If more than one BTITLE command is applied to the same attribute, the last
command supersedes all previous commands.
Note
Execute the SHOW BTITLE command to display the current setting of BTITLE.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
print_clause Sets the following:
• Skip columns.
• Skip lines.
• Align title data left, center or right.
• Format "text" for display.
For print_clause options, see the next table.
ON Turns the footer on, causing "text" to be printed.
OFF Turns the footer off.
Note - You do not have to redefine "text" to turn footers back on.
no parameter Displays BTITLE current settings.
Note - SHOW BTITLE also displays current settings.
BTITLE Parameters
print_clause Parameters
The following table describes each parameter of print_clause.
Clause Description
COL n Skips to the nth column before displaying the header. The first
column is numbered 0.
SKIP n Skips n lines before printing out the text. The default is 1.
Clause Description
LEFT, CENTER, RIGHT Aligns the title data on the current line. The data item (variable or
text) is aligned as a group to the end of the statement, or to the
next LEFT, CENTER, or RIGHT, or to the next COL, SKIP, or
TAB. CENTER and RIGHT are calculated based on the
LINESIZE option of the SET statement.
FORMAT format Specifies a format model for the following data item. FORMAT is
effective until the end of the statement or until another FORMAT
clause is encountered in the same statement. format options are
discussed following this table.
old_val Displays the current value of the variable old_val, set by
OLD_VALUE in the previously executed COLUMN statement.
"text" Displays a two-line footer. The first line contains the date at the
left and the page number on the right; the second line contains the
center-aligned text. You can include any number of the following
heading options enclosed in single quotation marks:
• C[n] – Centers heading or footing text within a line of n width.
• D – Inserts the current system date.
• L – Inserts a blank line.
• N – Suppresses the default prompt, “Enter new line to
continue...”, that appears at the bottom of each screen page.
Pages scroll without stopping until the report is finished. (The
prompt displays only in interactive mode.)
• P or S – Inserts the current page number.
• T – Inserts the time and date when report generation began.
TAB n Skips n columns from the current position.
format Options
format specifies the display format for values in the footer. format must be enclosed in quotation
marks, and can be one of the following:
• Character Format Options – The format for a character string is An where n is the column
width. The default is the length specified in the dictionary definition of the attribute.
• Date Format Options – You may not specify format options for date attributes; the
formatting specified in the dictionary definition of the attribute is used.
• Numeric Format Options – Use the options in the following table to build a display mask
for formatting numeric values.
Examples
The following example demonstrates using the BTITLE command to learn its status. The
preceding COLUMN command establishes the variable old_val, which is displayed in the
BTITLE setting.
Screen Example
sql> BTITLE;
Btitle is ON
Btitle skip 2 col 0 'Product:' tab 15oldval
The next example demonstrates creating a header and footer, then displaying them by executing a
SELECT statement. The SET PAGESIZE command causes the display page to be 10 lines long;
SET LINESIZE establishes a 40-character-wide display area.
Screen Example
Screen Example
Order
Number
----------
912
801
• BTITLE settings:
• SKIP 2 – to skip two lines before displaying the report footer (Product).
• COL 0 – to skip 0 spaces (left-justify) the footer (Product).
• TAB 2 – to skip two spaces before displaying the old value of PROD_NAME.
• ON – to turn the footer on.
Screen Example
sql>COLUMN PROD_NAME
sql>NEW_VALUE newval
sql>OLD_VALUE oldval;
sql>TTITLE SKIP 2
sql>CENTER "Product Prices" SKIP 2
sql>"Product:" TAB 2 newval;
sql>TTITLE ON;
sql>BTITLE SKIP 2 COL 0 "Product:" TAB 2 oldval;
sql>BTITLE ON;
The following SELECT statement displays output formatted by the above commands. Notice that
the first header does not display a product name after “Product:” because the variable old_val has
not yet been assigned a value.
Screen Example
Product:
Product Product
Number Name Price
---------- ---------- ----------
10007 Adapter $129.95
13001 Adapter $94.00
13002 Adapter $150.00
39400 CD Player $89.87
$89.87
...
30000 CD System $99.96
1
$99.96
37000 CD System $199.92
10
Product: CD System 10
Product Prices
Product: CD System 11
Product Product
Number Name Price
---------- ---------- ----------
38000 CD System $159.87
11
39000 CD System $249.96
12
$249.96
...
Note
For more examples, see TTITLE.
CLEAR
Syntax
CLEAR {BREAK | COLUMN | COMPUTE}
Description
The CLEAR command erases the current definition for the specified option.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
BREAK Clears the break definition specified by the
BREAK command.
COLUMN Clears column definitions defined by the
COLUMN command.
COMPUTE Clears computation definitions set by
COMPUTE commands.
CLEAR Parameters
Example
Screen Example
COLUMN
Syntax
COLUMN {attribute_name | expression}
[ALIAS alias]
[CLEAR | DEFAULT]
[FORMAT column_format]
[HEADING "text" [JUSTIFY {LEFT | CENTER | RIGHT}]]
[LIKE {expression | attribute_label}]
[NEWLINE]
[NEW_VALUE new_val]
[OLD_VALUE old_val]
[NOPRINT | PRINT]
[NULL "text"]
[ON | OFF] [SPACE n]
[WRAPPED | WORD_WRAPPED | TRUNCATED]
Description
The COLUMN command associates display formats for column headings with specified
attributes. If more than one COLUMN command is applied to the same attribute, the last overrides
all previous settings.
Tip
The COLUMN command formats all displayed attributes of the same name in all tables. When
selecting columns of the same name from multiple tables, avoid confusion by assigning an
attribute label to at least one of them in the SELECT statement that uses the COLUMN setting.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
attribute_name Specifies the attribute to format.
expression Any combination of attribute names, constants, arithmetic
operators, and UniData SQL functions that together select
attributes to be associated with display formats. Expressions that
contain spaces must be enclosed in quotation marks. expression
must be defined the same way as in the SELECT statement.
Keywords must be entered uppercase even if they were lowercase
in the SELECT statement.
ALIAS alias Assigns an alias to expression or attribute_spec. You may use this
alias in expression or attribute_spec anywhere in the statement;
however, alias must be defined for each statement.
CLEAR Removes the column definition for expression or attribute_spec.
DEFAULT Resets the column definition to default settings, including PRINT
ON and WRAP ON.
FORMAT column_format Formats values displayed in this column. For information on these
options, see “column_format Options” following this table.
HEADING "text" Assigns a column heading. The default column heading is the
attribute name or the expression itself. Enclose text within
quotation marks if it contains spaces or special characters. If the
text contains HEADSEP, the column heading is displayed over
multiple lines.
COLUMN Parameters
Parameter Description
JUSTIFY Aligns the column heading. HEADING must be specified to use
JUSTIFY.
• LEFT – Left-align column heading.
• CENTER – Center column heading.
• RIGHT – Align column heading at right column margin.
LIKE “expression” Copies the COLUMN specification of another column, or as
LIKE attribute_label defined in expression. LIKE attribute_label copies the display
name of an attribute.
NEWLINE With SET WRAP HORI, starts a new line before displaying the
value of a column. With SET WRAP DEF, switches to vertical
format.
NEW_VALUE new_val Saves the current value of an attribute for use in TTITLE
statements to print a header that reflects current attribute values.
NOPRINT Turns on or off printing column text. The default is PRINT.
PRINT
NULL "text" With null value handling on, the text variable specifies text to be
displayed for the null value. This text overrides the default text
specified in the NULL clause of the SET command, if any. If you
do not specify text for the null value in either the COLUMN
command or the SET command, the null value is represented by
an empty string.
With null value handling off, this keyword has no effect.
OFF Turns COLUMN settings off or on without affecting the settings.
ON The default is ON.
OLD_VALUE old_val Saves the current value of an attribute for use in BTITLE
statements to print a footer that reflects current attribute values.
Parameter Description
SPACE n Places the next column n spaces to the right of the current
position. Defaults to the position established by the SET
command (SET SPACE n).
WRAPPED Specifies wrapping or truncating of column text when text is
WORD_WRAPPED wider than the column.
TRUNCATED • WRAPPED wraps text to the next line; default.
• WORD_WRAPPED wraps text without breaking words.
• TRUNCATED deletes text that does not fit in the column.
no option Displays current column definitions.
column_format Options
column_format specifies the display format for values in the column. column_format must be
enclosed in quotation marks, and can be one of the following:
• Character Format Options – The format for a character string is An where n is the column
width. The default is the length specified in the dictionary definition of the attribute.
• Date Format Options – You cannot specify format options for date attributes; the
formatting specified in the dictionary definition of the attribute is used.
• Numeric Format Options – Use the options in the following table to build a display mask
for formatting numeric values.
Example
Option Explanation
of Mask
9 Represents one numeric display 9999
position.
0 Display leading zeros. 0999
Example
Option Explanation
of Mask
$ Prefix a dollar sign before the $9999
displayed value.
B Print leading zeros as blank. B999
MI Display minus sign (-) after a nega- 9999MI
tive value.
PR Display a negative value in angle 9999PR
brackets
. Align on the decimal point. 99.99
, Insert a comma where placed in the 99,999
mask.
V Multiply the value by the n power of 999V99
10, where n is the number of 9s after
V.
EEEE Display the scientific notation (the 9.99EEEE
format must contain four Es).
Examples
The following COLUMN statement skips a line after ORD_TIME is displayed, and presents the
data in vertical format:
Screen Example
The following output is produced when you select ORD_TIME after executing the above
COLUMN command:
Screen Example
Next, we clear the COLUMN setting and execute the same SELECT statement:
Screen Example
The same attributes are displayed as in the preceding example, but no lines are skipped:
Screen Example
Page 1
Order Order
Date Time
---------- -------
01/13/1996 12:30PM
09/28/1995 04:34PM
01/14/1996 03:00PM
10/05/1995 11:11AM
01/24/1996 03:09PM
01/15/1996 10:00AM
12/04/1995 09:45AM
01/24/1996 03:27PM
12/13/1995 12:51PM
...
Enter <New line> to continue...Q
COMMIT
Syntax
COMMIT [WORK]
Description
The UniData SQL COMMIT command concludes an active transaction. The optional keyword
WORK is provided for backward compatibility.
Note
COMMIT is a transaction processing (TP) command. The Recoverable File System (RFS) must be
in use for transaction processing to work. In the absence of RFS, TP commands are ignored.
UniData for Windows NT or Windows 2000 does not support RFS.
If you execute the COMMIT command in a non-RFS environment, UniData does not issue an
error message, but the command does not perform the expected function.
If a COMMIT command executes without an active transaction, UniData SQL displays the
following error message:
Invalid transaction termination: no active transaction.
Value Description
0 The commit completed successfully.
1 Transaction not started.
3 Transaction cannot commit.
COMO
Syntax
COMO option filename
Description
The COMO command saves the history of a user session. When you open a COMO file, UniData
SQL stores all terminal input and output in the UniData SQL DIR-type table, _PH_, in the file
O_filename (O_filename is a UNIX sequential file).
To specify a COMO file name that is not SQL compliant, enclose the file name in quotation marks,
as shown in the following statement: COMO ON “file.name”.
Tip
COMO files grow very quickly. Informix recommends that you periodically review and delete
unused COMO files.
option Values
The following options are valid for use with COMO.
Option Description
ON Opens a new COMO output file. If filename exists, con-
tents are overwritten.
OFF Closes the COMO file and stops capturing terminal dis-
play.
SPOOL Sends a copy of a selected COMO file to the printer.
DELETE Deletes the specified COMO file from the _PH_ table.
COMO Options
Option Description
LIST Lists all the COMO files in the _PH_ table.
APPEND Appends terminal display to an existing COMO file.
Examples
Note
The following examples show the COMO file name as it appears in UniData for UNIX. If you are
using UniData for Windows NT or Windows 2000, you would see the full path for the COMO file
(such as D:\UniData52\demo\_PH_\O_SAVESQL).
The following example demonstrates creating a COMO file, executing a command, and closing
the COMO file:
Screen Example
INVENTORY 56060
Inventory Date 01/11/1996
Inventory Time 12:00PM
Product Name Trackball
Features Super Deluxe Model
INVENTORY 57030
Inventory Date 12/15/1995
Inventory Time 05:34PM
Product Name Scanner
Enter <New line> to continue...Q
sql> COMO OFF SAVESQL;
_PH_/O_SAVESQL closed
The next example shows the contents of the COMO file SAVESQL.
Screen Example
/usr/ud52/_PH_/O_SAVESQL established
sql> SELECT * FROM INVENTORY;
Page 1
INVENTORY 53050
Inventory Date 01/09/1996
Inventory Time 08:00AM
Product Name Photocopier
Features Personal Photocopier
Color Quanti Price Reorde
---------- ------ ---------- ------
Beige 785 $369.95 50
INVENTORY 56060
Inventory Date 01/11/1996
Inventory Time 12:00PM
Product Name Trackball
Features Super Deluxe Model
Color Quanti Price Reorde
---------- ------ ---------- ------
Gray 494 $98.99 70
INVENTORY 57030
Inventory Date 12/15/1995
Inventory Time 05:34PM
Product Name Scanner
COMPUTE
Syntax
COMPUTE {AVG | COUNT | MAX | MIN | NUMBER | STD | SUM | VARIANCE...}
OF {expression | attribute_name}...
ON {expression | attribute_ name | REPORT | ROW...}
Description
The COMPUTE command performs computations on groups of data selected by a SELECT
statement. You may apply multiple COMPUTE commands to the same column.
To activate options set with COMPUTE, you must subsequently execute the BREAK command
and specify the same ‘ON’ condition as in the COMPUTE statement. You must also display the
BREAK attribute for COMPUTE to take effect. When the break (change in data value) occurs,
UniData SQL performs the calculations specified by the COMPUTE statement.
Tip
Use ORDER BY in the SELECT statement that uses the COMPUTE settings to order the rows in
the correct sequence.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
AVG Computes the average value. Valid for numeric data.
COUNT Counts the number of values in a row. Valid for all data
types. UniData SQL does not count the null value.
MAX Finds the largest value. Valid for numeric and character
type data.
MIN Finds the smallest value. Valid for numeric and
character type data.
NUMBER Counts the number of records in a table. Valid for all
data types and the null value.
STD Computes the standard deviation. Valid for numeric
data.
SUM Computes the sum of the values. Valid for numeric data.
VARIANCE Computes the variance. Valid for numeric data.
OF Specifies expression or attribute_name to use in
expression computations. Settings made in the COMPUTE
attribute_name statement execute when you select this specified
attribute or expression in subsequent SELECT
statements.
Tip - To perform computations using an attribute
without printing the result, execute the NOPRINT
option in the COLUMN command against that
attribute_name.
COMPUTE Parameters
Parameter Description
ON Specifies expression or attribute_name to compute on.
expression For a computation and break to occur on an attribute,
attribute_name you must also specify attribute_name in a BREAK
command. When the break (change in data value)
occurs, UniData SQL executes COMPUTE command
computations.
REPORT Prints the result of computations at the end of the report.
ROW Prints the result of computations and restart the
computation for each row.
Examples
The following example demonstrates the use of COMPUTE to obtain the average price of all items
in the ORDERS file:
Screen Example
The next example demonstrates using the COMPUTE command to obtain daily sales totals:
Screen Example
The final example shows a partial listing of the output produced by these statements:
Screen Example
Page 1
Order Client
Placed On: ORDERS Number Product Nu Qty Price
---------- ---------- ---------- ---------- ------ ----------
01/01/1968 804 9967 11100 1 $139.86
11120 2 $14.97
11130 1 $49.97
11140 1 $149.97
10050 1 $29.97
********** ----------
sum $384.74
CREATE INDEX
Syntax
CREATE INDEX index_name ON table_name (attribute_name)
Description
The UniData SQL CREATE INDEX command creates an alternate key index on attribute_name
in the table specified by table_name. The UniData SQL CREATE INDEX command also builds
the index with data from the table being indexed.
Reminder
The UniData SQL CREATE INDEX command performs the functions of both ECL commands
CREATE.INDEX and BUILD.INDEX.
The greater the number of records, the more an index reduces access time. In a table containing a
large number of records, an index significantly reduces the amount of time required for a SELECT
to display data (providing the SELECT statement has a search condition that takes advantage of
the index).
The alternate key attribute, designated by attribute_name, may be any D-type singlevalued or
multivalued attribute, virtual attribute, or may be a phrase that contains only one attribute. For
indexes based on virtual attributes, index_name must be the same as attribute_name. You can
create indexes on different attributes in one data table; however, you cannot create more than one
index on a single attribute.
When you create the first index for a table, UniData SQL prompts you to enter a length for the
alternate key.
Note
CREATE INDEX does not check the data for duplicate records. To check for duplicate records
when creating an index, use the ECL command CREATE.INDEX.
Tip
Allocate a length that will accommodate the longest value in all attributes to be indexed. An
adequate key length makes the index efficient but does not prevent it from accepting longer values.
Maximum key length is 1020 plus the number you assign. The default key length is 20.
Examples
The following example demonstrate creating an alternate key index for the INVENTORY table on
the attribute PROD_NAME. The new index is named PROD_IDX. Because this is the first index
to be created on INVENTORY, the user is prompted for alternate key length.
Screen Example
The next example demonstrates creating an index, then using it to decrease the length of time
required to access data when a SELECT is performed on the indexed field. Without an index on
CLIENT_NO, the same SELECT statement might take several times longer to retrieve the data.
Screen Example
CREATE SUBTABLE
Syntax
CREATE SUBTABLE subtable_name [(attribute_subtable_name [,attribute_subtable_name]...)]
AS SELECT query_spec
[PRIMARY KEY attribute_name[,attribute_name]...]
[FOREIGN KEY attribute_name[,attribute_name]...
REFERENCES subtable_name]
Description
The CREATE SUBTABLE command creates a UniData SQL view that presents values from the
base table in such a way that those values can be viewed and updated using 1NF ANSI-standard
SQL Data Manipulation Language (DML) commands. This enables you to update data in UniData
SQL base tables using desktop tools that access these subtables through UniData ODBC.
Subtable Requirements
To represent the three nested levels of data within UniData SQL tables (singlevalued, multivalued,
and multi-subvalued), you must create three subtables: one for each nested level. The nested levels
are referred to as NL0, NL1, and NL2.
• NL0 subtable represents singlevalued attributes.
• NL1 subtable represents multivalued attributes. All multivalued attributes must be in the
same association.
• NL2 subtable represents multi-subvalued attributes. All multi-subvalued attributes must
be in the same association.
These subtables are linked through primary and foreign keys.
Reminder
You cannot create a single subtable that contains attributes from different associations or that
combine more than one value type—such as combining multivalued and multi-subvalued
attributes. If you do, UniData returns an error message indicating the type of error, such as: a
subtable cannot contain both ‘MV’ and ‘MS’ attributes. (Note that the foreign key, which
is the primary key of the subtable or table at the next-higher level, is the only exception to this
rule.)
Key Subtable
Type NL0 NL1 NL2
Primary 1S 1 S, 1 MV 1 S, 1 MV, 1 MS
Foreign n/a 1S 1 S, 1 MV
Note
If you create an NL1 subtable without a primary key and later decide you want to create an NL2
subtable, you must drop the NL1 subtable and create an NL1 subtable with a primary key. After
this, you can create an NL2 subtable that references the primary key in the NL1 subtable.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
subtable_name Specifies the name of the new subtable. Subtable names
can contain alphabetic characters, numbers, or the
underscore character. ODBC prohibits the use of other
special characters.
The following restrictions apply to subtable names:
• The first character of the name cannot be a number.
• The subtable name must be unique among tables,
subtables, and views in the database.
• The maximum length of a subtable name is 30
characters.
attribute_subtable_name The name to be used for the attribute in this subtable. If
you rename one attribute, you must list all attributes, even
if you use the attribute name from the base table. You must
rename attributes when an expression is included in
query_spec.
AS SELECT query_spec Selects data to include in the subtable. query_spec is
defined in the SELECT statement section of this manual.
Note - You must unnest nested attributes to create a
subtable through which you can update the base table.
Note - The SELECT clause cannot contain more than 255
virtual attributes.
PRIMARY KEY attribute_name One or more attributes to use as the primary key for this
subtable. If you rename an attribute (see the preceding
description for attribute_subtable_name), you must use the
new name here.
Parameter Description
FOREIGN KEY attribute_name One or more attributes to use as the foreign key for this
subtable. The foreign key refers to the primary key of a
subtable one nested level higher. If you rename an attribute
(see renamed_attribute, above), you must use the new
name here.
REFERENCES subtable_name The corresponding subtable name, one nested level higher.
The subtable name contains, as a primary key, the
attribute_names listed in the FOREIGN KEY clause of
this statement.
Examples
Unique Key Subtable
The following statement creates an NL0 subtable that specifies a unique primary key. It does not
rename any attributes, but uses attribute names from the dictionary of the CLIENTS table. Notice
that the alias ID is used instead of @ID so that the subtable is ODBC accessible. Also, this NL0
subtable contains only singlevalued attributes from the CLIENTS base table.
Screen Example
Screen Example
Client # 9966
First Name Phil
Last Name Becker
Company Name Travelbooks, Inc.
City Hawthorn
State/Territory Vict.
...
Unnesting
The following statement creates an NL1 subtable that is associated by foreign key to
CLIENTS_NL0, which we just created:
Program Example
Screen Example
Screen Example
The following SELECT statement lists the contents of this new subtable:
Screen Example
The next example demonstrates creating the NL1 subtable. Notice that multivalued attributes are
selected and unnested in the subtable.
Screen Example
The following SELECT statement displays the (unnested) multivalued table, ORDER_NL1:
Screen Example
The next example demonsrates creating the NL2 subtable, which unnests the multi-subvalued
attributes:
Screen Example
Screen Example
CREATE TABLE
Syntax
CREATE TABLE table_name
(attribute_definition[,attribute_definition]...)
[MODULO modulo_number]
[DYNAMIC [KEYONLY | KEYDATA]]
[TRANSACTION | RECOVERABLE]
attribute_definition syntax:
attribute_name
{CHAR(size[,“conv_code”])
| DATE[({“date_conv” | “time_conv”})]
| NUMBER[({size | size,n | *}[,“conv_code”])]
| LONG]
[IDESC | VIRTUAL (“virt_definition”)]
[LOC(n)]
[DISP(“display_name”)]
[FORMAT(“fmt_desc”)]
[SM(“{S | MV | MS}”)]
[ASSOC(“assoc_name”)]
Description
The CREATE TABLE command performs two functions:
• Creates a new base table in your database.
• Stores the attribute definitions in the table’s dictionary.
UniData SQL automatically creates the singlevalued attribute @ID at location 0; the display name
is the name of the table, the format is 10L, indicating a character attribute 10 characters long, and
it is left-justified.
attribute_definition is explained in “Appendix A - Defining Attributes.”
Note
If quotation marks are included in the definition, use single quotation marks in embedded
definitions; for example: “TRANS(‘clients’,client_nbr, ‘client’,‘X’)”.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
table_name Specifies the name of the new table. Valid table names
can contain alphabetic characters, numbers, and the
following special characters: “_”, “@”, “#”, and “$”.
Note - If you plan to access the data in a table,
subtable, or view via ODBC, do not use @, #, or $
anywhere in the table name, and do not use an
underscore (_) as the first character.
The following restrictions apply to table names:
• The table name cannot be longer than 30 characters.
• The first character of the name cannot be a number.
• The table name must be unique among tables,
subtables, and views in the database.
• The table name cannot be a UniData SQL reserved
word.
Parameter Description
attribute_definition The following elements make up attribute_definition.
You must include data type immediately after each
attribute name you define. The other elements are
optional and can be entered in any order.
• Attribute name (required)
• Data type (required)
• Location relative to the beginning of the record
• Virtual attribute definition
• Display name
• Format description
• Value type specification (Default is singlevalued –
S)
• Association name
Note - System default format and conversion are
assigned based on data type when neither is specified.
These defaults are provided in the data type sections
of “Appendix A - Defining Attributes.”
MODULO no_blocks[, block_size] Controls the size of the table by assigning block size
and number of blocks to store the data.
This syntax is explained in the following section,
“Assigning Modulo.”
DYNAMIC Creates a dynamic table. For further information on
dynamic tables, see Administering UniData.
KEYONLY Used only with the DYNAMIC keyword. Sets the
split/merge type for a dynamic file to KEYONLY,
meaning that the load factor in each group is based on
keys and pointers only. This is the default split/merge
type.
Parameter Description
KEYDATA Used only with DYNAMIC keyword. Sets the
split/merge type for a dynamic file to KEYDATA,
meaning that the load factor in each group is based on
keys and pointers plus data.
For further information about split/merge types, see
the UniData Commands Reference manual.
TRANSACTION Creates a recoverable table. TRANSACTION and
RECOVERABLE RECOVERABLE are synonyms. For further
information on recoverable tables, see Administering
the Recoverable File System.
Assigning Modulo
UniData SQL reserves space on the disk to be used for the table based on the modulo number,
which determines the size of the table by assigning a specific number of blocks to store the data as
well as the size of the blocks. The default modulo is 1 for static files, and 3 for dynamic files.
Setting the modulo properly minimizes system overhead in the future. The purpose of deciding on
the “best” modulo number is to cause UniData SQL to allocate the appropriate number of blocks
of disk space when the table is created.
If you set modulo too small and the table becomes very large, the system has to handle the
overflow of newly inserted data at that time, which is very inefficient. Table access (SELECT,
UPDATE, etc.) will be slower than if the table had been properly sized.
There are two kinds of overflow: Level-1 and Level-2. Static hashed tables created with too small
of a modulo experience Level-2 overflow as they become larger, and ALTER TABLE MODULO
can correct the problem. Dynamic tables adjust their own modulo automatically as the table
expands and contracts. For further information on UniData SQL file types, see Administering
UniData.
Syntax:
MODULO no_blocks[, block_size]
Parameters
The following table describes each parameter of the syntax.
Parameter Description
no_blocks Numbers of blocks required to store the data; must be
a prime number. (Also controls data hashing.)
, block_size_multiplier A number, 1–16, multiplied by 1024, indicating block
size (or 0, indicating a block size of 512). Default
block size is usually 1024 bytes, although it may be
configured. For further information, see your system
administrator .
0 – UniData SQL assigns the smallest block size, 512
bytes.
>16 – UniData SQL interprets as 16.
<1 – UniData SQL interprets as 0.
MODULO Parameters
The Procedure
Follow the steps outlined below to determine MODULO setting:
1. Determine the block size. Choose a larger block size for tables that store very long records or a
large number of records.
2. Calculate the average number of records stored in one block.
records per block=(block_size - 32)/(avg. record length + 9)
avg. record length is the estimated average length of the records you plan to store in the table.
Tip
The FILE.STAT command reports the average number of bytes in a record.
3. Divide the estimated number of records you plan to store in the table by the records per block
number.
no. of records/records per block
4. Round up the results to the closest prime number. This is no_blocks, the minimum number of
blocks your table must have.
Tip
Use the ECL command PRIMENUMBER to obtain the prime number closest to the number you
calculate.
Examples
The following statement creates a table, NEW_TAB, that has three attributes: one character and
two numeric. The numeric attribute MONEY_FLD contains a conversion code that formats dollars
with two decimal places, preceding negative numbers with a minus sign (-).
Screen Example
The following example lists the dictionary entry for this table:
Screen Example
Page 1
@ID TYP LOC CONV NAME FORMAT SM ASSOC
--------------- --- ------------- ---- --------------- ------ -- ----------
@ID D 0 NEW_TAB 10L S
NUM_FLD D 1 10R S
CHAR_FLD D 2 10L S
MONEY_FLD D 3 MD2$ 10R S
,-
4 records listed
The next statement creates a table that has the following attributes:
• CHAR_FLD – data type character, length of 5
• DATE_FLD – data type date, formatted as mm/dd/yy
• NUM_FLD – data type numeric, formatted with preceding dollar sign; including two
decimal places
• CHAR2_FLD – data type character, length of 12, centered within a column 25 characters
wide
Screen Example
The following example creates a table that contains a virtual field, VIRT_FLD, which displays the
results of multiplying NUM_FLD and MONEY_FLD:
Screen Example
CREATE VIEW
Syntax
CREATE VIEW view_name
[(view_attribute_name [,view_attribute_name...])]
AS SELECT query_spec
Description
The CREATE VIEW command defines a view of base tables or existing views. You can update a
base table through a view in UniData SQL unless the view was created by a join.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
view_name Specifies the name of the new view. View names may contain
alphabetic characters, numbers and the underscore character.
ODBC prohibits the use of other special characters.
The following restrictions apply to view names:
• The first character of the name may not be a number.
• The view name must be unique among tables, subtables, and
views in the database.
• The maximum length of the view name is 30 characters.
Parameter Description
view_attribute_name Specifies a name for the attribute in the new view. The first
character must be an alphabetic character or underscore (_).
Consists of the following elements:
• Alphabetic characters
• Numbers
Note - The number of attribute_names in CREATE VIEW must be
the same as the number of attribute_names or expressions in the
SELECT clause.
AS SELECT query_spec Selects data to include in the view. query_spec is defined in the
SELECT statement section of this manual.
Example
The following example creates a view that includes all products of colors that begin with the letter
B. The subsequent SELECT statement displays part of the data retrieved by that view.
Screen Example
Page 1
Product Product
Number Name Color
---------- ---------- ----------
39400 CD Player Black
30000 CD System Black
1
37000 CD System Black
10
38000 CD System Black
11
39000 CD System Blue
12
31000 CD System Black
2
...
Brown
10040 Camcorder Black
Bag
Brown
...
58040 Monitor Beige
58050 Monitor Beige
56070 Mouse Pad Blue
40008 Telephone Burgundy
Black
...
96 records listed
DELETE
Syntax
DELETE FROM table_spec [table_label] [ID_list]
[WHERE search_condition]
Description
The DELETE command eliminates records from a table, subtable, or view. If no search_condition
is specified, but an ID_list is present, all records in the ID_list are deleted.
Warning
If search_condition and ID_list are not specified, all records in the table are deleted.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
FROM table_spec Specifies the table, subtable, or view from which records are to be
deleted.
table_label Specifies an alias for a table from which records are to be deleted.
ID_list Limits search_condition to only those records whose ID or key is listed in
ID_list. ID_list may be applied to a base table only, not to a view or
subtable.
DELETE Parameters
Parameter Description
WHERE Selects records to delete. If search_condition is applied to:
search_condition • A singlevalued attribute, UniData SQL deletes the entire record.
• A multivalued attribute, UniData SQL deletes all values that meet the
criteria. However, even if all values in the multivalued attribute are
deleted, values in singlevalued attributes of the same record remain.
• A multi-subvalued attribute, UniData SQL deletes all values that meet
the criteria. However, even if all values in the multi-subvalued attribute
are deleted, values in multivalued attributes in the same record remain.
Tip - You can delete a record based on WHERE virtual_fld = value.
Note - Within a WHERE clause, the sum total of the individual condi-
tions and the Boolean operators cannot exceed 127.
For information on writing WHERE clauses, see
Using UniData SQL.
Examples
The following example shows how to delete single and multiple attributes:
Screen Example
The following statement deletes all records from the CLIENTS table:
Screen Example
The following example displays the data in the multivalued attribute COLOR before a record is
deleted:
Screen Example
Screen Example
Finally, we execute the same SELECT statement as it was executed before the deletion to
demonstrate the deletion:
Screen Example
DROP INDEX
Syntax
DROP INDEX index_name FROM table_name
Description
The DROP INDEX command deletes the index specified by index_name for table_name. The
index must have been created by:
• UniData SQL CREATE INDEX command.
• ECL CREATE. INDEX command.
Note
Only the owner of a table may drop an index from that table.
Example
The following example demonstrates creating and dropping an index:
Screen Example
DROP SUBTABLE
Syntax
DROP SUBTABLE subtable_name;
Description
The DROP SUBTABLE command drops a subtable that was created by a CREATE SUBTABLE
statement. It also drops all views created on the subtable, but it does not affect the base table.
Dropping a high-level subtable makes invalid all subtables that reference it. So, before you drop a
subtable, be sure to drop all subtables that reference it.
Example
The following example demonstrates creating and dropping a SUBTABLE:
Screen Example
DROP TABLE
Syntax
DROP TABLE table_name
Description
The DROP TABLE command removes a base table from the database, deletes the table definition,
and deletes all subtables and views that are based on the table. Only the person who created a table
can drop it. UniData SQL prompts for confirmation before dropping the table.
Warning
You cannot recover a dropped table.
Example
The following example demonstrates creating a table, listing its dictionary, and deleting the table:
Screen Example
LISTDICT NEW_TAB;
Page 1
@ID TYP LOC CONV NAME FORMAT SM ASSOC
--------------- --- ------------- ---- --------------- ------ -- ----------
@ID D 0 NEW_TAB 10L S
NUM_FLD D 1 10R S
CHAR_FLD D 2 10L S
MONEY_FLD D 3 MD2$ 10R S
,-
4 records listed
DROP VIEW
Syntax
DROP VIEW view_name
Description
The DROP VIEW command removes a view from the database. This command automatically
drops any views that are subordinate to the dropped view. Only the owner of a view can drop it.
Example
The following example demonstrates creating a view, using it, deleting it, and then attempting to
use it after it has been deleted:
Screen Example
Transaction aborted.
EXIT
Syntax
EXIT
Description
The EXIT command quits UniData SQL and returns the cursor to the environment from which
you entered UniData SQL. The EXIT command performs the same function as QUIT. Note that
you do not conclude the EXIT or QUIT command with a semicolon.
Note
If you entered UniData SQL from the ECL prompt, EXIT returns you to the ECL prompt. When
you return to UniData SQL in the same session, your UniData SQL statement stack is restored. If
you entered UniData SQL from the operating system prompt, when you issue the EXIT command,
you return to the operating system prompt and all statement stack contents are lost.
Examples
Screen Example
sql> EXIT
:
GRANT
Syntax
GRANT {ALL PRIVILEGES | privilege[,privilege]...
ON table_spec
TO {PUBLIC | user_name [,user_name]...}
[WITH GRANT OPTION]
Description
The GRANT command specifies access privileges on tables, subtables, and views.
When a user creates a UniData SQL table, subtable, or view, the user owns the object. The owner
is initially the only user who can access the object. If other users need to use the table, subtable, or
view, the owner must grant them rights to access it. These access rights are called privileges. The
owner can add, change, and view privileges for other users.
If the owner grants privileges to another user with grant option, that user can grant any of the same
privileges for the table, subtable, or view to other users.
If you attempt to grant privileges on a table, view, or subtable for which you do not have privi-
leges, or on an object that does not exist, the following error message appears:
Sorry, you have no privilege on this file!
Only the owner can drop tables, subtables, or views, and create and drop indexes.
Tip
To learn who is the owner of a table, execute the UNIX command ls -l filename at the UNIX
prompt. You can also check the contents of the privilege table by executing the following:
Parameters
The following table describes each parameter in the syntax.
Parameter Description
ALL PRIVILEGES Grants all privileges the user of the command is allowed to
grant.
• If the user is the owner of the object, all privileges are
DELETE, INSERT, SELECT, and UPDATE.
• If the user is not the owner of the object, the user can grant
only those privileges acquired with grant option.
privilege Specifies privilege(s) to grant the user(s):
DELETE – Privilege to delete rows from a table, subtable, or
view.
INSERT – Privilege to insert rows in a table, subtable, or view.
SELECT – Privilege to select data in a table, subtable, or view.
UPDATE – Privilege to change values in a table, subtable, or
view.
ON table_spec Specifies the table, subtable, or view on which to grant
privileges.
TO PUBLIC Grants privilege to all users who have access to the server
machine.
TO user_name Grants access to the user specified by user_name.
WITH GRANT OPTION Gives the recipient(s) permission to grant the privileges they
acquired on this table, subtable, or view.
The value of the grant-op attribute of the privilege file can be
either of the following:
• 0 = No grant option specified
• 1 = Grant option specified
GRANT Parameters
Note
UniData SQL does not display a confirmation message when you grant or revoke privileges.
Examples
The following example creates a view on the INVENTORY table, then grants all privileges to
everyone:
Screen Example
Screen Example
INSERT
Syntax
INSERT INTO table_spec [(attribute_name
[, attribute_name...])]
VALUES (const_value [,const_value...])
INSERT INTO table_spec [(attribute_name
[, attribute_name...])]
query_spec
Description
The INSERT command adds rows to an existing table. Rows can be inserted into an empty table
or into a table that already contains data. You cannot insert duplicate values in the @ID attribute.
If conflicting aliases exist for a location of the target table, you must specify attribute_name.
Conflicting aliases have different formats, conversion codes, and so on.
To insert literal numeric or string values, use the first form of the syntax, enclosing string values in
quotation marks. To select data from another table and insert it into a table, use the second form of
the syntax. query_spec is described under SELECT.
If no attribute_names are specified, the query_spec or VALUES list must contain one value for
each data location in the dictionary for that table. The data values are inserted in order of location.
Warning
If two subtables map to the same association, but specify different primary keys, UniData SQL has
no way of ensuring that primary keys are unique. This could result in duplicate values being added
through UPDATE or INSERT, or in more than one row being updated by UPDATE.
Forms of INSERT
A value for @ID is always required. The INSERT statement has two forms:
• An INSERT statement with a VALUES clause inserts one row into a table:
• If attribute_name(s) are specified, the number and data type of attribute_name(s) and
const_value(s) must match.
• The sequence and data type of const_values must match those of the target attributes.
• If an attribute is character or date data type, you enclose the value to be inserted in
quotation marks.
• If you include attribute_name(s), @ID or its alias must be included in the list of
attribute_name(s).
• If the NULL_FLAG is set to 0 (off), the NULL keyword inserts an empty string ("").
• If the NULL_FLAG is set to1 (on), the following rules apply:
–You can use the NULL keyword with the INSERT or UPDATE command to insert
the null value into a singlevalued attribute.
–You can use the NULL keyword with the INSERT or UPDATE command to insert
the null value into a multivalued or multi-subvalued attribute if it is the only
value.
–You cannot use the INSERT or UPDATE command to add the null value along with
other values into a multivalued or multi-subvalued attribute. This is because Uni-
Data SQL cannot recognize the keyword NULL embedded in a quoted string such
as “D|NULL|I”. You must first create the record, then use the UPDATE command
to change existing values to null or to append null values.
–The null value is not valid for @ID.
• Regardless of whether null value handling is on or off, you can insert a missing value
by omitting an attribute’s value in a value list.
• An INSERT statement with a query_spec clause inserts a set of attribute values from one
or more tables into another table:
• The values to be inserted are determined by query_spec.
• If attribute_name(s) are specified, the number and data types must be the same as in
query_spec.
• You cannot insert into the table from which you are selecting attributes in query_spec.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
INTO Required keyword for inserting into a table.
table_spec Specifies the table, subtable, or view to receive inserted data.
attribute_name Specifies the attribute(s) to receive inserted data. If you specify
attribute_names, you must include the @ID or its alias.
attribute_names may be listed in any order; but the values
included in the VALUES list must be listed in the same order.
No duplicate locations or virtual attributes may be included.
VALUES const_value Specifies a constant value to be inserted. Character, date, and time
strings must be enclosed in quotation marks. Enter integer and
decimal values without quotation marks.
May be singlevalued, multivalued, multi-subvalued, or the null
value. A singlevalued constant may be a number or an
alphanumeric string. You cannot add multivalues and multi-
subvalues in the same string.
Note - To insert more than one value in a multivalued or multi-
subvalued attribute, you must enclose them in quotation marks
even if the data values are numeric; you must also include the
correct delimiter.
INSERT Parameters
Parameter Description
query_spec For a complete description of query_spec, see the SELECT
command.
Note - You cannot include a phrase in the expression included in
query_spec. Doing so results in a UniData SQL error.
You can include subqueries in query_spec.
Examples
The following statement inserts a new inventory item into the INVENTORY table. A value must
be included for each attribute because no attribute_name list is included.
Screen Example
The following example inserts a new record, 19999, into the INVENTORY table. No value is
entered for PROD_NAME, INV_DATE, or INV_TIME, so these attributes are assigned no values.
Screen Example
sql> INSERT INTO INVENTORY (ID, FEATURES, COLOR, QTY, PRICE, REORDER)
VALUES (19999, "133 MHz CPU, 25-in. SVGA Monitor, Keyboard, Mouse,
Microsoft Office", "Black", 50, 1000.00, 10);
1 record(s) created.
Features 133 MHz CPU, 25-in. SVGA Monitor, Keyboard, Mouse, Microsoft
Office
Color Quanti Price Reorde
---------- ------ ---------- ------
Black 50 $1,000.00 10
1 records listed
LISTDICT
Syntax
LISTDICT table_spec
Description
The LISTDICT command lists the dictionary of a UniData SQL table. table_spec specifies the
table, subtable, or view for which to list the dictionary.
Example
The following example lists the dictionary for the CLIENTS table:
Screen Example
sql> LISTDICT;
Page 1
@ID TYP LOC CONV NAME FORMAT SM ASSOC
--------------- --- ------------- ---- --------------- ------ -- ----------
@ID D 0 CLIENTS 10L S
ID D 0 Client # 10R S
FNAME D 1 First Name 15T S
LNAME D 2 Last Name 15T S
COMPANY D 3 Company Name 30T S
ADDRESS D 4 Address 25T MV
CITY D 5 City 15T S
STATE D 6 State/Territory 15T S
ZIP_CODE D 7 Postal Code 10R S
COUNTRY D 8 Country 15T S
PHONE_NUM D 9 Phone Number 14R MV PHONE_ITEM
S
PHONE_TYPE D 10 Phone Category 10T MV PHONE_ITEM
S
LOCK TABLE
Syntax
LOCK TABLE table_name [,table_name...]
IN {SHARE | EXCLUSIVE} MODE [NOWAIT]
Description
LOCK TABLE overrides UniData’s automatic locking system, providing a means of explicitly
controlling the locking of tables. LOCK TABLE is the only UniData SQL command that explicitly
locks tables. For an explanation of the UniData locking scheme, see Administering UniData.
Examples of situations in which you should use LOCK TABLE:
• A transaction accesses many files, but you need to isolate only one key file from other
transactions. LOCK TABLE allows you to specify a lower-level isolation (such as RC) for
a transaction, while locking a file at a higher level.
• An application may eventually lock almost all records in a file. UniData SQL locks
records as they are needed, then converts to a file lock when the maximum number of
record locks is reached. This can result in a deadlock. To avoid this, use LOCK TABLE to
lock the file at the beginning of the application.
• A batch process that updates records.
When LOCK TABLE is issued and no transaction is active, UniData SQL starts a new transaction.
Upon termination of the transaction, all locks are released.
When an application requests a file lock against records that are already locked by another user,
the application waits until the locks are released. This can appear to be a system or terminal hang
to the user. Include the NOWAIT keyword to avoid this.
UniData SQL allows a maximum of 128 files to be locked within a transaction, including system-
imposed locks as well as those you set explicitly.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
table_name Specifies the table to be locked.
IN SHARE MODE Indicates that a shared lock is to be placed on the table.
IN EXCLUSIVE MODE Indicates that an exclusive lock is to be placed on the
table.
NOWAIT Directs UniData SQL to abort the transaction rather
than wait for a lock to be released.
Note - If you do specify NOWAIT and include several
files in single LOCK TABLE command, and any one of
the files is already locked, the command fails.
QUIT
Syntax
QUIT
Description
The QUIT command exits UniData SQL unconditionally and returns the user to the environment
from which that user entered UniData SQL. QUIT performs the same function as EXIT. Notice
that the EXIT and QUIT commands do not include semicolons.
Note
If you enter UniData SQL from the ECL prompt, QUIT returns you to the ECL prompt. If you
return to UniData SQL in the same session, your UniData SQL statement stack is saved. If you
enter SQL from the operating system prompt, QUIT returns you to the operating system prompt,
and the UniData SQL statement stack is lost.
Example
Screen Example
sql> QUIT
:
REVOKE
Syntax
REVOKE {ALL PRIVILEGES | privilege[,privilege]...}
ON table_spec
FROM {PUBLIC | user_name[, user_name]...}
Description
The REVOKE command removes access to tables, subtables, or views for which privilege was
granted with the GRANT command. The REVOKE command enables you to revoke privileges for
specific users or for all users.
Note
If you want to revoke only the ability to grant options, you must REVOKE the privilege first, then
grant the privilege without grant option.
Cascading of REVOKE
When you revoke privileges for a user, any assignment that user has made is also revoked, as
illustrated by the following scenario:
User A owns TABLE_A and grants SELECT privilege (with grant option) on TABLE A to user B.
Then, user B grants SELECT privilege on the table to user C. If user A revokes the SELECT
privilege on TABLE_A from user B, it is automatically revoked for user C.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
ALL PRIVILEGES Revokes all privileges the user of the command possesses.
If the user is the owner of the object, all privileges are DELETE,
INSERT, SELECT, and UPDATE.
privilege Specifies privilege(s) to revoke:
DELETE – Privilege to delete rows from a table or subtable.
INSERT – Privilege to insert rows in a table or subtable.
SELECT – Privilege to select data in a table, subtable, or view.
UPDATE – Privilege to change values in a table or subtable.
ON table_spec Specifies the table, subtable, or view for which privileges are to
be revoked.
FROM Identifies the user for whom privileges are to be revoked.
PUBLIC Revokes specified privileges for all users with access to the
server machine.
user_name Revokes specified privileges for the user indicated by user_name.
REVOKE Parameters
Example
Screen Example
Note
UniData SQL does not display a confirmation message when you grant or revoke privileges.
ROLLBACK
Syntax
ROLLBACK [WORK]
Description
The UniData SQL ROLLBACK command cancels an active transaction. UniData SQL discards
pending writes and releases all locks acquired during the transaction. The optional keyword
WORK is provided for backward compatibility with legacy systems.
With the ROLLBACK command, UniData undoes all commands issued from the beginning of the
transaction and does not make any updates for the transaction.
Note
ROLLBACK is a transaction processing (TP) command. The Recoverable File System (RFS)
must be in use for transaction processing to work. In the absence of RFS, TP commands are
ignored. UniData for Windows NT or Windows 2000 does not support RFS.
If you execute the ROLLBACK command in a non-RFS environment, UniData does not issue an
error message, but the command does not perform the expected function.
Not all rollbacks are user-initiated. In addition to your ability to explicity execute the ROLLBACK
command in an application program, UniData can automatically roll back a transaction when it
encounters any of the following conditions:
• File-access errors (such as no privilege or violation of operation system–level security).
• Locking errors, such as deadlocks.
• Invalid command or invalid command syntax.
SELECT
Syntax
Query Specification (query_spec):
SELECT [ ALL | DISTINCT ] { * | { attribute_spec | expression} [ attribute_label ]
[ , {attribute_spec | expression} [ attribute_label ] ...] }
FROM table_spec [ table_label ] [ ID_list ]
[ [ INNER | { LEFT | RIGHT | FULL } [ OUTER ] ]
JOIN table_spec [ table_label ] [ ID_list ]
{ ON search_condition | USING ( attribute_name [ , attribute_name ...] ) } ...]
[ , table_spec [ table_label ] [ ID_list]
[ [ INNER | { LEFT | RIGHT | FULL } [ OUTER ] ]
JOIN table_spec [ table_label ] [ ID_list ]
{ ON search_condition | USING ( attribute_name [ , attribute_name ...] ) } ...] ...]
[ UNNEST [ NL1 | NL2 | NL_ALL ] { association_name | attribute_name}
[ , {association_name | attribute_name} ...] ]
[ WHERE search_condition]
[ GROUP BY { attribute_name | expression}
[ , { attribute_name | expression } ...]
[ HAVING condition ] ]
Select Statement (select_stmt):
query_spec
[ UNION query_spec ...]
[ ORDER BY { attribute_spec | ordinal_position | expression } [ ASC | DESC ] [ EXP ]
[ , {attribute_spec | ordinal position} [ ASC | DESC ] [ EXP ] ...] ]
[ TO filename | INTO temp_table | LPTR ]
Description
The SELECT command retrieves data from the database. A select statement (select_stmt) consists
of a query specification (query_spec), plus (optionally) one or more UNION clauses, ORDER BY
clauses and/or one of the following: TO, INTO, or LPTR. select_stmt and query_spec are also
clauses in some other statements, including CREATE SUBTABLE, CREATE VIEW, and
INSERT.
The keywords SELECT and FROM are required; all other keywords are optional. All keywords
must be used in the order they are listed in the above syntax. The required clauses provide the
following information:
• The SELECT clause tells UniData SQL what information to retrieve.
• The FROM clause tells UniData SQL where to find the information to retrieve.
In a SELECT statement, you cannot select more than 1000 attributes and expressions.
A SELECT statement or clause cannot contain more than 255 virtual attributes.
query_spec Parameters
The following table describes each parameter of the syntax.
Parameter Description
ALL Default. Returns every row selected by query_spec, including
duplicate rows.
DISTINCT Returns every unique row selected by query_spec. Duplicates are
filtered out.
query_spec Parameters
Parameter Description
* Selects all D-type attributes. Does not retrieve virtual fields. You
may not include attribute_name or expression with *. May be
qualified by a table name or table label by preceding the attribute
name with the table name/label and a period, as follows:
• table_name.*
• table_label.*
attribute_spec Specifies one or more attributes to retrieve. May be qualified by
preceding the attribute name with the table name/label and a
period, as follows:
• table_name.attribute_name
• table_label.attribute_name
Note - To select virtual fields, you must explicitly name them.
expression Any combination of attribute names, constants, arithmetic
operators, and UniData SQL functions that together select data.
Expressions that contain spaces must be enclosed in quotation
marks.
For information on writing expressions, including the operators
and functions you can use, see Using UniData SQL.
attribute_label Specifies the display name for an attribute. Display names are
used as column headers.
FROM Directs UniData SQL to the tables where the attribute_names are
stored. The FROM clause is a required element of the SELECT
statement. UniData SQL allows you to query multiple tables and
views in a single statement.
table_spec Specifies the table, subtable, or view from which data values are
selected.
table_label Specifies an alias for a table.
ID_list Restricts record selection to records with record IDs in ID_list.
Parameter Description
INNER Use in conjunction with the JOIN keyword. Performs an inner
join of the tables included in the FROM clause. Retrieves only
rows that meet the join condition. Therefore, rows in the result
set have matching values in the attributes on which the join is
based.
Parameter Description
{LEFT | RIGHT | FULL} Use in conjunction with the JOIN keyword. Performs an outer
[OUTER] join of the tables included in the FROM clause.
Retrieves all rows that meet the join criteria, but it also retrieves
additional unmatched rows based on whether it is a left or right
outer join. These additional rows come from the left (the table
preceding the JOIN keyword), right (the table following the
JOIN keyword), or both tables. The keywords refer to the
following:
LEFT – A left outer join retrieves all rows from the left table (the
table preceding the JOIN keyword), including those for which no
matching value exists in the joined table. In addition, it includes
rows for which values in the attributes match (these are the same
rows included in the inner join). Finally, it places null values in
all columns of the result table that come from the right table for
all unmatched rows.
RIGHT – A right outer join retrieves all rows from the right table
(the table preceding the JOIN keyword), including those for
which no matching value exists in the joined table. In addition, it
includes rows for which values in the attributes match (these are
the same rows included in the inner join.) Finally, it places null
values in all columns of the result table that come from the left
table for all unmatched rows.
FULL – A full outer join retrieves all rows from both tables
listed in the JOIN clause, combining the results from the left and
right outer joins. Therefore, all rows from both tables are
included, and those for which the attributes match are combined.
Finally, it places null values in all columns of the result table for
all unmatched rows.
OUTER – Optional keyword to specify an outer join (LEFT,
RIGHT, and FULL keywords produce outer joins).
For examples of LEFT RIGHT and FULL OUTER joins, see
Using UniData SQL.
Parameter Description
JOIN Indicates that a table or tables are being joined. If you include
JOIN, you must also include ON or USING.
A join uses data from one attribute to obtain data from another.
For instructions on joining tables, see Using UniData SQL.
ON search_condition Use in conjunction with the JOIN keyword. The conditional test
that selects records for the join.
Warning - If you mention more than one table in a SELECT
statement, but don’t include a join condition, a Cartesian product
results.
USING (attribute_name) Use in conjunction with the JOIN keyword. Specifies the
attribute on which the join is based. Records are selected when
values in the joined attribute from both tables are equal. USING
(attribute_name) produces the same effect as ON
table1.attrib_name = table2.attrib_name.
UNNEST Unnests data stored in multivalued and multi-subvalued
NL1 | NL2 | NL_ALL attributes. Unnesting repeats the values in the associated attribute
one level up. The optional keywords NL1, NL2, or NL_ALL
provide different levels of unnesting. For a description of these
options, see the “UNNEST Options” table in the next section.
The UNNEST clause can process 10,240 values in a multivalued
or multi-subvalued attribute, or in all associations for the
unnested record.
attribute_name Specifies an attribute to unnest.
association_name Specifies an association to unnest. Unnests all associated
attributes that are selected from the named association.
Parameter Description
WHERE search_condition Returns values that meet the criteria specified in
search_condition. WHERE evaluates multivalues and multi-
subvalues individually, as if they had been unnested.
search_condition takes the form:
attribute_name/expression rel_op attribute_name/expression
The following keywords and operators can be used in the
WHERE clause:
=, !=, <, <=, >, >=, <>, !<, !>
ALL
EVERY
subquery
NOT
IS [ NOT ] NULL
[ NOT ] BETWEEN
[ NOT ] IN
[ NOT ] INTERSECT
[ NOT ] LIKE
%, _, ..., nA, nN, nX
AND
OR
For examples that demonstrate the use of these elements, see
Using UniData SQL.
Within a WHERE clause, the total number of predicates and
Boolean operators cannot exceed 127.
GROUP BY Groups information according to attribute_spec or expression in
attribute_spec preparation for computing, breaking, and summarizing by
expression categories.
Parameter Description
HAVING condition Additional criteria that qualifies using aggregate functions.
search_condition. condition takes the form:
attribute_name/expression rel_op attribute_name/expression
For example:
HAVING fld1 = fld2 + 5
Note - rel_op may also be a Boolean operator (AND, OR).
UNNEST Options
All of the multivalued attributes and multi-subvalued attributes included in a single UNNEST
clause must belong to the same association. Executing an UNNEST on unassociated attributes
results in a Cartesian product. UNNEST with no option specified unnests all specified associated
attributes.
Syntax:
UNNEST [NL1 | NL2 | NL_ALL]{mv_attribute | ms_attribute | association_name}
The following table describes the options for the keyword UNNEST.
Option Description
NL1 Specify NL1 to unnest associated multivalued attributes. Repeats
the values in singlevalued attributes.
NL2 Specify NL2 to unnest associated multi-subvalued attributes.
Repeats the values in the associated multivalued attribute.
UNNEST Options
Option Description
NL_ALL Specify NL_ALL to unnest all associated multivalued and multi-
subvalued attributes. Singlevalued attributes are repeated for each
multivalued attribute, and multivalued attributes are repeated for
each multi-subvalued attribute.
NL_ALL has the effect of both NL1 and NL2 combined.
mv_attribute Name of the multivalued attribute to be unnested.
ms_attribute Name of the multi-subvalued attribute to be unnested.
association_name Name of the association to be unnested.
Guide to Unnesting
The following table provides the syntax to unnest to each level. The level of unnesting is
determined by a combination of the UNNEST option and the type of value (S, MV, or MS) of the
attributes involved:
Guide to Unnesting
select_stmt Parameters
The following table describes each parameter of the select_stmt syntax.
Parameter Description
query_spec query_spec is the first required element in the SELECT statement.
query_spec parameters are described in the first table in this
section.
UNION query_spec Combines the results of two query_spec statements into a single
result set. The number of selected items in both queries must be
the same; and the corresponding attributes must be of the same
data type.
Note - When results of all query_spec statements are combined,
duplicate records are discarded.
ORDER BY Arranges rows in sorted order based on attribute value or ordinal
attribute_spec | position. Explanations for attribute_spec and ordinal_position
ordinal_position follow.
Note - The ORDER BY clause may contain no more than nine
attribute names or ordinal positions.
select_stmt Parameters
Parameter Description
attribute_spec Specifies an attribute to use as a sort field. May be an individual
attribute name preceded by the table name/label and a period, as
follows:
• table_name.attribute_name
• table_label.attribute_name
To sort virtual fields, you must explicitly name them.
ordinal_position Arranges rows by the attribute(s) you indicate. Ordinal position is
determined by the order in which attributes and expressions are
listed in query_spec. The first attribute or expression is in ordinal
position 1.
For example, in the following statement:
SELECT ID, PRODUCT_NO, QTY
FROM ORDERS UNNEST PRODUCT_NO
ORDER BY ID, PRODUCT_NO;
the ORDER BY clause could also be written as follows to obtain
the same results:
ORDER BY 1,2
Parameter Description
INTO temp_table Places results of the SELECT in a temporary table.
LPTR Prints results of the SELECT on the system printer.
Examples
Simple Statements
The following example selects all attributes from the CLIENTS table:
Screen Example
CLIENTS 10034
First Name Fredrick
Last Name Anderson
Company Name Otis Concrete
Address 854, rue de Rivoli
City Paris
State/Territory
Postal Code 75008
Page 2
Country France
Phone Number Phone Cate
-------------- ----------
3342482815 Work
3342481924 Fax
CLIENTS 9980
First Name Beverly
Last Name Ostrovich
Company Name Riley Architects
Address 7925 S. Blake St.
City Sydney
State/Territory NSW
Postal Code 0207
Country Australia
Phone Number Phone Cate
-------------- ----------
6124168875 Work
6124168879 Fax
...
130 records listedThe following statement selects the D-type attribute PROD_NAME
and the virtual attribute LINE_ITEMS from the demo table INVENTORY, limiting the
selection to cameras:
Screen Example
Grouping
The following statement selects all rows containing the product name “Camera” from the
INVENTORY table. The query requests the price of the most expensive camera and the total
number of cameras of that color in the database, as well as counting the number of rows containing
each color of camera.
Screen Example
7 records listed
Unnesting
The following examples demonstrate execution of SELECT statements with and without
unnesting. Two records that contain multi-subvalues are used.
Note
More examples of unnesting are provided in “Appendix B - Unnesting Attributes.”
Nested
Screen Example
sql> select ID, CLIENT_NO, PRODUCT_NO, COLOR, QTY, PRICE from ORDERS
where ID = 805;
Page 1
Order Client
Number Number Product Nu Color Qty Price
---------- ---------- ---------- ---------- ------ ----------
805 9987 11140 Gray 5 $149.97
10120 Standard 25 $429.94
10050 Yellow 13 $29.97
10150 Silver 15 $48.82
10070 Silver 999 $34.97
1 records listed
Screen Example
sql> select ID, CLIENT_NO, PRODUCT_NO, COLOR, QTY, PRICE from ORDERS
unnest LINE_ITEMS
where ID = 949 or ID = 969;
Page 1
Order Client
Number Number Product Nu Color Qty Price
---------- ---------- ---------- ---------- ------ ----------
949 9990 56090 Red 3 $12.99
949 9990 56090 Blue 3 $12.99
949 9990 56090 Gray 3 $12.99
949 9990 56070 Red 3 $12.99
949 9990 56070 Blue 3 $12.99
949 9990 56070 Gray 3 $14.99
Screen Example
sql> select ID, CLIENT_NO, PRODUCT_NO, COLOR, QTY, PRICE from ORDERS
unnest NL1 LINE_ITEMS
where ID = 949 or ID = 969;
Page 1
Order Client
Number Number Product Nu Color Qty Price
---------- ---------- ---------- ---------- ------ ----------
949 9990 56090 Red 3 $12.99
Blue 3 $12.99
Gray 3 $12.99
949 9990 56070 Red 3 $12.99
Blue 3 $12.99
949 9990 56070 Gray 3 $14.99
969 9988 56080 Black 50 $3.99
Red 50 $3.99
Blue 50 $3.99
4 records listed
Screen Example
sql> select ID, CLIENT_NO, PRODUCT_NO, COLOR, QTY, PRICE from ORDERS
unnest NL2 LINE_ITEMS
where ID = 949 or ID = 969;
Page 1
Order Client
Number Number Product Nu Color Qty Price
---------- ---------- ---------- ---------- ------ ----------
949 9990 56090 Red 3 $12.99
56090 Blue 3 $12.99
56090 Gray 3 $12.99
56070 Red 3 $12.99
56070 Blue 3 $12.99
56070 Gray 3 $14.99
969 9988 56080 Black 50 $3.99
56080 Red 50 $3.99
56080 Blue 50 $3.99
2 records listed
Note
This syntax has the same effect as UNNEST with no option and UNNEST NL_ALL association.
Screen Example
sql> select ID, CLIENT_NO, PRODUCT_NO, COLOR, QTY, PRICE from ORDERS
unnest NL_ALL LINE_ITEMS
where ID = 949 or ID = 969;
Page 1
Order Client
Number Number Product Nu Color Qty Price
---------- ---------- ---------- ---------- ------ ----------
949 9990 56090 Red 3 $12.99
949 9990 56090 Blue 3 $12.99
949 9990 56090 Gray 3 $12.99
949 9990 56070 Red 3 $12.99
949 9990 56070 Blue 3 $12.99
949 9990 56070 Gray 3 $14.99
969 9988 56080 Black 50 $3.99
969 9988 56080 Red 50 $3.99
969 9988 56080 Blue 50 $3.99
9 records listed
Note
This syntax has the same effect as UNNEST NL1 Association.
Screen Example
sql> select ID, CLIENT_NO, PRODUCT_NO, COLOR, QTY, PRICE from ORDERS
unnest NL1 PRODUCT_NO,PRICE
where ID = 949 or ID = 969;
Page 1
Order Client
Number Number Product Nu Color Qty Price
---------- ---------- ---------- ---------- ------ ----------
949 9990 56090 Red 3 $12.99
Blue 3 $12.99
Gray 3 $12.99
949 9990 56070 Red 3 $12.99
Blue 3 $12.99
949 9990 56070 Gray 3 $14.99
969 9988 56080 Black 50 $3.99
Red 50 $3.99
Blue 50 $3.99
4 records listed
Note
This syntax has the same effect as UNNEST NL2 Association.
Screen Example
sql> select ID, CLIENT_NO, PRODUCT_NO, COLOR, QTY, PRICE from ORDERS
unnest NL2 PRODUCT_NO,PRICE
where ID = 949 or ID = 969;
Page 1
Order Client
Number Number Product Nu Color Qty Price
---------- ---------- ---------- ---------- ------ ----------
949 9990 56090 Red 3 $12.99
56090 Blue 3 $12.99
56090 Gray 3 $12.99
56070 Red 3 $12.99
56070 Blue 3 $12.99
56070 Gray 3 $14.99
969 9988 56080 Black 50 $3.99
56080 Red 50 $3.99
56080 Blue 50 $3.99
2 records listed
Note
This syntax has the same effect as UNNEST with no option and UNNEST NL_ALL association.
Screen Example
sql> select ID, CLIENT_NO, PRODUCT_NO, COLOR, QTY, PRICE from ORDERS
sql> unnest NL_ALL PRICE
sql> where ID = 949 or ID = 969;
Page 1
Order Client
Number Number Product Nu Color Qty Price
SET
Syntax
SET {HEADING {OFF | ON} |
LINESIZE n |
MARGIN n |
MISSING {NULL | “string”}
NEWPAGE n |
NULL “text” |
PAGESIZE n |
PAUSE {ON | OFF} |
SPACE n |
WRAP {VERT | HORI | DEF}
UNDERLINE{“char” | OFF | ON}
DISPLAY TPMESSAGE {ON | OFF}
TRANSACTION {READ ONLY | READ WRITE |
ISOLATION LEVEL {READ UNCOMMITTED | READ COMMITTED |
REPEATABLE READ | SERIALIZABLE}
Description
The SET statement sets a system variable’s value. UniData SQL system variables affect the way
query results or reports are displayed. You may use the SET statement to override the system
defaults or to restore them later.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
HEADING ON Enables or suppresses printing of column headings in
HEADING OFF reports. The default is ON.
SET Parameters
Parameter Description
LINESIZE n Sets the width of the report line. The default is 80.
MARGIN n Sets the left margin of the display or report and allows
you to align the display. The default is 1.
MISSING {NULL | “string”} With MISSING NULL set, and null value handling on,
missing values are treated as nulls; with any other string
set, missing values are NOT treated as nulls, and the
string represents missing values in display.
This setting makes UniData SQL operate the same way
as desktop tools, which access UniData SQL through
ODBC. For further information on UniData null value
handling, see Using UniData.
Note - NULL_FLAG =1 in udtconfig turns on null value
handling.
NEWPAGE n Sets a number of blank lines to be printed between the
bottom title of each page and the top title of the next
page. If n is 0, UniData SQL issues a form feed between
pages. The default is 1.
NULL “text” Sets the text to represent the null value in display.
PAGESIZE n Sets the number of lines per page for display of the
results of query_spec or SELECT statements. The
default is 23. This option remains in effect if you return
to UniData when you exit UniData SQL.
PAUSE In interactive mode, when PAUSE is ON, display stops at
ON | OFF the end of each page and displays the prompt Enter
<New line> to continue.... The next page displays
when the user presses ENTER.
The default in interactive mode is ON; PAUSE ON has
no effect in UniData SQL scripts.
Parameter Description
SPACE Sets the number of spaces between the columns in a
report. The default is 1.
WRAP Determines how UniData SQL displays columns in
results of query_spec or SELECT statements:
• VERT – Displays each column on a new line; column
headings and column values may wrap on several
lines.
• HORI – Displays columns across the line, wrapping
when LINESIZE is exceeded.
• DEF–Follows UniData conventions: when a whole
row fits on one line, UniData SQL displays it
horizontally; when it does not, UniData SQL displays
it vertically.
For examples of the different WRAP types, see the
“Examples” section.
UNDERLINE char Sets the character used to underline headings. Standard
ON | OFF characters are '-' and '='.
DISPLAY DISPLAY TPMESSAGE ON turns on the display of
TPMESSAGE notification messages for transaction processing (TP)
ON | OFF commands.
UniData SQL always displays “Transaction aborted”
when a transaction is rolled back, regardless of the
TPMESSAGE setting.
Note - DISPLAY TPMESSAGE ON traces transaction
processing (TP) commands. The Recoverable File
System (RFS) must be in use for transaction processing
to work. In the absence of RFS, TP commands are
ignored.
Parameter Description
TRANSACTION Specifies the access mode and isolation level of the next
READ ONLY | READ WRITE | transaction. Does not start a new transaction, and cannot
ISOLATION LEVEL be executed within an active transaction. Default settings
are restored upon completion of the transaction.
The combination of isolation level and access mode
determines the access mode and file or record locks set.
READ ONLY – The next transaction is read-only.
READ WRITE – Default. The next transaction is read-
write.
ISOLATION LEVEL – For further information, see the
“Isolation Levels” table in the next section. Choose from:
• READ UNCOMMITTED
• READ COMMITTED (the default)
• REPEATABLE READ
• SERIALIZABLE
Tip - You can set the level of isolation for your
environment by setting the UniData environment vari-
able DEFAULT_ISO_LEVEL.
For further information on transaction processing and
isolation levels, see Using UniData SQL.
Isolation Levels
Your selection of isolation level may affect the access mode and locks set for the next transaction.
Isolation Levels
Examples
The following example demonstrates the PAGESIZE clause to set the display page to 10 lines, and
the LINESIZE clause to establish a 40-character-wide display area. Report headers and footers are
included to show where “pages” begin and end.
Screen Example
Screen Example
Order
Number
----------
912
801
The next set of examples demonstrates the SET DISPLAY TPMESSAGE ON command, which
turns on the display of transaction processing (TP) commands.
Reminder
The Recoverable File System (RFS) must be in use for transaction processing to work. In the
absence of RFS, TP commands are ignored. UniData for Windows NT or Windows 2000 does not
support RFS.
This example demonstrates turning on display of transaction start and transaction commit
messages:
Screen Example
After the preceding SET DISPLAY TPMESSAGE ON statement is executed, any statement that
creates, updates, or deletes a table generates Transaction started and Transaction committed
messages, as in the following example:
Screen Example
sql> INSERT INTO INVENTORY (ID, FEATURES, COLOR, QTY, PRICE, REORDER)
sql> VALUES (99999, "133 MHz CPU, 25-in. SVGA Monitor, Keyboard, Mouse,
sql> Microsoft Office", "Black", 50, 1000.00, 10);
Transaction started.
1 record(s) created.
Transaction committed.
1 records listed
Transaction committed.
The transaction in the following example is set to read-only with an isolation level of READ
UNCOMMITTED. Therefore, the attempt to add a value is not allowed. The SELECT statement
displays the record to show that the new value was not added.
Screen Example
1 records listed
The following example demonstrates the HORI and DEF settings for WRAP. HORI forces
UniData SQL to print column text horizontally, wrapping when LINESIZE is exceeded; DEF
switches the display to vertical because the report line does not fit on one line.
Screen Example
3065487569 Fax
1 records listed
sql> SET WRAP DEF;
sql> SELECT * FROM CLIENTS WHERE ID = 10015;
Page 1
CLIENTS 10015
First Name Cal
Last Name di Grigorio
Company Name Regina Flooring
Address 913 Montreal Ave.
City Regina
State/Territory Saskatchewan
Postal Code S4P3V7
Country Canada
Phone Number Phone Cate
-------------- ----------
3067881245 Work
3065487569 Fax
1 records listed
The following series of examples demonstrates the effects of SET MISSING NULL, which causes
UniData SQL to mimic ODBC’s handling of empty strings, by converting them to the null value.
Reminder
NULL_FLAG in udtconfig must be ON for SET MISSING to take effect.
Screen Example
This example computes the average of PRICE for products 10010 and 10020. Values in the PRICE
attribute for product 10010 are empty strings, and are therefore included in the computation:
Screen Example
Page 1
Product Na Product Nu Price
---------- ---------- ----------
Camcorder 10010
10010
10010
10010
10020 $200.00
10020 $200.00
10020 $200.00
10020 $200.00
********** ----------
avg $100.00
8 records listed
Next, we execute SET MISSING NULL to have empty strings handled as nulls. Then we execute
the same computation. This time, values in the PRICE attribute for product 10010 are not included
in computation of average, because null values are ignored by aggregate functions.
Screen Example
Page 1
Product Na Product Nu Price
---------- ---------- ----------
Camcorder 10010 N
10010 N
10010 N
10010 N
10020 $200.00
10020 $200.00
10020 $200.00
10020 $200.00
********** ----------
avg $200.00
8 records listed
Screen Example
Page 1
Product Na Product Nu Price
---------- ---------- ----------
Camcorder 10010
10010
10010
10010
10020 $200.00
10020 $200.00
10020 $200.00
10020 $200.00
********** ----------
avg $100.00
8 records listed
SHOW
Syntax
SHOW {ALL | BTITLE | TTITLE | set_option}
Description
The SHOW statement displays the values of UniData SQL system variables.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
ALL Displays the settings of all SHOW options.
BTITLE Displays the BTITLE definition
TTITLE Displays the TTITLE definition.
SHOW Parameters
Parameter Description
set_option Displays the current setting of any SET option
listed below. See SET for descriptions of the
following options:
• HEADING
• HEADSEP
• LINESIZE
• MARGIN
• NEWPAGE
• NULL
• PAGESIZE
• PAUSE
• SPACE
• WRAP
• UNDERLINE
Examples
The following example displays the current setting of the PAGESIZE parameter, which is defined
by the SET command:
Screen Example
The next example uses the SHOW ALL command to display the default settings for the
environment variables set by the SET command:
Screen Example
The final example uses the SET command to assign the letter “N” to represent the null value in
display and print:
Screen Example
SQL
Syntax
sql
Description
The ECL command sql initiates an interactive UniData SQL session. You can execute this
command from the operating system level or from udt.
Note
For instructions on exiting from an interactive UniData SQL session, see EXIT and QUIT.
TTITLE
Syntax
TTITLE [“text”]
TTITLE [ print_clause | OFF | ON]
print_clause syntax:
{SKIP [n] | [COL [n] | [ LEFT | CENTER | RIGHT] }
[ “text”]
[FORMAT format | [TAB [n] ] [new_val] ]...
Description
TTITLE establishes a header for printed and displayed reports. You can specify any number of
constants and variables. These parameters are executed in the order in which you define them. You
can apply any number of TTITLE commands to one or more attributes. If more than one TTITLE
command is applied to the same attribute, the last command supersedes all previous commands.
Note
Execute the SHOW TTITLE command to display the current setting of TTITLE.
Parameters
The following table describes each parameter of the syntax.
Option Description
"text" Displays a two-line header. The first line contains the date at the left and the
page number on the right; the second line contains the center-aligned text. You
can include any number of the following heading options enclosed in single
quotation marks:
• C[n] – Centers heading or footing text within a line of n width.
• D – Inserts the current system date.
• L – Inserts a blank line.
• N – Suppresses the default prompt, “Enter new line to continue...”, which
appears at the bottom of each screen page. Pages scroll without stopping
until the report is finished. (The prompt displays only in interactive mode.)
• P or S – Inserts the current page number.
• T – Inserts the time and date when report generation began.
print_clause print_clause has the following syntax:
{COL n | SKIP [n] | [LEFT | CENTER | RIGHT]...} [FORMAT format]
{variable | "text"}] [TAB [n] {variable | "text"}...]
For descriptions of print_clause parameters, see the next table.
OFF Turns the header off or on without affecting the heading text. The default is
ON OFF.
no parameter Displays TTITLE current settings.
Note - SHOW TTITLE also displays current settings.
TTITLE Parameters
print_clause Parameters
The following table describes each parameter of print_clause:
Clause Description
COL n Skips to the nth column of the current line (see LINESIZE option
of SET command). The space is required.
SKIP n Skips n lines before printing out the text. The default is 1. You
must include a space after the keyword SKIP.
LEFT, CENTER, RIGHT Aligns the title data on the current line. The following data item
(variable or text) is aligned as a group to the end of the statement,
or to the next LEFT, CENTER, or RIGHT, or to the next COL,
SKIP, or TAB. CENTER and RIGHT are calculated based on the
LINESIZE option of the SET statement.
FORMAT format Specifies a format model for the following data item. FORMAT
is effective until the end of the statement or until another
FORMAT clause is encountered in the same statement. format
options are discussed following this table.
new_val Displays the current value of the variable new_val, set by
NEW_VALUE in a previously executed COLUMN statement.
Clause Description
"text" Displays a two-line header. The first line contains the date on the
left and the page number on the right; the second line contains
the center-aligned text. In addition to literal text, you can include
any number of the following heading options:
• C[n] – Centers heading text within a line of n width.
• D – Inserts the current system date in the heading.
• L – Executes a new line.
• N – Suppresses the default prompt, “Enter new line to
continue...”, which appears at the bottom of each screen page.
Pages scroll without stopping until the report is finished.
• P or S – Inserts the current page number.
• T – Inserts the time and date when report generation began.
TAB n Skips n columns from the current position. The space is optional.
format Options
format specifies the display format for values in the header. format must be enclosed in quotation
marks, and can be one of the following:
• Character Format Options – The format for a character string is An where n is the column
width. The default is the length specified in the dictionary definition of the attribute.
• Date Format Options– You may not specify format options for date attributes; the
formatting specified in the dictionary definition of the attribute is used.
• Numeric Format Options – Use the options in the following table to build a display mask
for formatting numeric values.
Note
If the format is not applicable to the data type of a particular data item, FORMAT has no effect on
that item, and the default format is used. The format specified in the FORMAT clause is the same
as described in the COLUMN statement. For further information, see COLUMN.
Examples
The following example defines a centered title of “Open Orders.” The SELECT statement displays
the title.
Screen Example
Open Orders
Client
Number Product Nu Qty Price
---------- ---------- ------ ----------
9965 40003 10 $49.97
9965 56000 4 $79.99
9966 11100 1 $139.86
9966 11150 1 $99.97
9966 34000 2 $199.87
...
The next example uses the variables old and new, that are set by the COLUMN command. These
variables, added to TTITLE and BTITLE, include in the header and footer current and old values
in the CLIENT_NO attribute:
Screen Example
...
10045 10060 126 $39.97
10060 144 $39.97
10060 203 $39.97
Client: 10045
Client: 10045
Client
Number Product Nu Qty Price
---------- ---------- ------ ----------
10070 144 $34.97
10070 144 $34.97
10150 144 $48.82
10059 51090 1 $39.95
...
10062 57040 1 $209.99
10077 10003 6 $3,200.00
10004 6 $2,500.00
Client: 10077
Client: 10077
Client
Number Product Nu Qty Price
---------- ---------- ------ ----------
10006 6 $159.95
10086 33000 1 $599.96
35000 2 $198.93
...
Client: 10086
UPDATE
Syntax
UPDATE table_spec [ID_list]
{SET | ADD VALUE | ADD SUBVALUE}
attribute_name = expression
[,attribute_name = expression ...]
[WHERE search_condition]
Description
The UPDATE statement changes values stored in one or more attributes of a table.
You cannot update @ID with the UPDATE command. To update @ID, you must delete and
reinsert the record. For further information, see the DELETE and INSERT commands in this
manual.
Warning
If two subtables map to the same association, but specify different primary keys, UniData SQL has
no way of ensuring that primary keys are unique. This could result in duplicate values being added
through UPDATE or INSERT, or by more than one row being updated by UPDATE.
Warning
An UPDATE statement with no WHERE clause updates all rows in the table.
Parameters
The following table describes each parameter of the syntax.
Parameter Description
table_spec Name of the table, view, or subtable to be updated.
ID_list Limits update to only those records whose ID is listed in ID_list.
ID_list may be applied to a base table only, not to a view or
subtable.
SET Replaces the values in one or more attributes of records satisfying
WHERE search_condition. You may not include delimiters to set
multivalues or multi-subvalues.
ADD VALUE Appends values to the end of an existing multivalued or multi-
ADD SUBVALUE subvalued attribute specified by attribute_name for the rows
satisfying the WHERE clause. More information is provided on
this subject following this table, as well as in Using UniData.
attribute_name Specifies an attribute to update. May be an individual attribute
name; may be qualified by preceding the attribute name with the
table name/label and a period, as follows:
• table_name.attribute_name
• table_label.attribute_name
expression Any combination of attribute names, constants, arithmetic
operators, and UniData SQL functions that together return a
value that determines the value to store in the attribute.
You may set an attribute to the null value with an expression like
this: attribute_name = NULL.
UPDATE Parameters
Parameter Description
WHERE search_condition Updates attribute values that meet the criteria specified in
search_condition. WHERE evaluates multivalues and multi-
subvalues as if they have been unnested. search_condition takes
the form:
attribute_name/expression rel_op attribute_name/expression
For example: WHERE fld1 BETWEEN 100 AND 500.
rel_op may also be a Boolean operator (AND, OR).
Warning - If no WHERE clause or ID list is included, ALL rows
of the table are updated.
Note - Within a WHERE clause, the sum total of the individual
conditions and the Boolean operators cannot exceed 127.
For information on writing WHERE clauses, see Using UniData.
Examples
The following example updates the address for CLIENTS record 9982:
Screen Example
1 records listed
The next example adds two new multivalues for PHONE_NUM and PHONE_TYPE. First, we
display the record to be updated.
Screen Example
Then, we add the new multivalues and display the record again.
Screen Example
You define attributes when you create or alter a table by using CREATE TABLE and ALTER
TABLE. Follow the instructions in this appendix to define an attribute when the UniData SQL
syntax indicates attribute_definition.
Attribute definitions consist of the following elements. Attribute name and data type are required
and must be entered first and second; the other elements are optional and can be entered in any
order. The elements are described in the following sections of this appendix:
• Attribute name (required)
• Data type (required)
• Location
• Virtual attribute description
• Display name
• Format
• Value code specification
• Association description
Syntax:
attribute_name
{CHAR(size[,“conv_code”])
| DATE[({“date_conv” | “time_conv”})]
| NUMBER[({size | size,n | *}[,“conv_code”])]
| LONG]
[IDESC | VIRTUAL (“virt_definition”)]
[LOC(n)]
[DISP(“display_name”)]
[FORMAT(“fmt_desc”)]
[SM(“{S | MV | MS}”)]
[ASSOC(“assoc_name”)]
Attribute Name
You must assign an attribute name when you define a new attribute. Valid attribute names can
contain the following types of characters:
• Alphabetic characters
• Numbers
• Special characters: “_”, “@”, “#”, and “$”
The following restrictions apply to attribute names:
• The first character of an attribute name must be an alphabetic character, underscore (_), or
at symbol (@).
Note
If you plan to access the data in a table, subtable, or view via ODBC, do not use @, #, or $
anywhere in the attribute name, and do not use an underscore (_) as the first character.
Data Type
Data type describes the type of values that the attribute contains. You can specify four data types:
• CHAR
• DATE
• NUMBER
• LONG
Syntax:
{CHAR(size[,“conv_code”]) | DATE[({“date_conv” | “conv_code”})] |
NUMBER[({size | size,n | *}[,“conv_code”])] | LONG]
You can enter any type of data into any attribute; however, be careful when you store a different
type of data in an attribute than is indicated by the data type of that attribute. If a conversion is
specified, it may produce results that differ from your expectations. Also, be aware that changing
the data type for an attribute in some cases appears to alter the data.
You can also establish a FORMAT or conversion code that contradicts the data type. If the format
or conversion is inappropriate for the data values contained in the attribute, it is ignored.
Reminder
Data type is optional for ALTER TABLE MODIFY.
CHAR
The CHAR data type tells UniData SQL that a particular attribute contains character string data.
Syntax:
CHAR(length[,“conv_code”])
length is the length of the character string in display format, including the mask. Length is a
required parameter.
For valid conv_code options, see “Conversion Codes” later in this appendix.
Note
You must enclose literal values in quotation marks. If you enter a number without quotation marks,
UniData stores it as numeric data type regardless of the data type indicated for that attribute.
DATE
Use the DATE specification to tell UniData SQL that the attribute contains either date or time
values. UniData stores a date as a single integer with 0 representing December 31, 1967, and 1
representing January 1, 1968, and so on. Negative numbers represent dates before December 31,
1967. UniData stores time as an integer between 0 and 86400 (seconds since midnight). Some
points to remember about DATE data type:
• Time – To specify time data type, use the DATE data type and conv_code MT. Negative
input and numbers greater than 86400 are invalid for time data-type attributes.
• Data Entry – Unless the date or time is enclosed in quotation marks, UniData assumes that
it is an integer being entered in internal format.
• Defaults – The default format for a DATE data-type attribute is 10 characters, left-
justified. Default conversion is “D2/”.
Syntax:
DATE[(“date_conv”)]
See “Conversion Codes,” later in this appendix, for an explanation of date_conv.
NUMBER
The NUMBER specification tells UniData SQL how to convert input numeric values to the
internal format and how to display the numeric values on output. When entering data, do not
enclose data to be stored in numeric attributes in quotation marks.
Syntax:
NUMBER[({length | length,n | *} [,conv_code])]
Note
If you define an attribute as NUMBER or LONG, but specify a format of 10L (which implies
CHAR data type) the attribute is considered to be CHAR, and attempts to perform arithmetic
functions on that attribute result in the error “Invalid function on character field.”
Parameters
The following table describes each parameter of the syntax.
Parameter Description
length Length of the number value in display format,
including the mask.
n Specifies the number of decimal places to
include in the formatted number.
* Directs UniData SQL to use the default length
of 10 digits.
,conv_code See “Conversion Codes,” in this appendix, for
an explanation of date_conv.
NUMBER Parameters
Warning
Be aware that altering the num_conv or format for a numeric attribute could affect the values when
they are displayed. For example, if you remove an MD2 formatting code, the decimal is no longer
inserted when the data is retrieved, effectively multiplying the value by 100.
LONG
LONG describes an attribute that can hold numeric data. Although UniData SQL does not limit the
size of an attribute, some systems do. The LONG description is provided for compatibility with
other systems. The LONG data type has no options. When entering data, do not enclose data to be
stored in numeric attributes in quotation marks.
The default format for a LONG data-type attribute is 10 digits, right-justified. No default
conversion is performed on numbers.
Syntax:
LONG
Warning
Be aware that altering the format for a numeric attribute could affect the values stored. For
example, if you remove an MD formatting code, the decimal is no longer insterted when the data is
retrieved, effectively multiplying the value by 100.
Conversion Codes
You may specify any of the conversions in the following table in conv_code or date_conv for any
attribute. However, if an inappropriate conversion is applied, UniData disregards the conversion,
storing or extracting the data without converting it. The data is converted into internal format when
stored in the attribute, and into display format when extracted from the attribute.
Warning
Be aware that altering the conv_code or format for a numeric attribute could affect the values when
they are displayed. For example, if you remove an MD formatting code, the decimal is no longer
inserted when the data is retrieved, effectively multiplying the displayed value by 100.
The conversion codes in this table are described in the UniBasic Commands Reference in the
section on OCONV.
Code Conversion
D Date.
G Extracts one or more strings sepa-
rated by a delimiter.
L Length.
MB Binary.
MC Masked character.
MD Masked decimal.
ML Left justify.
MO Octal.
MP Packed decimal.
Conversion Codes
Code Conversion
MP1 Convert to packed decimal without
truncating at the first CHAR(0) or
altering this character.
MR Right justify.
MT Time.
MX Hexadecimal.
P Pattern match.
R Range.
S SOUNDEX
T Text extraction
Location (LOC)
LOC places the attribute at position n relative to the beginning of the record. If you do not specify
LOC, UniData SQL assumes the input order to be the relative position of each attribute. If two
attributes share the same location, they are considered to be aliases. @ID is at location 0.
Syntax:
LOC(n)
Tip
Use the SET command with the HEADSEP option to set a character to print between columns.
The default is ‘|’. Include the HEADSEP character in string.expr to make the header wrap to a new
line and print the HEADSEP character between columns. Use the FORMAT and COLUMN
keywords to add additional formatting characteristics to header and column text.
Syntax:
DISP (“string.expr”)
string.expr must be enclosed in quotation marks.
FORMAT
FORMAT stores a display format in the table dictionary. UniData SQL first applies the conversion
codes specified in data type (using the CHAR, DATE, and NUMBER keywords) if they are
present before applying FORMAT codes. If no conversion code or display format is coded, Uni-
Data SQL uses the system default for that data type.
Syntax:
FORMAT(“length[f.char]{L | R | T | C}[n][$][,][Z][mask]”)
Option Description
length An integer specifying the width of the output value.
f.char A character used to fill the formatted string, if necessary. If a number
is used in place of a character, you precede it with a “\” to clearly
indicate that it is f.char.
L Specifies left-justification in a column of length spaces. If the text is
longer than length, it is broken in length intervals.
R Specifies right-justification in a column of length spaces.
T Specifies text justification. If data must be broken to fit in a column,
it is broken between words.
C Specifies centered text in the column of length spaces.
n Sets the maximum number of decimal places allowed, rounding if
necessary. If you enter 0 as n, the number is rounded to an integer.
$ Precedes the output number with a dollar sign.
, Separates the number every three digits.
Option Description
Z Suppresses leading zeros
mask Specifies a pattern mask composed of numbers and other characters.
UniData SQL sequentially places numeric data in the mask before
justification. To create the mask, enter one # for each character; enter
special characters (such as comma and decimal point) where you
want them to appear in the printed string (e.g. enter ###,###.## to
insert commas and the decimal point in the output string).
Type Explanation
MV Multivalued attribute
MS Multi-subvalued attribute
S Singlevalued attribute (default)
Value Codes
Associating Attributes
An association is the mechanism UniData uses to establish a relationship among attributes. Within
an association, multivalued attributes and multi-subvalued attributes are related to, or associated
with, each other.
An example of related information that would be stored in a UniData database as an association is
the following: A company's inventory consists of parts that are sold in different colors; each part is
identified by a different part number and price, and a quantity on hand is recorded for each color of
each part number. You do not want the price for one part getting mistaken for that of another, and
you want the correct colors to be related to the correct part number.
The information can be stored, retrieved and manipulated based on the relationships established by
the association; and you may unnest all associated attributes by unnesting the association.
The keyword ASSOC and assoc_name are stored in the definition of each associated multivalued
and multi-subvalued attribute.
Syntax:
ASSOC(“assoc_name”)
This appendix explains use of the levels of unnesting using the SELECT statement and all
combinations of the keywords UNNEST, NL1, NL2, and NL_ALL. The appendix is divided into
two sections:
• Unnesting Associated Attributes
• Unnesting Unassociated Attributes
Tip
You can use any combination of fields selected and fields unnested, with the exception that you
cannot use the NL2 keyword when only a multivalued attribute is listed. Here is an example of this
invalid syntax:
Screen Example
This example displays the dictionary of the table using the UniData SQL LISTDICT command:
Screen Example
Finally, the following INSERT statements populate the table with data that will help demonstrate
unnesting:
Screen Example
The following SELECT statement displays the contents of the table as stored in nf2 (nested)
format:
Screen Example
Note
When you unnest associated multivalued attributes, values in the associated singlevalued attributes
are repeated.
The following displays the results that are obtained when you execute any of the example
statements:
Screen Example
Page 1
tab1 s_fld mv1_f mv2_f ms1_f ms2_f
---------- ----- ----- ----- ----- -----
1 A A1 a1 A1-1 a1-1
A1-2 a1-2
1 A A2 a2 A2-1
A2-2
A2-3
1 A A3 A3-1
2 B B1 b1 B1-1 b1-1
b1-2
b1-3
2 B B2 b2 B2-1
2 B B3 b3 B3-1
2 B b4
2 B b5
3 C C1 c1 C1-1 c1-1
C1-2 c1-2
C1-3
3 C c2
10 records listed
Note
When you unnest associated multi-subvalued attributes, values in the associated multivalued
attributes are repeated, but singlevalued attributes are not repeated.
The following example shows the results when you execute any of the example statements:
Screen Example
Page 1
tab1 s_fld mv1_f mv2_f ms1_f ms2_f
---------- ----- ----- ----- ----- -----
1 A A1 a1 A1-1 a1-1
A1 a1 A1-2 a1-2
A2 a2 A2-1
A2 a2 A2-2
A2 a2 A2-3
A3 A3-1
2 B B1 b1 B1-1 b1-1
B1 b1 b1-2
B1 b1 b1-3
B2 b2 B2-1
B3 b3 B3-1
b4
b5
3 C C1 c1 C1-1 c1-1
C1 c1 C1-2 c1-2
C1 c1 C1-3
c2
3 records listed
Note
When you unnest all attributes in an association, all singlevalued and multivalued attributes are
repeated.
The following displays the results that are obtained when you execute any of the example
statements:
Screen Example
Page 1
tab1 s_fld mv1_f mv2_f ms1_f ms2_f
---------- ----- ----- ----- ----- -----
1 A A1 a1 A1-1 a1-1
1 A A1 a1 A1-2 a1-2
1 A A2 a2 A2-1
1 A A2 a2 A2-2
1 A A2 a2 A2-3
1 A A3 A3-1
2 B B1 b1 B1-1 b1-1
2 B B1 b1 b1-2
2 B B1 b1 b1-3
2 B B2 b2 B2-1
2 B B3 b3 B3-1
2 B b4
2 B b5
3 C C1 c1 C1-1 c1-1
3 C C1 c1 C1-2 c1-2
3 C C1 c1 C1-3
3 C c2
17 records listed
Screen Example
Here is the structure of the table created above, as displayed with the LISTDICT command:
Screen Example
Screen Example
Screen Example
Screen Example
This appendix contains examples of all CREATE SUBTABLE statements you can write, including
creating unique and generated primary and foreign keys.
Reminder
Subtables are updatable views you can access through 1NF commands.
Base Tables
The following tables are used in the CREATE SUBTABLE examples in this appendix.
T_CLIENTS
Screen Example
listdict T_CLIENTS;
Page 1
@ID TYP LOC CONV NAME FORMAT SM ASSOC
--------------- --- ------------- ---- --------------- ------ -- ----------
@ID D 0 T_CLIENTS 10L S
ID D 0 Client # 10R S
ID1 D 0 T_CLIENTS 10L S
FNAME D 1 First Name 15T S
LNAME D 2 Last Name 15T S
COMPANY D 3 Company Name 30T S
ADDRESS D 4 Address 25T MV
CITY D 5 City 15T S
STATE D 6 State/Territory 15T S
ZIP_CODE D 7 Postal Code 10R S
COUNTRY D 8 Country 15T S
PHONE_NUM D 9 Phone Number 14R MV PHONE_ITEM
S
PHONE_TYPE D 10 Phone Category 10T MV PHONE_ITEM
S
@UQ PH NAME COMPANY
ADDRESS CITY
STATE ZIP COU
NTRY PHONE PH
ONE_TYPE
PHONE_ITEMS PH PHONE PHONE_T
YPE
@ORIGINAL SQ @ID
@SYNONYM SQ ID1
NAME V FNAME:" ":LNA Name 30T S
ME
T_INVENTORY
Screen Example
T_ORDERS
Screen Example
LINE_ITEMS PH PRODUCT_NO PR
OD_NAME FEATU
RES COLOR QTY
PRICE EPRICE
PHONE_ITEMS PH PHONE PHONE_T
YPE
@ORIGINAL SQ @ID
@SYNONYM SQ ID1
ADDRESS V TRANS('CLIENT Address 25T MV
S',CLIENT_NO,
'ADDRESS','X'
)
CITY V TRANS('CLIENT City 15T S
S',CLIENT_NO,
'CITY','X')
COMPANY V TRANS('CLIENT Company 15T S
S',CLIENT_NO,
'COMPANY','X'
)
COUNTRY V TRANS('CLIENT Country 10T S
S',CLIENT_NO,
'COUNTRY','X'
)
EPRICE V PRICE*QTY MD2, Extended Price 12R MS LINE_ITEMS
$
FEATURES V TRANS('INVENT Features 30T MV LINE_ITEMS
ORY',PRODUCT_
NO,'FEATURES'
,'X')
GRAND_TOTAL V PRICE*QTY; SU MD2, Grand Total 14R S
M(SUM(@1)) $
NAME V TRANS('CLIENT Name 25T S
S',CLIENT_NO,
'FNAME','X'):
" ": TRANS('
CLIENTS',CLIE
NT_NO,'LNAME'
,'X')
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Program Example
Arithmetic functions and operators, along with constants and attribute names, make up UniData
SQL expressions. The following commands include expressions in their syntax:
Reminder
UniData SQL expressions are made up of attribute names, constants, arithmetic functions, and
arithmetic operators.
Arithmetic Functions
You can include the following UniData functions in expressions.
Arithmetic
Description
Function
ABS (nvalue) Absolute value of nvalue.
ACOS (nvalue) Trigonometric arc-cosine of nvalue. The result is expressed as the
degree of the arc-cosine of the nvalue, which ranges from 0 to 180.
ASIN (nvalue) Trigonometric arc-sine of nvalue. The result is expressed as the
degree of the arc-sin of the nvalue, which ranges from -90 to 90.
ATAN (nvalue) Trigonometric arc-tangent of nvalue.
COS (nvalue) Cosine of nvalue. nvalue is expressed as degree.
EXP (nvalue) Raises ”e” (natural exponential) by the value of nvalue.
INT (x) Integer value of x.
LN (nvalue) Natural log of nvalue.
MOD (nvalue, m) Remainder of nvalue divided by m.
POWER(nvalue, e) Raises the numeric value to the power e.
ROUND(nvalue, e) Rounds the nvalue to the number of decimal places specified by e.
SIGN(nvalue) Returns +1 if the nvalue is greater than zero, 0 if the nvalue is equal
to zero, -1 if the nvalue is less than zero.
SIN (nvalue) Sine of nvalue. nvalue is expressed as degree.
SQRT (nvalue) Square root of nvalue; if nvalue is 0, returns 0.
TAN (nvalue) Tangent of nvalue. nvalue is expressed as degree.
TRUNC Truncates the nvalue to ddigits right of (nvalue{,d}) the decimal
place. The default is 0.
Arithmetic Functions
Arithmetic Operators
The following arithmetic operators can be combined with attribute names and constants to make
up arithmetic expressions. Arithmetic expressions can also be combined with arithmetic functions
within UniData SQL expressions:
Operator Function
+ Addition
- Subtraction
* Multiplication
/ Division
Arithmetic Operators
Symbols A
!< operator, 114 aborting
!= operator, 114 transaction when record locked, 102
!> operator, 114 ABS arithmetic function, 228
% operator, 114 access modes
* operator specifying in UniData SQL, 133
in arithmetic expressions, 229 ACOS arithmetic function, 228
in SELECT, 110 ADD keyword
+ operator, 229 ALTER TABLE command with, 14
/ operator, 229 ADD VALUE keyword
< operator, 114 UPDATE command with, 155
<= operator, 114 adding
<> operator, 114 attribute to table, 14, 157
= operator, 114 attribute value, 157
> operator, 114 ALIAS keyword
>= operator, 114 COLUMN command with, 37
@ID aligning
creating, 67 column header, 38
modifying, 16 report title, 147
_ operator, 114 ALL keyword
_PH_ directory, 45 GRANT command with, 90
_PH_ table, 45 REVOKE command with, 104
SELECT command with, 114
SHOW command with, 143