Unidata: Unidata SQL Commands Reference

Download as pdf or txt
Download as pdf or txt
You are on page 1of 242

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.

Documentation Team: Claire Gustafson

GOVERNMENT LICENSE RIGHTS

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.

ii UniData SQL Commands Reference


Contents

Reference - UniData SQL Commands ............................................7


Elements of Syntax Statements ...................................................................8
Elements of UniData SQL ..........................................................................9
SELECT Statement Elements ...................................................................12
ALTER TABLE ........................................................................................14
AUTO COMMIT ......................................................................................21
BREAK .....................................................................................................23
BTITLE .....................................................................................................26
CLEAR .....................................................................................................35
COLUMN .................................................................................................36
COMMIT ..................................................................................................43
COMO ......................................................................................................45
COMPUTE ...............................................................................................49
CREATE INDEX .....................................................................................54
CREATE SUBTABLE .............................................................................57
CREATE TABLE .....................................................................................67
CREATE VIEW .......................................................................................76

UniData SQL Commands Reference 3


Contents

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

Appendix A - Defining Attributes ...............................................161


Attribute Name .......................................................................................163
Data Type ................................................................................................164
Conversion Codes ...................................................................................168
Virtual Attributes (IDESC or VIRTUAL) ..............................................170
Location (LOC) .......................................................................................171

4 UniData SQL Commands Reference


Contents

Display Name (DISP) .............................................................................172


FORMAT ................................................................................................173
Value Code Specification .......................................................................175
Associating Attributes .............................................................................176

Appendix B - Unnesting Attributes ............................................177


Unnesting Associated Attributes ............................................................178
Unnesting Unassociated Attributes .........................................................186

Appendix C - Creating Subtables ...............................................189


Base Tables .............................................................................................190
CREATE SUBTABLE Examples ..........................................................195

Appendix D - Arithmetic Functions and Operators ..................227


Arithmetic Functions ..............................................................................228
Arithmetic Operators ..............................................................................229

Index

UniData SQL Commands Reference 5


Contents

6 UniData SQL Commands Reference


Reference - UniData
SQL Commands

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.

UniData SQL Commands Reference 7


Reference - UniData SQL Commands

Elements of Syntax Statements


This reference manual uses a common method for stating syntax for UniData commands. The
syntax statement includes the command name, required arguments, and options that you can use
with the command. Italics represents a variable that you can replace with any valid option. The
following figure illustrates the elements of a syntax statement.

command names square brackets indicate


appear in boldface an optional argument
no brackets or braces a vertical line indicates that
indicates a required you may choose between
argument the given arguments

COMMAND required [option] [option1 | option2]


{option1 | option2} required... "string" quotation marks
must enclose a
literal string
braces indicate that you an ellipsis indicates that
must choose between you may enter more than
the given arguments one argument

8 UniData SQL Commands Reference


Elements of UniData SQL

Elements of UniData SQL


Commands Summary
Data Definition Language (DDL)
Data definition language is also called “schema definition.” It uses table, indexing, view, and
subtable commands.

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

UniData SQL Commands Reference 9


Reference - UniData SQL Commands

Data Control Language (DCL)


Data control language is also called “connection management.” It uses privilege and transaction
processing commands.

Privilege Commands:
• GRANT
• REVOKE

Transaction Processing Commands:


• AUTO COMMIT
• COMMIT
• ROLLBACK
• LOCK TABLE
• SET DISPLAY
• SET TRANSACTION

Data Manipulation Language (DML)


• INSERT
• SELECT
• UPDATE
• DELETE

10 UniData SQL Commands Reference


Elements of UniData SQL

Report Commands (RPT)


• TTITLE
• BTITLE
• COLUMN
• COMPUTE
• BREAK
• CLEAR
• SET
• SHOW

Supplementary Commands (SUP)


• SQL
• EXIT
• QUIT
• LISTDICT
• COMO

UniData SQL Commands Reference 11


Reference - UniData SQL Commands

SELECT Statement Elements


*
ALL
DISTINCT
attributes
functions
expressions
literals
FROM
UNNEST
NL1, NL2, NL_ALL
WHERE
=, !=, <, <=, >, >=, <>, !<, !>
ALL
EVERY
subquery
NOT
IS [ NOT ] NULL
[ NOT ] BETWEEN
[ NOT ] IN
[ NOT ] INTERSECT
[ NOT ] LIKE
%, _, ..., nA, nN, nX
GROUP BY
HAVING
UNION
ORDER BY
TO
INTO
LPTR

12 UniData SQL Commands Reference


SELECT Statement Elements

UniData SQL Limitations


• In a SELECT statement, you cannot select more than 1000 attributes.
• All identifiers in UniData SQL, such as table_name, view_name, attribute_name,
table_label, and all variables in OLD/NEW_VALUE of the COLUMN statement can be
no longer than 30 characters.
• A UniData SQL statement cannot exceed 49 lines. The length of a single line of a UniData
SQL statement, when used interactively, cannot exceed 272 characters.
• A single association cannot exceed 64 attributes.
• A table can contain a maximum of 12 associations.
• SELECT statement or clause cannot contain more than 255 virtual attributes.
• The IN predicate cannot contain more than five operators. Each operator must be a
constant. The length of each constant cannot exceed 95 characters.
• Within a WHERE clause, the total number of predicates and Boolean operators cannot
exceed 255.
• The ORDER BY clause can contain no more than nine elements (attribute names,
expressions, and ordinal positions).
• The number of tables in the FROM clause of a SELECT statement is limited to 16.
However, when performing a join, a new temporary table is created internally for every
two joined tables in the FROM clause. Therefore, a join can contain no more than eight
join tables, whereas a nested subquery with exactly one table at every level may contain
up to 16 levels.
• The UNNEST clause can process 10,240 values in a multivalued or multi-subvalued
attribute, or in all associations for the unnested record.
• The number of elements (column names, expressions, and functions) in a select list cannot
exceed 1000.

UniData SQL Commands Reference 13


Reference - UniData SQL Commands

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.

You must update/reindex if you modify an indexed attribute.

14 UniData SQL Commands Reference


ALTER TABLE

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.

ALTER TABLE Keywords

The parameters for ALTER TABLE are described under CREATE TABLE. Exceptions and
additions to these descriptions are noted in the following sections.

ALTER TABLE ADD


The ADD keyword creates a new attribute definition or alias. If no location is specified, the new
attribute is assigned the next available location.
Syntax:
ALTER TABLE table_name ADD (attribute_definition [, attribute_definition]...)

Parameters
table_name is the name of the table to be modified. For a description of attribute_definition, see
“Appendix A - Defining Attributes.”

UniData SQL Commands Reference 15


Reference - UniData SQL Commands

Example: ALTER TABLE ADD

Screen Example

sql> ALTER TABLE ORDERS ADD


sql> (CATEGORY CHAR(10));
1 attribute(s) added.

ALTER TABLE MODIFY


The MODIFY keyword modifies only the characteristics of the attribute you specify; other
characteristics of the attribute remain the same. Note that UniData may update associations
affected by the changes you make. The attribute you specify in the MODIFY clause must already
exist in the dictionary; if it does not, UniData SQL displays an error message.
You can modify any characteristic of an attribute definition except the location of the @ID
attribute.
Syntax:
ALTER TABLE table_name MODIFY (attribute_definition [, attribute_definition]...)
table_name is the name of the table to be modified. For a description of attribute_definition, see
“Appendix A - Defining Attributes.” Data type in attribute_definition is optional for ALTER
TABLE MODIFY.

Parameters
For a description of table_name, see CREATE TABLE. For a description of attribute_definition,
see “Appendix A - Defining Attributes.”

Modifying Association Names


When you modify the association name of an attribute, UniData SQL makes corresponding
changes to the PH attribute.
• If you add a new association name to an attribute definition, UniData SQL creates a phrase
attribute for that name and puts the related attribute name into the phrase of the PH
attribute.

16 UniData SQL Commands Reference


ALTER TABLE

• 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.

Example: ALTER TABLE MODIFY


The following example demonstrates modifying the ORDERS table by adding a display name for
the CLIENT_NO attribute:

Screen Example

sql> ALTER TABLE ORDERS MODIFY


sql> (CLIENT_NO DISP("Client No."));
1 attribute(s) modified.

ALTER TABLE DELETE


The DELETE keyword deletes an attribute definition or alias. You cannot delete the @ID of the
table unless it has at least one alias.
Syntax:
ALTER TABLE table_ spec DELETE (attribute_name[, attribute_name]...)

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.”

UniData SQL Commands Reference 17


Reference - UniData SQL Commands

Examples: ALTER TABLE DELETE


This example demonstrates deleting PRICE from the ORDERS table:

Screen Example

sql> ALTER TABLE ORDERS DELETE (PRICE);


1 attribute(s) deleted.

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

sql> ALTER TABLE ORDERS DELETE (@ID);


1 attribute(s) deleted.
sql> SELECT @ID FROM ORDERS;
@ID is not a field name.
Transaction aborted.

18 UniData SQL Commands Reference


ALTER TABLE

Then, when the @ID is added back at the same location, the data is again accessible through that
attribute name.

Screen Example

sql> ALTER TABLE ORDERS ADD (@ID NUMBER LOC(0));


1 attribute(s) added.
sql> SELECT @ID FROM ORDERS;
Page 1
@ID
----------
912
801
941
805
830
970
...

ALTER TABLE MODULO


The MODULO keyword resizes a static table. Disk space is reallocated based on the new
MODULO. Assigning a new modulo physically rebuilds the file.
Syntax:
ALTER TABLE table_name MODULO m [,n]

UniData SQL Commands Reference 19


Reference - UniData SQL Commands

Parameters
table_name is the name of the table to be modified. For instructions on setting MODULO, see
CREATE TABLE.

Example
Screen Example

sql> ALTER TABLE CLIENTS MODULO 23;


CLIENTS RESIZED from 19 to 23

20 UniData SQL Commands Reference


AUTO COMMIT

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.

AUTO COMMIT Parameters

UniData SQL Commands Reference 21


Reference - UniData SQL Commands

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

sql> AUTO COMMIT;


Transaction auto commit option is ON.
sql> AUTO COMMIT OFF;
sql> AUTO COMMIT;
Transaction auto commit option is OFF.

22 UniData SQL Commands Reference


BREAK

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.

UniData SQL Commands Reference 23


Reference - UniData SQL Commands

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

24 UniData SQL Commands Reference


BREAK

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

sql> BREAK ON PROD_NAME SKIP 1;


sql> SELECT PROD_NAME, FEATURES, COLOR, ID FROM INVENTORY
sql> UNNEST LINE_ITEMS
sql> ORDER BY PROD_NAME, FEATURES;
Page 1
Product Product
Name Features Color Number
---------- ------------------------------ ---------- ----------
Adapter A/C Adapter for notebook N/A 10007
computers
Ethernet LC Card N/A 13001
Workgroup Hub N/A 13002

CD Player Personal Model, Bass Boost Gray 39500


Portable Model Black 39400
Portable Model Gray 39400

...

UniData SQL Commands Reference 25


Reference - UniData SQL Commands

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.

26 UniData SQL Commands Reference


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.

Print Clause Parameters

UniData SQL Commands Reference 27


Reference - UniData SQL Commands

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.

Print Clause Parameters (continued)

28 UniData SQL Commands Reference


BTITLE

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.

Option Explanation Example


9 Determines number of digits displayed. 9999
0 Display leading zeros. 0999
$ Prefix displayed value with a dollar sign. $9999
B Print leading zeros as blank. B999
MI Display minus sign (-) after a negative 9999MI
value.
PR Display a negative value in angle brackets 9999PR
. Align on the decimal point. 99.99
, Insert a comma every three digits. 99,999
V Multiply the value by the n power of 10, 999V99
where n is the number of 9s after V.
EEEE Display the scientific notation (the format 9.99EEEE
must contain four Es).

format Numeric Options

UniData SQL Commands Reference 29


Reference - UniData SQL Commands

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> COLUMN PROD_NAME OLD_VALUE old_val;

sql> BTITLE SKIP 2 COL 0 "Product:" TAB 15 old_val;


sql> BTITLE ON;

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

sql> SET PAGESIZE 10;


sql> SET LINESIZE 40;
sql> TTITLE "Page TOP Title";
sql> BTITLE "Page BOTTOM Title";
sql> TTITLE ON;
sql> BTITLE ON;
sql> SELECT ID FROM ORDERS;

30 UniData SQL Commands Reference


BTITLE

The following is output from the preceding commands:

Screen Example

Jun 17 1996 Page 1


Page TOP Title

Order
Number
----------
912
801

Page BOTTOM Title


Enter <New line> to continue...Q

The next example demonstrates the following:


• SET LINESIZE – to set the report width to 40 characters
• COLUMN...NEW_VALUE...OLD_VALUE – to save the current and old value of
PROD_NAME (from the INVENTORY table)
• TTITLE settings:
• SKIP 2 – to skip two lines before displaying the report title (Product Prices)
• CENTER – to center the report title (Product Prices)
• SKIP 2 – to skip two lines before displaying the next title line (Product)
• TAB 2 – to skip two spaces before printing the new value of PROD_NAME
• ON – to turn the header on

UniData SQL Commands Reference 31


Reference - UniData SQL Commands

• 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>SET LINESIZE 40;

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;

32 UniData SQL Commands Reference


BTITLE

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

sql>SELECT ID, PROD_NAME, PRICE FROM INVENTORY ORDER BY PROD_NAME;


Product Prices

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
...

UniData SQL Commands Reference 33


Reference - UniData SQL Commands

Note
For more examples, see TTITLE.

34 UniData SQL Commands Reference


CLEAR

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

sql> CLEAR COMPUTE;


computes cleared
sql> CLEAR BREAK;
breaks cleared

UniData SQL Commands Reference 35


Reference - UniData SQL Commands

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.

36 UniData SQL Commands Reference


COLUMN

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

UniData SQL Commands Reference 37


Reference - UniData SQL Commands

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.

COLUMN Parameters (continued)

38 UniData SQL Commands Reference


COLUMN

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 Parameters (continued)

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

column_format Numeric Options

UniData SQL Commands Reference 39


Reference - UniData SQL Commands

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).

column_format Numeric Options (continued)

Examples
The following COLUMN statement skips a line after ORD_TIME is displayed, and presents the
data in vertical format:

Screen Example

sql> COLUMN ORD_TIME NEWLINE;

40 UniData SQL Commands Reference


COLUMN

The following output is produced when you select ORD_TIME after executing the above
COLUMN command:

Screen Example

sql> SELECT ORD_DATE, ORD_TIME FROM ORDERS;


Page 1
Order Date 01/13/1996
Order Time 12:30PM

Order Date 09/28/1995


Order Time 04:34PM

Order Date 01/14/1996


Order Time 03:00PM
...
Enter <New line> to continue...Q

Next, we clear the COLUMN setting and execute the same SELECT statement:

Screen Example

sql> CLEAR COLUMN;


columns cleared
sql> SELECT ORD_DATE, ORD_TIME FROM ORDERS;

UniData SQL Commands Reference 41


Reference - UniData SQL Commands

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

42 UniData SQL Commands Reference


COMMIT

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.

The system performs the following steps during a transaction commit:


• Disables the break key.
• Writes all updates.
• Releases all locks acquired within the transaction.
• Enables the break key.
If the transaction cannot commit, the system performs the following steps:
• Aborts the transaction.
• Releases all locks acquired within the transaction.

UniData SQL Commands Reference 43


Reference - UniData SQL Commands

UniBasic STATUS Function Return Values


The UniBasic STATUS function returns the values in the following table if executed immediately
after the UniData SQL COMMIT command.

Value Description
0 The commit completed successfully.
1 Transaction not started.
3 Transaction cannot commit.

UniBasic STATUS Return Values

44 UniData SQL Commands Reference


COMO

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

UniData SQL Commands Reference 45


Reference - UniData SQL Commands

Option Description
LIST Lists all the COMO files in the _PH_ table.
APPEND Appends terminal display to an existing COMO file.

COMO Options (continued)

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

sql> COMO ON SAVESQL;


/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

46 UniData SQL Commands Reference


COMO

Color Quanti Price Reorde


---------- ------ ---------- ------
Gray 494 $98.99 70

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

UniData SQL Commands Reference 47


Reference - UniData SQL Commands

Enter <New line> to continue...Q


sql> COMO OFF SAVESQL;

48 UniData SQL Commands Reference


COMPUTE

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.

UniData SQL Commands Reference 49


Reference - UniData SQL Commands

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

50 UniData SQL Commands Reference


COMPUTE

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.

COMPUTE Parameters (continued)

UniData SQL Commands Reference 51


Reference - UniData SQL Commands

Examples
The following example demonstrates the use of COMPUTE to obtain the average price of all items
in the ORDERS file:

Screen Example

sql> COMPUTE AVG OF PRICE ON REPORT;


sql> BREAK ON PRICE ON REPORT;
sql> SELECT PRICE FROM ORDERS;
Page 1
Price
----------
$129.95
$1,799.00
$1,399.99
$149.97
$429.94
$29.97
$48.82
$34.97
$8.99
$24.99
...
----------
$735.92

The next example demonstrates using the COMPUTE command to obtain daily sales totals:

Screen Example

sql> BREAK ON ORD_DATE SKIP 1;


sql> COLUMN ORD_DATE HEADING "Order|Placed On:" JUSTIFY CENTER;
sql> COMPUTE SUM OF PRICE ON ORD_DATE;
sql> SELECT ORD_DATE, @ID, CLIENT_NO, PRODUCT_NO, QTY, PRICE FROM ORDERS
sql> ORDER BY ORD_DATE;

52 UniData SQL Commands Reference


COMPUTE

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

04/09/1968 791 9997 10004 5 $2,500.00


**********
sum $2,500.00
...

UniData SQL Commands Reference 53


Reference - UniData SQL Commands

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.

54 UniData SQL Commands Reference


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

sql> CREATE INDEX PROD_IDX ON INVENTORY (PROD_NAME);


Alternate key length (default 20): 50
"PRODUCT" created
One "*" represents 1000 records

Building "PROD_IDX" ...

175 record(s) processed.

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

sql> CREATE INDEX CLIENT_ORDS ON ORDERS(CLIENT_NO);


"CLIENT_ORDS" created
One "*" represents 1000 records

Building "CLIENT_ORDS" ...

193 record(s) processed.

UniData SQL Commands Reference 55


Reference - UniData SQL Commands

sql> SELECT CLIENT_NO, ID, PRODUCT_NO, QTY FROM ORDERS


sql> WHERE CLIENT_NO = "10004";
Page 1
Client
Number ORDERS Product Nu Qty
---------- ---------- ---------- ------
10004 834 40007 6
40013 6
50010 48
52010 24
53030 6
53000 120
54070 48
55000 24
55040 48
56020 48
55090 24
54010 48
58050 48
10004 911 57090 3
10004 891 40010 2
3 records listed

56 UniData SQL Commands Reference


CREATE SUBTABLE

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.

Representing Multivalues and Multi-Subvalues


You must unnest multivalued and multi-subvalued attributes in the SELECT clause that is a part of
the CREATE SUBTABLE statement. If you do not, the system displays an error message and does
not create the subtable.

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.

UniData SQL Commands Reference 57


Reference - UniData SQL Commands

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.)

Primary and Foreign Keys


The NL0 subtable defines the primary key. The purpose of a primary key is to specify one or more
attributes whose data values are unique among all values for that record. UniData SQL does not
allow a record to be added to a subtable with a duplicate key value.
The primary key of the NL0 subtable becomes the foreign key in the NL1 subtable. To enable
UniData SQL to locate the primary key, you name the NL0 subtable in the REFERENCES clause
of the CREATE SUBTABLE statement that creates the NL1 subtable.
To create an NL2 subtable, use the NL1 subtable’s primary key as the NL2 table’s foreign key, and
list the NL1 subtable name in the REFERENCES clause. No primary key is required when you
create an NL2 subtable, because no lower-level subtable will reference this (NL2) subtable.
However, you may want to define a primary key for NL2 subtables to ensure the uniqueness of the
data. The primary and foreign keys accomplish the same data relationships in subtables as
associations do in UniData SQL base tables.
The following table summarizes the number and value type of attributes required to create primary
and foreign keys in subtables.

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

Primary and Foreign Keys for Subtables

58 UniData SQL Commands Reference


CREATE SUBTABLE

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.

Unique and Generated Keys


You create one of the following types of primary or foreign keys for each subtable:
• Unique keys, in which the uniqueness of the key value depends on the data itself. In this
case, actual attribute names are used in the PRIMARY KEY or FOREIGN KEY clauses.
• Generated keys, in which UniData SQL assigns a number to be part of each key value, so
that the key value is unique even when the data itself is not. In this case, use NL1_KEY or
NL2_KEY in the SELECT statement, rename the selected values, and use these new
names in the PRIMARY KEY or FOREIGN KEY clause. The concept of unique and
generated keys applies to both primary and foreign keys, because the foreign key of the
referencing subtable is the primary key of the referenced subtable.

UniData SQL Commands Reference 59


Reference - UniData SQL Commands

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.

CREATE SUBTABLE Parameters

60 UniData SQL Commands Reference


CREATE SUBTABLE

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.

CREATE SUBTABLE Parameters (continued)

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

sql> CREATE SUBTABLE CLIENTS_NL0 AS


sql> SELECT ID, FNAME, LNAME, COMPANY,
sql> CITY, STATE, ZIP_CODE, COUNTRY
sql> FROM CLIENTS
sql> PRIMARY KEY ID;

Subtable CLIENTS_NL0 created.

The following SELECT statement lists the contents of this subtable:

UniData SQL Commands Reference 61


Reference - UniData SQL Commands

Screen Example

sql> SELECT * FROM CLIENTS_NL0 ORDER BY ID;


Page 1
Client # 9965
First Name Gary
Last Name Phillips
Company Name Bank and Trust
City New York
State/Territory NY
Postal Code 00213
Country USA

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

sql> CREATE SUBTABLE CLIENTS_NL1 AS


sql> SELECT ID, PHONE_TYPE, PHONE_NUM
sql> FROM CLIENTS
sql> UNNEST PHONE_ITEMS
sql> PRIMARY KEY ID, PHONE_TYPE
sql> FOREIGN KEY ID REFERENCES CLIENTS_NL0;

Subtable CLIENTS_NL1 created.

The following statement displays the contents of CLIENTS_NL1:

62 UniData SQL Commands Reference


CREATE SUBTABLE

Screen Example

sql> SELECT * FROM CLIENTS_NL1 ORDER BY ID, PHONE_TYPE;


Page 1
Client # Phone Cate Phone Number
---------- ---------- --------------
9965 Fax 2125556162
9965 Work 2125556161
9966 Fax 0398171799
9966 Work 0398171788
9967 Fax 2045158892
9967 Work 2045154562
...

Unnesting NL1 and NL2


The next series of examples demonstrates creating NL0, NL1, and NL2 subtables that are linked
by primary and foreign keys. This first statement creates the NL0 subtable. Notice that this
statement does not rename the attributes, but uses the attribute names from the CLIENTS table
dictionary. The new subtable contains unique primary keys; no foreign key is allowed, because this
is the top (NL0) level subtable.

Screen Example

sql> CREATE SUBTABLE ORDER_NL0


sql> AS SELECT ID, CLIENT_NO, ORD_DATE, ORD_TIME
sql> FROM ORDERS
sql> PRIMARY KEY ID;

Subtable ORDER_NL0 created.

UniData SQL Commands Reference 63


Reference - UniData SQL Commands

The following SELECT statement lists the contents of this new subtable:

Screen Example

sql> SELECT * FROM ORDER_NL0;


Page 1
Order Client Order Order
Number Number Date Time
---------- ---------- ---------- -------
912 9984 01/13/1996 12:30PM
801 10018 09/28/1995 04:34PM
941 10009 01/14/1996 03:00PM
805 9987 10/05/1995 11:11AM
830 10013 01/24/1996 03:09PM
970 9988 01/15/1996 10:00AM
863 10006 12/04/1995 09:45AM
...
834 10004 01/24/1996 03:27PM
922 10021 01/13/1996 09:39AM
811 10023 10/02/1995 10:10PM
193 records listed

The next example demonstrates creating the NL1 subtable. Notice that multivalued attributes are
selected and unnested in the subtable.

Screen Example

sql> CREATE SUBTABLE ORDER_NL1


sql> AS SELECT ID, PRODUCT_NO, PROD_NAME
sql> FROM ORDERS
sql> UNNEST PRODUCT_NO, PROD_NAME
sql> PRIMARY KEY ID, PRODUCT_NO
sql> FOREIGN KEY ID REFERENCES ORDER_NL0;

64 UniData SQL Commands Reference


CREATE SUBTABLE

The following SELECT statement displays the (unnested) multivalued table, ORDER_NL1:

Screen Example

sql> SELECT * FROM ORDER_NL1;


Page 1
Order
Number Product Nu Product Na
---------- ---------- ----------
912 53000 Printer
Cartridge
801 11000 Computer
941 50000 Computer
...
818 14001 Memory
818 14002 Memory
818 14003 Memory
818 13004 Hard Drive
818 13005 Hard Drive
818 13006 Hard Drive
818 54030 Hard Drive
818 54060 Hard Drive
818 54080 Disk Drive
...
Page 32
Order
Number Product Nu Product Na
---------- ---------- ----------
811 13002 Adapter
811 15001 Modem
487 records listed

UniData SQL Commands Reference 65


Reference - UniData SQL Commands

The next example demonsrates creating the NL2 subtable, which unnests the multi-subvalued
attributes:

Screen Example

sql> CREATE SUBTABLE ORDER_NL2


sql> AS SELECT ID, PRODUCT_NO, COLOR, QTY, PRICE, EPRICE
sql> FROM ORDERS
sql> UNNEST PRODUCT_NO, COLOR, QTY, PRICE
sql> FOREIGN KEY ID, PRODUCT_NO REFERENCES ORDER_NL1;

Subtable ORDER_NL2 created.

The final example displays a portion of the NL2 subtable:

Screen Example

sql> SELECT * FROM ORDER_NL2;


Page 1
Order
Number Product Nu Color Qty Price Extended Pri
---------- ---------- ---------- ------ ---------- ------------
912 53000 N/A 6 $129.95 $779.70
801 11000 Gray 1 $1,799.00 $1,799.00
941 50000 Gray 10 $1,399.99 $13,999.90
805 11140 Gray 5 $149.97 $749.85
805 10120 Standard 25 $429.94 $10,748.50
805 10050 Yellow 13 $29.97 $389.61
805 10150 Silver 15 $48.82 $732.30
805 10070 Silver 999 $34.97 $34,935.03
...
505 records listed

66 UniData SQL Commands Reference


CREATE TABLE

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.”

UniData SQL Commands Reference 67


Reference - UniData SQL Commands

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.

CREATE TABLE Parameters

68 UniData SQL Commands Reference


CREATE TABLE

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.

CREATE TABLE Parameters (continued)

UniData SQL Commands Reference 69


Reference - UniData SQL Commands

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.

CREATE TABLE Parameters (continued)

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]

70 UniData SQL Commands Reference


CREATE TABLE

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

UniData SQL Commands Reference 71


Reference - UniData SQL Commands

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.

72 UniData SQL Commands Reference


CREATE TABLE

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

sql> CREATE TABLE NEW_TAB


sql> (NUM_FLD NUMBER,
sql> CHAR_FLD CHAR(10),
sql> MONEY_FLD NUMBER(10,"MD2$,-"));
3 attribute(s) added.
Create file NEW_TAB, modulo/1,blocksize/1024

The following example lists the dictionary entry for this table:

Screen Example

sql> 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

UniData SQL Commands Reference 73


Reference - UniData SQL Commands

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

sql> CREATE TABLE TEST_TAB (CHAR_FLD CHAR(5), DATE_FLD DATE("D2/"),


sql> NUM_FLD NUMBER(15,"MD2$"), CHAR2_FLD CHAR(12) FORMAT("25C"));
4 attribute(s) added.
Create file TEST_TAB, modulo/1,blocksize/1024

74 UniData SQL Commands Reference


CREATE TABLE

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

sql> CREATE TABLE NEW_TAB


sql> (NUM_FLD NUMBER,
sql> CHAR_FLD CHAR(10),
sql> MONEY_FLD NUMBER(10,"MD2$,-"),
sql> VIRT_FLD NUMBER VIRTUAL("NUM_FLD * MONEY_FLD"));
4 attribute(s) added.
Create file NEW_TAB, modulo/1,blocksize/1024

sql> 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
,-
VIRT_FLD V NUM_FLD * MON 10R S
EY_FLD
5 records listed

UniData SQL Commands Reference 75


Reference - UniData SQL Commands

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.

CREATE VIEW Parameters

76 UniData SQL Commands Reference


CREATE VIEW

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.

CREATE VIEW Parameters (continued)

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

sql> CREATE VIEW NEW_VIEW


sql> AS SELECT * FROM INVENTORY
sql> WHERE COLOR LIKE “B%”;

View NEW_VIEW created.

sql> SELECT ID, PROD_NAME, COLOR


sql> FROM NEW_VIEW
sql> UNNEST COLOR
sql> ORDER BY PROD_NAME;

UniData SQL Commands Reference 77


Reference - UniData SQL Commands

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

78 UniData SQL Commands Reference


DELETE

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

UniData SQL Commands Reference 79


Reference - UniData SQL Commands

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.

DELETE Parameters (continued)

Examples
The following example shows how to delete single and multiple attributes:

Screen Example

sql> DELETE FROM CLIENTS WHERE ID = 9729;


1 record(s) deleted or updated.

The following statement deletes all records from the CLIENTS table:

Screen Example

sql> DELETE FROM CLIENTS;


129 record(s) deleted or updated.

80 UniData SQL Commands Reference


DELETE

The following example displays the data in the multivalued attribute COLOR before a record is
deleted:

Screen Example

sql> SELECT ID, PROD_NAME, COLOR, QTY, PRICE


sql> FROM INVENTORY
sql> UNNEST NL_ALL LINE_ITEMS
sql> WHERE PROD_NAME LIKE “Wrist%”
sql> ORDER BY PROD_NAME;
Page 1
Product Product
Number Name Color Quanti Price
---------- ---------- ---------- ------ ----------
56090 Wrist Rest Blue 500 $12.99
56090 Wrist Rest Gray 500 $12.99
56090 Wrist Rest Green 500 $12.99
56090 Wrist Rest Red 500 $12.99
56090 Wrist Rest Rose 499 $12.99
5 records listed

Next, the record containing the Rose-colored wrist rest is deleted:

Screen Example

sql> DELETE FROM INVENTORY


sql> WHERE PROD_NAME LIKE "Wrist%"
AND COLOR = "Rose";
1 record(s) deleted or updated.

UniData SQL Commands Reference 81


Reference - UniData SQL Commands

Finally, we execute the same SELECT statement as it was executed before the deletion to
demonstrate the deletion:

Screen Example

sql> SELECT ID, PROD_NAME, COLOR, QTY, PRICE


sql> FROM INVENTORY
sql> UNNEST NL_ALL LINE_ITEMS
sql> WHERE PROD_NAME LIKE "Wrist%"
sql> ORDER BY PROD_NAME;
Page 1
Product Product
Number Name Color Quanti Price
---------- ---------- ---------- ------ ----------
56090 Wrist Rest Blue 500 $12.99
56090 Wrist Rest Gray 500 $12.99
56090 Wrist Rest Green 500 $12.99
56090 Wrist Rest Red 500 $12.99
4 records listed

82 UniData SQL Commands Reference


DROP INDEX

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

sql> CREATE INDEX ORDER_IDX ON ORDERS(CLIENT_NO);


"ORDER_IDX" created
One "*" represents 1000 records

Building "ORDER_IDX" ...

193 record(s) processed.

sql> DROP INDEX ORDER_IDX FROM ORDERS;


"ORDER_IDX" deleted

UniData SQL Commands Reference 83


Reference - UniData SQL Commands

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

sql> CREATE SUBTABLE ORDERS_TST AS


sql> SELECT ID, ORD_DATE, ORD_TIME, CLIENT_NO
sql> FROM ORDERS
sql> PRIMARY KEY ID;

Subtable ORDERS_TST created.

sql> DROP SUBTABLE ORDERS_TST;

Subtable ORDERS_TST has been dropped.

84 UniData SQL Commands Reference


DROP TABLE

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

sql> CREATE TABLE NEW_TAB


sql> (NUM_FLD NUMBER,
sql> CHAR_FLD CHAR(10),
sql> MONEY_FLD NUMBER(10,"MD2$,-"));
3 attribute(s) added.
Create file NEW_TAB, modulo/1,blocksize/1024

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
,-

UniData SQL Commands Reference 85


Reference - UniData SQL Commands

4 records listed

sql> DROP TABLE NEW_TAB;


Do you really want to delete file NEW_TAB?(Y/N):y
Deleting file D_NEW_TAB.
Deleting file NEW_TAB.

86 UniData SQL Commands Reference


DROP VIEW

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

sql> CREATE VIEW NEW_VIEW


sql> AS SELECT * FROM INVENTORY
sql> WHERE COLOR LIKE "B%";

View NEW_VIEW created.

sql> SELECT ID, PROD_NAME, COLOR


sql> FROM NEW_VIEW
sql> UNNEST COLOR
sql> WHERE PROD_NAME LIKE "Wrist%"
sql> ORDER BY PROD_NAME;
Page 1
Product Product
Number Name Color
---------- ---------- ----------

UniData SQL Commands Reference 87


Reference - UniData SQL Commands

56090 Wrist Rest Blue


1 records listed

sql> DROP VIEW NEW_VIEW;


View NEW_VIEW has been dropped.

sql> SELECT ID, PROD_NAME, COLOR


sql> FROM NEW_VIEW
sql> WHERE PROD_NAME LIKE "Wrist%"
sql> ORDER BY PROD_NAME;
No privilege on file NEW_VIEW!

Transaction aborted.

88 UniData SQL Commands Reference


EXIT

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
:

UniData SQL Commands Reference 89


Reference - UniData SQL Commands

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:

select * from privilege;

90 UniData SQL Commands Reference


GRANT

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

UniData SQL Commands Reference 91


Reference - UniData SQL Commands

Note
UniData SQL does not display a confirmation message when you grant or revoke privileges.

92 UniData SQL Commands Reference


GRANT

Examples
The following example creates a view on the INVENTORY table, then grants all privileges to
everyone:

Screen Example

sql> CREATE VIEW NEW_VIEW


sql> AS SELECT * FROM INVENTORY
sql> WHERE COLOR LIKE "B%";

View NEW_VIEW created.

sql> GRANT ALL PRIVILEGES ON NEW_VIEW TO PUBLIC;

The following statement grants UPDATE privilege to user samh:

Screen Example

sql> GRANT UPDATE ON NEW_VIEW TO samh;

UniData SQL Commands Reference 93


Reference - UniData SQL Commands

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.

94 UniData SQL Commands Reference


INSERT

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.

UniData SQL Commands Reference 95


Reference - UniData SQL Commands

• 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

96 UniData SQL Commands Reference


INSERT

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.

INSERT Parameters (continued)

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

sql> INSERT INTO INVENTORY VALUES (9999, "3/26/96", "10:30","Camcorder Bag",


"Water-resistant Nylon", "Silver}Gray", "600}600", "25.97}25.97", "70}70");
1 record(s) created.

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.

sql> SELECT * FROM INVENTORY WHERE ID = "19999";


Page 1
INVENTORY 19999
Inventory Date
Inventory Time
Product Name

UniData SQL Commands Reference 97


Reference - UniData SQL Commands

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

98 UniData SQL Commands Reference


LISTDICT

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

UniData SQL Commands Reference 99


Reference - UniData SQL Commands

@UQ PH NAME COMPANY


ADDRESS CITY
STATE ZIP COU
NTRY PHONE PH
ONE_TYPE
PHONE_ITEMS PH PHONE_NUM PHO
Enter <New line> to continue...Q

100 UniData SQL Commands Reference


LOCK TABLE

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.

UniData SQL Commands Reference 101


Reference - UniData SQL Commands

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.

LOCK TABLE Parameters

102 UniData SQL Commands Reference


QUIT

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
:

UniData SQL Commands Reference 103


Reference - UniData SQL Commands

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.

104 UniData SQL Commands Reference


REVOKE

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

sql> REVOKE ALL PRIVILIEGES ON NEW_VIEW FROM PUBLIC;

UniData SQL Commands Reference 105


Reference - UniData SQL Commands

Note
UniData SQL does not display a confirmation message when you grant or revoke privileges.

106 UniData SQL Commands Reference


ROLLBACK

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.

UniData SQL Commands Reference 107


Reference - UniData SQL Commands

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 ]

108 UniData SQL Commands Reference


SELECT

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

UniData SQL Commands Reference 109


Reference - UniData SQL Commands

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.

query_spec Parameters (continued)

110 UniData SQL Commands Reference


SELECT

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.

query_spec Parameters (continued)

UniData SQL Commands Reference 111


Reference - UniData SQL Commands

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.

query_spec Parameters (continued)

112 UniData SQL Commands Reference


SELECT

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.

query_spec Parameters (continued)

UniData SQL Commands Reference 113


Reference - UniData SQL Commands

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.

query_spec Parameters (continued)

114 UniData SQL Commands Reference


SELECT

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).

query_spec Parameters (continued)

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

UniData SQL Commands Reference 115


Reference - UniData SQL Commands

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.

UNNEST Options (continued)

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:

To Unnest This Level Use this Syntax


Multivalue only UNNEST mv_attribute
UNNEST NL1 association
UNNEST NL1 mv_attribute
UNNEST NL1 ms_attribute
UNNEST NL1 mv_attribute, ms_attribute
UNNEST NL_ALL mv_attribute
Multi-subvalue only UNNEST ms_attribute
UNNEST NL2 association_name
UNNEST NL2 ms_attribute
UNNEST NL2 mv_attribute, ms_attribute
(UNNEST NL2 mv_attribute is invalid)

Guide to Unnesting

116 UniData SQL Commands Reference


SELECT

To Unnest This Level Use this Syntax


Multivalue and Multi- UNNEST association_name
subvalue UNNEST mv_attribute, ms_attribute
UNNEST NL_ALL ms_attribute
UNNEST NL_ALL association_name
UNNEST NL_ALL mv_attribute, ms_attribute

Guide to Unnesting (continued)

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

UniData SQL Commands Reference 117


Reference - UniData SQL Commands

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

expression Any combination of attribute names, constants, arithmetic


operators, and UniData SQL functions that together return a value
that determines how data will be ordered. Expressions that contain
spaces must be enclosed in quotation marks.
You may set an attribute to the null value with an expression like
this: attribute_name = NULL.
ASC Orders data in ascending order—lowest value to highest value.
This is the default order.
DESC Orders data in descending order—highest value to lowest value.
EXP Unnests multivalues and multi-subvalues before ordering.
TO filename Places results of the SELECT in a sequential file.

select_stmt Parameters (continued)

118 UniData SQL Commands Reference


SELECT

Parameter Description
INTO temp_table Places results of the SELECT in a temporary table.
LPTR Prints results of the SELECT on the system printer.

select_stmt Parameters (continued)

Examples
Simple Statements
The following example selects all attributes from the CLIENTS table:

Screen Example

sql> SELECT * FROM CLIENTS;


Page 1
CLIENTS 9999
First Name Paul
Last Name Castiglione
Company Name Chez Paul
Address 45, rue de Rivoli
City Paris
State/Territory
Postal Code 75008
Country France
Phone Number Phone Cate
-------------- ----------
3342425544 Work
3342664857 Fax

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

UniData SQL Commands Reference 119


Reference - UniData SQL Commands

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

sql> SELECT ALL PROD_NAME, LINE_ITEMS FROM INVENTORY


sql> WHERE PROD_NAME = "Camera";
Page 1
Product Reorde
Name Color Price Quanti Point Differ
---------- ---------- ---------- ------ ------ ------
Camera Black $129.97 12000 50 11950
Silver $129.97 149 50 99
Camera Black $48.82 800 60 740
Silver $48.82 14985 60 14925
Camera Black $199.97 4998 40 4958
Gray $199.97 3912 40 3872
Camera Black $34.97 8934 40 8894

120 UniData SQL Commands Reference


SELECT

Silver $34.97 6999 40 6959


...

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

sql> SELECT COLOR, MAX(PRICE), SUM(QTY), COUNT(PROD_NAME)


sql> FROM INVENTORY
sql> UNNEST COLOR
sql> WHERE PROD_NAME = "Camera"
sql> GROUP BY COLOR;
Page 1
CNT(Prod

UniData SQL Commands Reference 121


Reference - UniData SQL Commands

Color MAX(Price) SUM(Qu Name)


---------- ---------- ------ --------
Black $339.97 50419 9
Gray $199.97 14715 3
N/A $149.97 5997 1
Red $29.97 8000 1
Silver $339.97 24130 5
Standard $429.94 5973 1
Yellow $29.97 4996 1
========== ====== ========
$429.94 114230 21

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.”

122 UniData SQL Commands Reference


SELECT

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

UNNEST Association – No Option


In this example, the association LINE_ITEMS is unnested. This unnests all associated multivalues
and multi-subvalues; therefore, for each multi-subvalue, the singlevalued attributes are repeated,
as is the (associated) multivalue, PRODUCT_NO.

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

UniData SQL Commands Reference 123


Reference - UniData SQL Commands

969 9988 56080 Black 50 $3.99


969 9988 56080 Red 50 $3.99
969 9988 56080 Blue 50 $3.99
9 records listed

UNNEST NL1 Association


In this example, the UNNEST keyword is used with option NL1, and the association
LINE_ITEMS is listed in the UNNEST clause. This unnests the associated multivalue,
PRODUCT_NO; therefore, for each multivalue, all singlevalued attributes are repeated.

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

124 UniData SQL Commands Reference


SELECT

UNNEST NL2 Association


In this example, the UNNEST keyword is used with option NL2, and the association
LINE_ITEMS is listed in the UNNEST clause. This unnests associated multi-subvalues only;
therefore, for each multi-subvalue, the associated multivalue, PRODUCT_NO, is repeated.

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

UniData SQL Commands Reference 125


Reference - UniData SQL Commands

UNNEST NL_ALL Association


In this example, the UNNEST keyword is used with option NL_ALL, and the association
LINE_ITEMS is listed in the UNNEST clause. This unnests all associated multivalues and multi-
subvalues; therefore, for each multi-subvalue, the singlevalued attributes are repeated, as is the
(associated) multivalue, PRODUCT_NO.

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

UNNEST NL1 Associated Multivalued, Multi-Subvalued Attributes


In this example, the UNNEST keyword is used with option NL1; and the associated attributes
PRODUCT_NO (multivalued) and PRICE (multi-subvalued) are listed in the UNNEST clause.
The NL1 keyword limits unnesting to the associated multivalue (PRODUCT_NO); therefore, for
each multivalue, all singlevalued attributes are repeated.

126 UniData SQL Commands Reference


SELECT

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

UNNEST NL2 Associated Multivalued, Multi-Subvalued Attributes


In this example, the UNNEST keyword is used with option NL2; and the associated attributes
PRODUCT_NO (multivalued) and PRICE (multi-subvalued) are listed in the UNNEST clause.
Option NL2 limits the unnesting to the associated multi-subvalue, PRODUCT_NO; therefore, for
each multi-subvalue, the multivalue is repeated.

Note
This syntax has the same effect as UNNEST NL2 Association.

UniData SQL Commands Reference 127


Reference - UniData SQL Commands

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

UNNEST NL_ALL Associated Multivalued Attribute


In this example, the UNNEST keyword is used with option NL2; and the associated attributes
PRODUCT_NO (multivalued) and PRICE (multi-subvalued) are listed in the UNNEST clause.
This unnests all associated multivalues and multi-subvalues; therefore, for each multi-subvalue,
the singlevalued attributes are repeated, as is the (associated) multivalue, PRODUCT_NO.

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

128 UniData SQL Commands Reference


SELECT

---------- ---------- ---------- ---------- ------ ----------


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

UniData SQL Commands Reference 129


Reference - UniData SQL Commands

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

130 UniData SQL Commands Reference


SET

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.

SET Parameters (continued)

UniData SQL Commands Reference 131


Reference - UniData SQL Commands

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.

SET Parameters (continued)

132 UniData SQL Commands Reference


SET

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.

SET Parameters (continued)

UniData SQL Commands Reference 133


Reference - UniData SQL Commands

Isolation Levels
Your selection of isolation level may affect the access mode and locks set for the next transaction.

Level Access Mode Locks


READ UNCOMMITTED Read only None
READ COMMITTED Choose read-only or UPDATE, INSERT DELETE – exclu-
read/write access; sive record locks (regardless of
defaults to read/write. isolation level)
REPEATABLE READ Choose read-only or • SELECT– shared record locks
read/write access; • UPDATE, INSERT, DELETE –
defaults to read/write. exclusive record locks (regardless
of isolation level)
SERIALIZABLE Choose read-only or • If the target record @ID is
read/write access; supplied – Shared locks on records
defaults to read/write. being read, and exclusive locks on
records being updated.
• If the target record @ID is not
supplied – File-level shared locks
on tables being read, or a record-
level exclusive lock on records
being updated.

Isolation Levels

134 UniData SQL Commands Reference


SET

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

sql> SET PAGESIZE 10;


sql> SET LINESIZE 40;
sql> TTITLE "Page TOP Title";
sql> BTITLE "Page BOTTOM Title";
sql> TTITLE ON;
sql> BTITLE ON;
sql> SELECT ID FROM ORDERS;

The following example shows output from the above commands:

Screen Example

Jun 17 1996 Page 1


Page TOP Title

Order
Number
----------
912
801

Page BOTTOM Title


Enter <New line> to continue...Q

UniData SQL Commands Reference 135


Reference - UniData SQL Commands

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

sql> SET DISPLAY TPMESSAGE ON;

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.

sql> SELECT * FROM INVENTORY WHERE ID = "99999";


Transaction started.
Page 1
INVENTORY 99999
Inventory Date
Inventory Time
Product Name

136 UniData SQL Commands Reference


SET

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

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

sql> SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

sql> UPDATE CLIENTS "9999"


sql> ADD VALUE PHONE_NUM = "3032940000";
Transaction access conflict: update in READ ONLY transaction.

sql> SELECT * FROM CLIENTS WHERE ID='9999';


Page 1
CLIENTS 9999
First Name Paul
Last Name Castiglione
Company Name Chez Paul
Address 45, reu de Rivoli
City Paris
State/Territory
Postal Code 75008
Country France
Phone Number Phone Cate
-------------- ----------
3342425544 Work
3342664857 Fax

1 records listed

UniData SQL Commands Reference 137


Reference - UniData SQL Commands

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

sql> SET WRAP HORI;


SELECT * FROM CLIENTS WHERE ID = 10015;
Page 1
CLIENTS First Name Last Name Company Name
---------- --------------- --------------- ------------------------------
Address City State/Territory Postal Cod
------------------------- --------------- --------------- ----------
Country Phone Number Phone Cate
--------------- -------------- ----------
10015 Cal di Grigorio Regina Flooring
913 Montreal Ave. Regina Saskatchewan S4P3V7
Canada 3067881245 Work

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

138 UniData SQL Commands Reference


SET

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.

This first statement converts PRICE to empty strings in product 10010:

Screen Example

sql> UPDATE ORDERS SET PRICE = "" WHERE PRODUCT_NO = 10010;


4 record(s) updated.

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

sql> COMPUTE AVG OF PRICE ON PROD_NAME;


sql> BREAK ON PROD_NAME SKIP 1;
sql> SELECT PROD_NAME, PRODUCT_NO, PRICE FROM ORDERS
sql> UNNEST PRODUCT_NO
sql> WHERE PRODUCT_NO BETWEEN 10010 AND 10020 ORDER BY PRODUCT_NO;

UniData SQL Commands Reference 139


Reference - UniData SQL Commands

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

sql> SET MISSING NULL;


sql> SET NULL "";
sql> COMPUTE AVG OF PRICE ON PROD_NAME;
sql> BREAK ON PROD_NAME SKIP 1;
sql> SELECT PROD_NAME, PRODUCT_NO, PRICE FROM ORDERS
sql> UNNEST PRODUCT_NO
sql> WHERE PRODUCT_NO BETWEEN 10010 AND 10020 ORDER BY PRODUCT_NO;

140 UniData SQL Commands Reference


SET

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

Finally, we reset MISSING = “” to return to normal processing of empty strings:

Screen Example

sql> SET MISSING "";

sql> COMPUTE AVG OF PRICE ON PROD_NAME;


sql> BREAK ON PROD_NAME SKIP 1;
sql> SELECT PROD_NAME, PRODUCT_NO, PRICE FROM ORDERS
sql> UNNEST PRODUCT_NO
sql> WHERE PRODUCT_NO BETWEEN 10010 AND 10020 ORDER BY PRODUCT_NO;

UniData SQL Commands Reference 141


Reference - UniData SQL Commands

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

142 UniData SQL Commands Reference


SHOW

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

UniData SQL Commands Reference 143


Reference - UniData SQL Commands

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

SHOW Parameters (continued)

Examples
The following example displays the current setting of the PAGESIZE parameter, which is defined
by the SET command:

Screen Example

sql> SHOW PAGESIZE;


Page size is 66

144 UniData SQL Commands Reference


SHOW

The next example uses the SHOW ALL command to display the default settings for the
environment variables set by the SET command:

Screen Example

sql> SHOW ALL;


HEADSEP is '|'
UNDERLINE is '-'
Line size is 80
Newpage is 0
Null is
Number format is
Number width is 10
Page size is 23
Left margin is 0
Pause text is Enter <New line> to continue...
Space is 1
Heading is ON
Underline is ON
Pause is ON
Report is in default form
Sample is OFF.
Head seperate character is on
Header no supress

The final example uses the SET command to assign the letter “N” to represent the null value in
display and print:

Screen Example

sql> SET NULL “N”;


sql> SHOW NULL;
Null text is N

UniData SQL Commands Reference 145


Reference - UniData SQL Commands

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.

146 UniData SQL Commands Reference


TTITLE

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.

UniData SQL Commands Reference 147


Reference - UniData SQL Commands

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

148 UniData SQL Commands Reference


TTITLE

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.

Print Clause Parameters

UniData SQL Commands Reference 149


Reference - UniData SQL Commands

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.

Print Clause Parameters (continued)

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.

150 UniData SQL Commands Reference


TTITLE

• Numeric Format Options – Use the options in the following table to build a display mask
for formatting numeric values.

Option Explanation Example


9 Determines number of digits displayed. 9999
0 Display leading zeros. 0999
$ Prefix displayed value with a dollar sign. $9999
B Print leading zeros as blank. B999
MI Display minus sign (-) after a negative 9999MI
value.
PR Display a negative value in angle brackets 9999PR
. Align on the decimal point. 99.99
, Insert a comma every three digits. 99,999
V Multiply the value by the n power of 10, 999V99
where n is the number of 9s after V.
EEEE Display the scientific notation (the format 9.99EEEE
must contain four Es).

format Numeric Options

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.

UniData SQL Commands Reference 151


Reference - UniData SQL Commands

Examples
The following example defines a centered title of “Open Orders.” The SELECT statement displays
the title.

Screen Example

sql> TTITLE CENTER "Open Orders" SKIP 3;


sql> TTITLE ON;
sql> SELECT CLIENT_NO, PRODUCT_NO, QTY, PRICE FROM ORDERS
sql> UNNEST LINE_ITEMS
sql> ORDER BY CLIENT_NO;

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
...

152 UniData SQL Commands Reference


TTITLE

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

sql> COLUMN CLIENT_NO OLD_VALUE old NEW_VALUE new;


sql> BREAK ON CLIENT_NO SKIP PAGE;
sql> TTITLE LEFT "Client: "TAB 5 new;
sql> TTITLE ON;
sql> BTITLE COL 15 "Client: "TAB 5 old;
sql> BTITLE ON;
sql> BREAK ON CLIENT_NO;

sql> SELECT CLIENT_NO, PRODUCT_NO, QTY, PRICE FROM ORDERS


sql> UNNEST LINE_ITEMS
sql> ORDER BY CLIENT_NO;
Client:
Client
Number Product Nu Qty Price
---------- ---------- ------ ----------
10006 5 $159.95
11140 2 $149.97
13001 25 $94.00
52000 1 $199.99
838 53050 1
...
9967 10050 1 $29.97
11100 1 $139.86
11120 2 $14.97
11130 1 $49.97
Client: 9967
Client: 9967
Client
Number Product Nu Qty Price
---------- ---------- ------ ----------
11140 1 $149.97
12005 1 $400.00

UniData SQL Commands Reference 153


Reference - UniData SQL Commands

...
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

154 UniData SQL Commands Reference


UPDATE

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.

UniData SQL Commands Reference 155


Reference - UniData SQL Commands

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

156 UniData SQL Commands Reference


UPDATE

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.

UPDATE Parameters (continued)

Adding Multivalues and Multi-Subvalues


To add multivalues or multi-subvalues to an attribute, use an ADD VALUE or ADD SUBVALUE
clause. These clauses insert the value or subvalue into a record as follows:
• ADD VALUE appends the value to the end of a multivalued or multi-subvalued attribute,
after satisfying the conditions specified by the WHERE clause. Separate multivalues with
value marks ( } ), and multi-subvalues with subvalue marks ( | ).
• ADD SUBVALUE appends the subvalue to the end of the group of multi-subvalues after
satisfying the conditions specified by the WHERE clause.
• A multivalued constant cannot contain the right brace (}) as data. UniData SQL interprets
this as a value mark.
• You cannot include value marks in a string constant with the ADD SUBVALUE
keywords. Use ADD VALUE to add multivalues, and ADD SUBVALUE to add multi-
subvalues.

UniData SQL Commands Reference 157


Reference - UniData SQL Commands

Null Value Handling


Remember the following points when using the keyword NULL:
• You cannot use INSERT or UPDATE command to add the null value, along with other
values, into a multivalued or multi-subvalued attribute. This is because UniData 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.
• With null value handling turned off, the keyword NULL inserts an empty string.
• The null value is not valid for @ID.

Examples
The following example updates the address for CLIENTS record 9982:

Screen Example

sql> UPDATE CLIENTS "9982"


sql> SET ADDRESS = "10318 West Bend Ave.";
1 record(s) updated.

sql> SELECT * FROM CLIENTS


sql> WHERE ID = 9982;
Page 1
CLIENTS 9982
First Name Marc
Last Name Willette
Company Name Regal Oil
Address 10318 West Bend Ave.
City Los Angeles
State/Territory CA
Postal Code 85694
Country USA

158 UniData SQL Commands Reference


UPDATE

Phone Number Phone Cate


-------------- ----------
3102584569 Work
3102584568 Fax

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

sql> SELECT * FROM CLIENTS


sql> WHERE ID = 9982;
Page 1
CLIENTS 9982
First Name Marc
Last Name Willette
Company Name Regal Oil
Address 10318 West Bend Ave.
City Los Angeles
State/Territory CA
Postal Code 85694
Country USA
Phone Number Phone Cate
-------------- ----------
3102584569 Work
3102584568 Fax
1 records listed

UniData SQL Commands Reference 159


Reference - UniData SQL Commands

Then, we add the new multivalues and display the record again.

Screen Example

sql> UPDATE CLIENTS "9982"


sql> ADD VALUE PHONE_NUM = "7197789615}7197789509",
sql> PHONE_TYPE = "Mobile}Pager";
1 record(s) updated.
sql> SELECT * FROM CLIENTS
sql> WHERE ID = 9982;
Page 1
CLIENTS 9982
First Name Marc
Last Name Willette
Company Name Regal Oil
Address 10318 West Bend Ave.
City Los Angeles
State/Territory CA
Postal Code 85694
Country USA
Phone Number Phone Cate
-------------- ----------
3102584569 Work
3102584568 Fax
7197789615 Mobile
7197789509 Pager
1 records listed

160 UniData SQL Commands Reference


Appendix A - Defining
Attributes

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

UniData SQL Commands Reference 161


Appendix A - Defining Attributes

Default Format and Conversion Codes


When you define an attribute using CREATE TABLE or ALTER TABLE, the following default
formats and conversion codes are applied if none is explicitly specified. These formats and
conversions determine how attribute values are displayed. Conversion is applied first, then format.

Data Default Default


What Is Displayed
Type Format Conversion
character xL none x characters wide, left-justified
date 10L D2/ 10 characters wide, left-justified,
MM/DD/YY
number 10R none 10 digits wide, right-justified
long 10R none 10 digits wide, right-justified

Default Attribute Display Format

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”)]

162 UniData SQL Commands Reference


Attribute 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.

• An attribute name can be no longer than 30 characters.


• The name cannot be a UniData SQL reserved word.
• The name must be unique among attribute names within the table, subtable, or view.

UniData SQL Commands Reference 163


Appendix A - Defining Attributes

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.

164 UniData SQL Commands Reference


Data Type

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])]

UniData SQL Commands Reference 165


Appendix A - Defining Attributes

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.

166 UniData SQL Commands Reference


Data Type

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.

UniData SQL Commands Reference 167


Appendix A - Defining Attributes

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

168 UniData SQL Commands Reference


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

Conversion Codes (continued)

UniData SQL Commands Reference 169


Appendix A - Defining Attributes

Virtual Attributes (IDESC or VIRTUAL)


A virtual attribute is a dictionary record definition that relies on a formula to derive its value.
Syntax:
[IDESC | VIRTUAL] (“virt_definition”)
The IDESC or VIRTUAL keyword follows the data type keyword. The formula may be an
expression, function, or UniBasic subroutine. For instructions on writing virtual attributes, see
Using UniData.
You must enclose virtual attribute descriptions in quotation marks.

170 UniData SQL Commands Reference


Location (LOC)

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)

UniData SQL Commands Reference 171


Appendix A - Defining Attributes

Display Name (DISP)


DISP provides a name for the attribute to be used as a column header. Generally, attribute_name is
not suitable for display purposes because it is abbreviated or is not meaningful.

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.

172 UniData SQL Commands Reference


FORMAT

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]”)

Display Format Options


The following table shows the display format options.

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.

Display Format Options

UniData SQL Commands Reference 173


Appendix A - Defining Attributes

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).

Display Format Options (continued)

174 UniData SQL Commands Reference


Value Code Specification

Value Code Specification


SM
SM specifies the value type.
Syntax:
SM(“{S | MV | MS}”)
Valid types are:

Type Explanation
MV Multivalued attribute
MS Multi-subvalued attribute
S Singlevalued attribute (default)

Value Codes

UniData SQL Commands Reference 175


Appendix A - Defining Attributes

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”)

176 UniData SQL Commands Reference


Appendix B - Unnesting
Attributes

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

UniData SQL Commands Reference 177


Appendix B - Unnesting Attributes

Unnesting Associated Attributes


The levels of attributes included in the UNNEST clause determine the level of unnesting. The
options listed below further modify this determination:
• NL1 – Restricts unnesting to level 1, even if a lower-level attribute is listed. Unnests
associated multivalued attributes, repeating the values in the associated singlevalued
attribute.
• NL2 – Restricts unnesting to level 2, even if a higher-level attribute is listed. Unnests
associated multi-subvalued attributes, repeating the values in the associated multivalued
attribute.
• NL_ALL – Unnests all levels of all attributes listed. If only multivalued attributes are
listed, repeats the values in singlevalued attributes. If only multi-subvalued attributes are
listed, repeats the values in singlevalued and multivalued attributes.
• No Option – Unnesting level is determined by the attribute(s) listed in the UNNEST
clause.

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:

select s_fld, mv_fld from tab1 unnest NL2 mv_fld;

178 UniData SQL Commands Reference


Unnesting Associated Attributes

Sample Table for Unnesting Examples


This first example creates a table to use in the unnesting examples:

Screen Example

sql> create table tab1


( s_fld char(5),
mv1_fld char(5) sm("MV") assoc("a_1"),
mv2_fld char(5) sm("MV") assoc("a_1"),
ms1_fld char(5) sm("MS") assoc("a_1"),
ms2_fld char(5) sm("MS") assoc("a_1")
) modulo 1;
5 attribute(s) added.
Create file tab1, modulo/1,blocksize/1024

This example displays the dictionary of the table using the UniData SQL LISTDICT command:

Screen Example

sql> listdict tab1;


Page 1
@ID TYP LOC CONV NAME FORMAT SM ASSOC
--------------- --- ------------- ---- --------------- ------ -- ----------
@ID D 0 tab1 10L S
s_fld D 1 5L S
mv1_fld D 2 5L MV a_1
mv2_fld D 3 5L MV a_1
ms1_fld D 4 5L MS a_1
ms2_fld D 5 5L MS a_1
a_1 PH ms2_fld ms1_f
ld mv2_fld mv
1_fld
7 records listed

Finally, the following INSERT statements populate the table with data that will help demonstrate
unnesting:

UniData SQL Commands Reference 179


Appendix B - Unnesting Attributes

Screen Example

sql> insert into tab1 values


( 1, "A", "A1}A2}A3", "a1}a2", "A1-1|A1-2}A2-1|A2-2|A2-3}A3-1", "a1-1|a1-2" );
1 record(s) created.
sql> insert into tab1 values
( 2, "B", "B1}B2}B3", "b1}b2}b3}b4}b5", "B1-1}B2-1}B3-1", "b1-1|b1-2|b1-3" );
1 record(s) created.
sql> insert into tab1 values
( 3, "C", "C1", "c1}c2", "C1-1|C1-2|C1-3", "c1-1|c1-2" );
1 record(s) created.

The following SELECT statement displays the contents of the table as stored in nf2 (nested)
format:

Screen Example

sql> select * from tab1;


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
A2 a2 A2-1
A2-2
A2-3
A3 A3-1
2 B B1 b1 B1-1 b1-1
b1-2
b1-3
B2 b2 B2-1
B3 b3 B3-1
b4
b5
3 C C1 c1 C1-1 c1-1
C1-2 c1-2
C1-3
c2
3 records listed

180 UniData SQL Commands Reference


Unnesting Associated Attributes

Unnesting Associated Multivalued Attributes


The following UNNEST clause syntax unnests multivalued attributes; all of the example UniData
SQL statements produce the same results:
• UNNEST NL1 association_name
for example: select * from tab1 unnest NL1 a_1;
• UNNEST multivalued_attribute
for example: select * from tab1 unnest mv1_fld;
• UNNEST NL1 multivalued_attribute
for example: select * from tab1 unnest NL1 mv1_fld;
• UNNEST NL1 multivalued_attribute, multi-subvalued_attribute
for example: select * from tab1 unnest NL1 mv1_fld,ms1_fld;
• UNNEST NL_ALL multivalued_attribute
for example: select * from tab1 unnest NL_ALL mv1_fld;

Note
When you unnest associated multivalued attributes, values in the associated singlevalued attributes
are repeated.

UniData SQL Commands Reference 181


Appendix B - Unnesting Attributes

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

Unnesting Associated Multi-Subvalued Attributes


The following UNNEST clause syntax unnests multi-subvalued attributes only. All of the example
UniData SQL statements produce the same results.
• UNNEST multi-subvalued_attribute
for example: select * from tab1 unnest ms1_fld;
• UNNEST NL2 association_name
for example: select * from tab1 unnest NL2 a_1;
• UNNEST NL2 multi-subvalued_attribute
for example: select * from tab1 unnest NL2 ms1_fld;

182 UniData SQL Commands Reference


Unnesting Associated Attributes

• UNNEST NL2 multivalued_attribute, multi-subvalued_attribute


for example: select * from tab1 unnest NL2 mv1_fld,ms1_fld;

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

UniData SQL Commands Reference 183


Appendix B - Unnesting Attributes

Unnesting All Attributes in an Association


The following UNNEST clause syntax unnests multivalued and multi-subvalued attributes of the
same association:
• UNNEST association_name
for example: select * from tab1 unnest a_1;
• UNNEST multivalued_attribute, multi-subvalued attribute
for example: select * from tab1 unnest mv1_fld,ms1_fld;
• UNNEST NL_ALL multi-subvalued_attribute
for example: select * from tab1 unnest NL_ALL ms1_fld;
• UNNEST NL_ALL association_name
for example: select * from tab1 unnest NL_ALL a_1;
• UNNEST NL_ALL multivalued attribute, multi-subvalued_attribute
for example: select * from tab1 unnest NL_ALL mv1_fld,ms1_fld;

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

184 UniData SQL Commands Reference


Unnesting Associated Attributes

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

UniData SQL Commands Reference 185


Appendix B - Unnesting Attributes

Unnesting Unassociated Attributes


Unnesting unassociated attributes results in a Cartesian product: every multivalue is listed with
every multi-subvalue, as the following example demonstrates. In this example, we create a table
containing unassociated multivalues and multi-subvalues for demonstration purposes.

Screen Example

sql> create table tab1


( unassoc_MV char(7) sm("MV"),
unassoc_MS char(7) sm("MS")
) modulo 1;
2 attribute(s) added.
Create file tab1, modulo/1,blocksize/1024

Here is the structure of the table created above, as displayed with the LISTDICT command:

Screen Example

sql> listdict tab1;


Page 1
@ID TYP LOC CONV NAME FORMAT SM ASSOC
--------------- --- ------------- ---- --------------- ------ -- ----------
@ID D 0 tab1 10L S
unassoc_MV D 1 7L MV
unassoc_MS D 2 7L MS
3 records listed

Now we populate the table:

Screen Example

sql> insert into tab1 values ( 1, "a}b}c", "a1|a2}b1|b2|b3}c1" );


1 record(s) created.

186 UniData SQL Commands Reference


Unnesting Unassociated Attributes

insert into tab1 values ( 2, "AA", "A1|A2}B1|B2|B3}C1" );


1 record(s) created.

Here is the data as it is stored in tab1:

Screen Example

sql> SELECT * FROM tab1;


Page 1
tab1 unassoc unassoc
---------- ------- -------
1 a a1
1 a a1
b a2
c b1
b2
b3
c1
2 AA A1
A2
B1
B2
B3
C1
2 records listed

UniData SQL Commands Reference 187


Appendix B - Unnesting Attributes

Selecting unassociated attributes results in a Cartesian product, as illustrated in the following


example:

Screen Example

sql>SELECT * FROM tab1


sql>UNNEST unassoc_MV, unassoc_MS;
Page 1
tab1 unassoc unassoc
---------- ------- -------
1 a a1
1 a a2
1 a b1
1 a b2
1 a b3
1 a c1
1 b a1
1 b a2
1 b b1
1 b b2
1 b b3
1 b c1
1 c a1
1 c a2
1 c b1
1 c b2
1 c b3
1 c c1
2 AA A1
2 AA A2
Page 2
tab1 unassoc unassoc
---------- ------- -------
2 AA B1
2 AA B2
2 AA B3
2 AA C1
24 records listed

188 UniData SQL Commands Reference


Appendix C - Creating
Subtables

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.

This appendix is divided into the following sections:


• Base Tables
Dictionary listings of the tables from which the subtables are created.
• CREATE SUBTABLE Examples
Examples of all CREATE SUBTABLE statements.

UniData SQL Commands Reference 189


Appendix C - Creating Subtables

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

190 UniData SQL Commands Reference


Base Tables

PHONE V SUBR("PHONE_F Phone Number 20R MV PHONE_ITEM


MT",PHONE_NUM S
,COUNTRY)
ZIP V SUBR("PSTLCOD Postal Code 10R S
E_FMT",@RECOR
D)
NEXT_CLI_NO X 10096 Next Client #
21 records listed

T_INVENTORY
Screen Example

sql> listdict T_INVENTORY;


Page 1
@ID TYP LOC CONV NAME FORMAT SM ASSOC
--------------- --- ------------- ---- --------------- ------ -- ----------
@ID D 0 T_INVENTORY 10L S
ID D 0 Product Number 10R S
ID1 D 0 T_INVENTORY 10L S
INV_DATE D 1 D4/ Inventory Date 10R S
INV_TIME D 2 MTH Inventory Time 5R S
PROD_NAME D 3 Product Name 10T S
FEATURES D 4 Features 30T S
COLOR D 5 Color 10T MV LINE_ITEMS
QTY D 6 Quantity 6R MV LINE_ITEMS
PRICE D 7 MD2, Price 10R MV LINE_ITEMS
$
REORDER D 8 Reorder Point 6R MV LINE_ITEMS
@UQ PH INV_DATE INV_
TIME PROD_NAM
E FEATURES LI
NE_ITEMS

UniData SQL Commands Reference 191


Appendix C - Creating Subtables

LINE_ITEMS PH COLOR PRICE Q


TY REORDER DI
FF
@ORIGINAL SQ @ID
@SYNONYM SQ ID1
DIFF V QTY - REORDER Difference 6R MV LINE_ITEMS
NEXT_INV_NO X 58051 Next Inventory
#
17 records listed

T_ORDERS
Screen Example

sql> listdict T_ORDERS;


Page 1
@ID TYP LOC CONV NAME FORMAT SM ASSOC
--------------- --- ------------- ---- --------------- ------ -- ----------
@ID D 0 T_ORDERS 10L S
ID D 0 Order Number 10R S
ID1 D 0 T_ORDERS 10L S
ORD_DATE D 1 D4/ Order Date 10R S
ORD_TIME D 2 MTH Order Time 7R S
CLIENT_NO D 3 Client Number 10R S
PRODNO D 4 PRODNO 10L MV LINE_ITEMS
PRODUCT_NO D 4 Product Number 10R MV LINE_ITEMS
COLOR D 5 Color 10T MS LINE_ITEMS
QTY D 6 Qty 6R MS LINE_ITEMS
PRICE D 7 MD2, Price 10R MS LINE_ITEMS
$
@UQ PH ORD_DATE ORD_
TIME CLIENT_N
O NAME COMPAN
Y ADDRESS CIT
Y STATE ZIP C
OUNTRY PHONE_
ITEMS LINE_IT
EMS GRAND_TOT
AL

192 UniData SQL Commands Reference


Base Tables

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')

UniData SQL Commands Reference 193


Appendix C - Creating Subtables

PHONE V TRANS('CLIENT Phone Number 20R MV PHONE_ITEM


S',CLIENT_NO, S
'PHONE_NUM','
X'); TRANS('C
LIENTS',CLIEN
T_NO,'COUNTRY
','X'); SUBR(
"PHONE_FMT",@
1,@2)
PHONE_TYPE V TRANS('CLIENT Phone Type 10T MV PHONE_ITEM
S',CLIENT_NO, S
'PHONE_TYPE',
'X')
PROD_NAME V TRANS('INVENT Product Name 10T MV LINE_ITEMS
ORY',PRODUCT_
NO,'PROD_NAME
','X')
STATE V TRANS('CLIENT State 15T S
S',CLIENT_NO,
'STATE','X')
ZIP V TRANS('CLIENT Postal Code 10R S
S',CLIENT_NO,
-1,'X'); SUB
R("PSTLCODE_F
MT",@1)
NEXT_ORD_NO X 983 Next Order #
30 records listed

194 UniData SQL Commands Reference


CREATE SUBTABLE Examples

CREATE SUBTABLE Examples


The following sample SQL scripts create subtables from the base tables T_CLIENTS,
T_INVENTORY, and T_ORDER. to produce NL0, NL1, and NL2 subtables with names like
"XXXnyy", where:
XXX = CLI, INV or ORD
n = nesting level: 0, 1 or 2
yy = sequential number within XXXn group

T_CLIENTS NL0 Subtables


CLI001: NL0 Subtable, UNIQUE PKEY, all Single-value D-fields

Program Example

create subtable CLI001 (pkID1,FNAME,LNAME,COMPANY,


CITY,STATE,ZIP_CODE,COUNTRY) as
select ID1,FNAME,LNAME,COMPANY,
CITY,STATE,ZIP_CODE,COUNTRY
from T_CLIENTS
primary key pkID1;

CLI002: NL0 Subtable, UNIQUE PKEY, Partial view

Program Example

create subtable CLI002 (pkID1,FNAME,LNAME) as


select ID1,FNAME,LNAME
from T_CLIENTS
primary key pkID1;

UniData SQL Commands Reference 195


Appendix C - Creating Subtables

CLI003: NL0 Subtable w/Virtual fld, UNIQUE PKEY

Program Example

create subtable CLI003 (pkID1,FNAME,LNAME,COMPANY,


CITY,STATE,ZIP_CODE,COUNTRY,vNAME,vZIP) as
select ID1,FNAME,LNAME,COMPANY,
CITY,STATE,ZIP_CODE,COUNTRY,NAME,ZIP
from T_CLIENTS
primary key pkID1;

T_CLIENTS NL1 Subtables


CLI101: NL1 Subtable, UNNEST assoc, UNIQUE PKEY

Program Example

create subtable CLI101 (pkID1,pkPHONE_TYPE,PHONE_NUM) as


select ID1,PHONE_TYPE,PHONE_NUM
from T_CLIENTS
unnest PHONE_ITEMS
primary key pkID1,pkPHONE_TYPE
foreign key pkID1 references CLI001;

CLI102: NL1 Subtable, UNNEST assoc, GENERATED PKEY, FKEY

Program Example

create subtable CLI102 (pkID1,p1PHONE_TYPE,PHONE_TYPE,PHONE_NUM) as


select ID1,NL1_KEY(PHONE_TYPE),PHONE_TYPE,PHONE_NUM
from T_CLIENTS
unnest PHONE_ITEMS
primary key pkID1,p1PHONE_TYPE
foreign key pkID1 references CLI001;

196 UniData SQL Commands Reference


CREATE SUBTABLE Examples

CLI103: CreateNL1 Subtable w/Virtual fld, UNNEST assoc,


UNIQUE PKEY

Program Example

create subtable CLI103 (pkID1,pkPHONE_TYPE,PHONE_NUM,vPHONE) as


select ID1,PHONE_TYPE,PHONE_NUM,PHONE
from T_CLIENTS
unnest PHONE_ITEMS
primary key pkID1,pkPHONE_TYPE
foreign key pkID1 references CLI001;

CLI104: NL1 Subtable w/Virtual, UNNEST assoc, GENERATED


PKEY, FKEY

Program Example

create subtable CLI104 (pkID1,p1PHONE_TYPE,PHONE_TYPE,PHONE_NUM,vPHONE) as


select ID1,NL1_KEY(PHONE_TYPE),PHONE_TYPE,PHONE_NUM,PHONE
from T_CLIENTS
unnest PHONE_ITEMS
primary key pkID1,p1PHONE_TYPE
foreign key pkID1 references CLI001;

CLI105: NL1 Subtable, UnAssociated MV field, UNIQUE PKEY

Program Example

create subtable CLI105 (pkID1,pkADDRESS) as


select ID1,ADDRESS
from T_CLIENTS
unnest ADDRESS
primary key pkID1,pkADDRESS
foreign key pkID1 references CLI001;

UniData SQL Commands Reference 197


Appendix C - Creating Subtables

T_INVENTORY NL0 Subtable


INV001: NL0 Subtable, UNIQUE PKEY, all Single-value D-fields

Program Example

create subtable INV001 (pkID1,INV_DATE,INV_TIME,PROD_NAME,FEATURES) as


select ID1,INV_DATE,INV_TIME,PROD_NAME,FEATURES
from T_INVENTORY
primary key pkID1;

T_INVENTORY NL1 Subtables


INV101: NL1 Subtable, UNNEST field, UNIQUE PKEY, FKEY

Program Example

create subtable INV101 (pkID1,pkCOLOR,QTY,PRICE) as


select ID1,COLOR,QTY,PRICE
from T_INVENTORY
unnest COLOR
primary key pkID1,pkCOLOR
foreign key pkID1 references INV001;

INV102: NL1 Subtable, UNNEST field, FKEY

Program Example

create subtable INV102 (ID1,COLOR,QTY,PRICE) as


select ID1,COLOR,QTY,PRICE
from T_INVENTORY
unnest COLOR
foreign key ID1 references INV001;

198 UniData SQL Commands Reference


CREATE SUBTABLE Examples

INV103: NL1 Subtable, UNNEST NL1 field, UNIQUE PKEY, FKEY

Program Example

create subtable INV103 (pkID1,pkCOLOR,QTY,PRICE) as


select ID1,COLOR,QTY,PRICE
from T_INVENTORY
unnest NL1 COLOR
primary key pkID1,pkCOLOR
foreign key pkID1 references INV001;

INV104: NL1 Subtable, UNNEST NL1 field, FKEY

Program Example

create subtable INV104 (ID1,COLOR,QTY,PRICE) as


select ID1,COLOR,QTY,PRICE
from T_INVENTORY
unnest NL1 COLOR
foreign key ID1 references INV001;

INV105: NL1 Subtable, UNNEST NL_ALL field, UNIQUE PKEY, FKEY

Program Example

create subtable INV105 (pkID1,pkCOLOR,QTY,PRICE) as


select ID1,COLOR,QTY,PRICE
from T_INVENTORY
unnest NL_ALL COLOR
primary key pkID1,pkCOLOR
foreign key pkID1 references INV001;

UniData SQL Commands Reference 199


Appendix C - Creating Subtables

INV106: NL1 Subtable, UNNEST NL_ALL field, FKEY

Program Example

create subtable INV106 (ID1,COLOR,QTY,PRICE) as


select ID1,COLOR,QTY,PRICE
from T_INVENTORY
unnest NL_ALL COLOR
foreign key ID1 references INV001;

INV107: NL1 Subtable, UNNEST field, GENERATED PKEY, FKEY

Program Example

create subtable INV107 (pkID1,p1COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(COLOR),COLOR,QTY,PRICE
from T_INVENTORY
unnest COLOR
primary key pkID1,p1COLOR
foreign key pkID1 references INV001;

INV108: NL1 Subtable, UNNEST field, FKEY

Program Example

create subtable INV108 (ID1,p1COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(COLOR),COLOR,QTY,PRICE
from T_INVENTORY
unnest COLOR
foreign key ID1 references INV001;

200 UniData SQL Commands Reference


CREATE SUBTABLE Examples

INV109: NL1 Subtable, UNNEST NL1 field, GENERATED PKEY,


FKEY

Program Example

create subtable INV109 (pkID1,p1COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(COLOR),COLOR,QTY,PRICE
from T_INVENTORY
unnest NL1 COLOR
primary key pkID1,p1COLOR
foreign key pkID1 references INV001;

INV110: NL1 Subtable, UNNEST NL1 field, FKEY

Program Example

create subtable INV110 (ID1,p1COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(COLOR),COLOR,QTY,PRICE
from T_INVENTORY
unnest NL1 COLOR
foreign key ID1 references INV001;

INV111: NL1 Subtable, UNNEST NL_ALL field, GENERATED


PKEY, FKEY

Program Example

create subtable INV111 (pkID1,p1COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(COLOR),COLOR,QTY,PRICE
from T_INVENTORY
unnest NL_ALL COLOR
primary key pkID1,p1COLOR
foreign key pkID1 references INV001;

UniData SQL Commands Reference 201


Appendix C - Creating Subtables

INV112: NL1 Subtable, UNNEST NL_ALL field, FKEY

Program Example

create subtable INV112 (ID1,p1COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(COLOR),COLOR,QTY,PRICE
from T_INVENTORY
unnest NL_ALL COLOR
foreign key ID1 references INV001;

INV113: NL1 Subtable, UNNEST NL1 assoc, UNIQUE PKEY, FKEY

Program Example

create subtable INV113 (pkID1,pkCOLOR,QTY,PRICE) as


select ID1,COLOR,QTY,PRICE
from T_INVENTORY
unnest NL1 LINE_ITEMS
primary key pkID1,pkCOLOR
foreign key pkID1 references INV001;

INV114: NL1 Subtable, UNNEST NL1 assoc, FKEY

Program Example

create subtable INV114 (ID1,COLOR,QTY,PRICE) as


select ID1,COLOR,QTY,PRICE
from T_INVENTORY
unnest NL1 LINE_ITEMS
foreign key ID1 references INV001;

202 UniData SQL Commands Reference


CREATE SUBTABLE Examples

INV115: NL1 Subtable, UNNEST NL1 assoc, GENERATED PKEY,


FKEY

Program Example

create subtable INV115 (pkID1,p1COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(COLOR),COLOR,QTY,PRICE
from T_INVENTORY
unnest NL1 LINE_ITEMS
primary key pkID1,p1COLOR
foreign key pkID1 references INV001;

INV116: NL1 Subtable, UNNEST NL1 assoc, FKEY

Program Example

create subtable INV116 (ID1,p1COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(COLOR),COLOR,QTY,PRICE
from T_INVENTORY
unnest NL1 LINE_ITEMS
foreign key ID1 references INV001;

INV117: NL1 Subtable, UNNEST field, GENERATED PKEY, FKEY

Program Example

create subtable INV117 (pkID1,p1COLOR_QTY_PRICE,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(COLOR,QTY,PRICE),COLOR,QTY,PRICE
from T_INVENTORY
unnest NL1 COLOR,QTY,PRICE
primary key pkID1,p1COLOR_QTY_PRICE
foreign key pkID1 references INV001;

UniData SQL Commands Reference 203


Appendix C - Creating Subtables

INV118: NL1 Subtable, UNNEST NL1 assoc, UNIQUE PKEY, FKEY

Program Example

create subtable INV118 (pkID1,pkCOLOR,QTY,PRICE,REORDER) as


select ID1,COLOR,QTY,PRICE,REORDER
from T_INVENTORY
unnest NL1 LINE_ITEMS
primary key pkID1,pkCOLOR
foreign key pkID1 references INV001;

INV119: NL1 Subtable w/Virtual, UNNEST NL1 assoc, UNIQUE


PKEY, FKEY

Program Example

create subtable INV119 (pkID1,pkCOLOR,QTY,PRICE,REORDER,vDIFF) as


select ID1,COLOR,QTY,PRICE,REORDER,DIFF
from T_INVENTORY
unnest NL1 LINE_ITEMS
primary key pkID1,pkCOLOR
foreign key pkID1 references INV001;

T_ORDERS NL0 Subtables


ORD001: NL0 Subtable, UNIQUE PKEY, all Single-value D-fields

Program Example

create subtable ORD001 (pkID1,ORD_DATE,ORD_TIME,CLIENT_NO) as


select ID1,ORD_DATE,ORD_TIME,CLIENT_NO
from T_ORDERS
primary key pkID1;

204 UniData SQL Commands Reference


CREATE SUBTABLE Examples

ORD002: NL0 Subtable w/Virtual, UNIQUE PKEY,


Single-value D-fields

Program Example

create subtable ORD002 (pkID1,ORD_DATE,ORD_TIME,CLIENT_NO,vNAME,vCOMPANY) as


select ID1,ORD_DATE,ORD_TIME,CLIENT_NO,NAME,COMPANY
from T_ORDERS
primary key pkID1;

T_ORDERS NL1 Subtables


ORD101: NL1 Subtable, UNNEST field, UNIQUE PKEY, FKEY

Program Example

create subtable ORD101 (pkID1,pkPRODNO) as


select ID1,PRODNO
from T_ORDERS
unnest PRODNO
primary key pkID1,pkPRODNO
foreign key pkID1 references ORD001;

ORD102: NL1 Subtable, UNNEST field, FKEY

Program Example

create subtable ORD102 (ID1,PRODNO) as


select ID1,PRODNO
from T_ORDERS
unnest PRODNO
foreign key ID1 references ORD001;

UniData SQL Commands Reference 205


Appendix C - Creating Subtables

ORD103: NL1 Subtable, UNNEST NL1 field, UNIQUE PKEY, FKEY

Program Example

create subtable ORD103 (pkID1,pkPRODNO) as


select ID1,PRODNO
from T_ORDERS
unnest NL1 PRODNO
primary key pkID1,pkPRODNO
foreign key pkID1 references ORD001;

ORD104: NL1 Subtable, UNNEST NL1 field, FKEY

Program Example

create subtable ORD104 (ID1,PRODNO) as


select ID1,PRODNO
from T_ORDERS
unnest NL1 PRODNO
foreign key ID1 references ORD001;

ORD105: NL1 Subtable, UNNEST NL_ALL field, UNIQUE PKEY,


FKEY

Program Example

create subtable ORD105 (pkID1,pkPRODNO) as


select ID1,PRODNO
from T_ORDERS
unnest NL_ALL PRODNO
primary key pkID1,pkPRODNO
foreign key pkID1 references ORD001;

206 UniData SQL Commands Reference


CREATE SUBTABLE Examples

ORD106: NL1 Subtable, UNNEST NL_ALL field, FKEY

Program Example

create subtable ORD106 (ID1,PRODNO) as


select ID1,PRODNO
from T_ORDERS
unnest NL_ALL PRODNO
foreign key ID1 references ORD001;

ORD107: NL1 Subtable, UNNEST field, GENERATED PKEY, FKEY

Program Example

create subtable ORD107 (pkID1,p1PRODNO,PRODNO) as


select ID1,NL1_KEY(PRODNO),PRODNO
from T_ORDERS
unnest PRODNO
primary key pkID1,p1PRODNO
foreign key pkID1 references ORD001;

ORD108: NL1 Subtable, UNNEST field, FKEY

Program Example

create subtable ORD108 (ID1,p1PRODNO,PRODNO) as


select ID1,NL1_KEY(PRODNO),PRODNO
from T_ORDERS
unnest PRODNO
foreign key ID1 references ORD001;

UniData SQL Commands Reference 207


Appendix C - Creating Subtables

ORD109: NL1 Subtable, UNNEST NL1 field, GENERATED PKEY,


FKEY

Program Example

create subtable ORD109 (pkID1,p1PRODNO,PRODNO) as


select ID1,NL1_KEY(PRODNO),PRODNO
from T_ORDERS
unnest NL1 PRODNO
primary key pkID1,p1PRODNO
foreign key pkID1 references ORD001;

ORD110: NL1 Subtable, UNNEST NL1 field, FKEY

Program Example

create subtable ORD110 (ID1,p1PRODNO,PRODNO) as


select ID1,NL1_KEY(PRODNO),PRODNO
from T_ORDERS
unnest NL1 PRODNO
foreign key ID1 references ORD001;

ORD111: NL1 Subtable, UNNEST NL_ALL field, GENERATED


PKEY, FKEY

Program Example

create subtable ORD111 (pkID1,p1PRODNO,PRODNO) as


select ID1,NL1_KEY(PRODNO),PRODNO
from T_ORDERS
unnest NL_ALL PRODNO
primary key pkID1,p1PRODNO
foreign key pkID1 references ORD001;

208 UniData SQL Commands Reference


CREATE SUBTABLE Examples

--# select * from ORD111 order by 1,2;

ORD112: NL1 Subtable, UNNEST NL_ALL field, FKEY

Program Example

create subtable ORD112 (ID1,p1PRODNO,PRODNO) as


select ID1,NL1_KEY(PRODNO),PRODNO
from T_ORDERS
unnest NL_ALL PRODNO
foreign key ID1 references ORD001;

ORD113: NL1 Subtable, UNNEST NL1 assoc, UNIQUE PKEY,


FKEY

Program Example

create subtable ORD113 (pkID1,pkPRODNO) as


select ID1,PRODNO
from T_ORDERS
unnest NL1 LINE_ITEMS
primary key pkID1,pkPRODNO
foreign key pkID1 references ORD001;

ORD114: NL1 Subtable, UNNEST NL1 assoc, FKEY

Program Example

create subtable ORD114 (ID1,PRODNO) as


select ID1,PRODNO
from T_ORDERS
unnest NL1 LINE_ITEMS
foreign key ID1 references ORD001;

UniData SQL Commands Reference 209


Appendix C - Creating Subtables

ORD115: NL1 Subtable, UNNEST NL1 assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD115 (pkID1,p1PRODNO,PRODNO) as


select ID1,NL1_KEY(PRODNO),PRODNO
from T_ORDERS
unnest NL1 LINE_ITEMS
primary key pkID1,p1PRODNO
foreign key pkID1 references ORD001;

ORD116: NL1 Subtable, UNNEST NL1 assoc, FKEY

Program Example

create subtable ORD116 (ID1,p1PRODNO,PRODNO) as


select ID1,NL1_KEY(PRODNO),PRODNO
from T_ORDERS
unnest NL1 LINE_ITEMS
foreign key ID1 references ORD001;

ORD117: NL1 Subtable, UNNEST NL1 assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD117 (pkID1,p1COLOR_PRODNO,PRODNO) as


select ID1,NL1_KEY(COLOR,PRODNO),PRODNO
from T_ORDERS
unnest NL1 LINE_ITEMS
primary key pkID1,p1COLOR_PRODNO
foreign key pkID1 references ORD001;

210 UniData SQL Commands Reference


CREATE SUBTABLE Examples

ORD118: NL1 Subtable, UNNEST NL1 assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD118 (pkID1,p1QTY_COLOR_PRODNO,PRODNO) as


select ID1,NL1_KEY(QTY,COLOR,PRODNO),PRODNO
from T_ORDERS
unnest NL1 LINE_ITEMS
primary key pkID1,p1QTY_COLOR_PRODNO
foreign key pkID1 references ORD001;

ORD119: NL1 Subtable w/Virtual, UNNEST NL1 assoc, UNIQUE


PKEY, FKEY -

Program Example

create subtable ORD119 (pkID1,pkPRODNO,vPROD_NAME,vFEATURES) as


select ID1,PRODNO,PROD_NAME,FEATURES
from T_ORDERS
unnest NL1 LINE_ITEMS
primary key pkID1,pkPRODNO
foreign key pkID1 references ORD001;

UniData SQL Commands Reference 211


Appendix C - Creating Subtables

T_ORDERS NL2 Subtables


ORD201: NL2 Subtable, UNNEST field, UNIQUE PKEY, FKEY

Program Example

create subtable ORD201 (pkID1,pkPRODNO,pkCOLOR,QTY,PRICE) as


select ID1,PRODNO,COLOR,QTY,PRICE
from T_ORDERS
unnest PRODNO,COLOR
primary key pkID1,pkPRODNO,pkCOLOR
foreign key pkID1,pkPRODNO references ORD101;

ORD202: NL2 Subtable, UNNEST field, FKEY

Program Example

create subtable ORD202 (ID1,PRODNO,COLOR,QTY,PRICE) as


select ID1,PRODNO,COLOR,QTY,PRICE
from T_ORDERS
unnest PRODNO,COLOR,QTY
foreign key ID1,PRODNO references ORD101;

ORD203: NL2 Subtable, UNNEST NL_ALL field, UNIQUE PKEY,


FKEY

Program Example

create subtable ORD203 (pkID1,pkPRODNO,pkCOLOR,QTY,PRICE) as


select ID1,PRODNO,COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL PRODNO,COLOR,QTY
primary key pkID1,pkPRODNO,pkCOLOR
foreign key pkID1,pkPRODNO references ORD101;

212 UniData SQL Commands Reference


CREATE SUBTABLE Examples

ORD204: NL2 Subtable, UNNEST NL_ALL field, FKEY

Program Example

create subtable ORD204 (ID1,PRODNO,COLOR,QTY,PRICE) as


select ID1,PRODNO,COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL PRODNO,COLOR,QTY
foreign key ID1,PRODNO references ORD101;

ORD205: NL2 Subtable, UNNEST field, GENERATED PKEY, FKEY

Program Example

create subtable ORD205 (pkID1,p1PRODNO,pkCOLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),COLOR,QTY,PRICE
from T_ORDERS
unnest PRODNO,COLOR,QTY
primary key pkID1,p1PRODNO,pkCOLOR
foreign key pkID1,p1PRODNO references ORD107;

ORD206: NL2 Subtable, UNNEST field, FKEY

Program Example

create subtable ORD206 (ID1,p1PRODNO,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),COLOR,QTY,PRICE
from T_ORDERS
unnest PRODNO,COLOR,QTY
foreign key ID1,p1PRODNO references ORD107;

UniData SQL Commands Reference 213


Appendix C - Creating Subtables

ORD207: NL2 Subtable, UNNEST NL_ALL field, GENERATED


PKEY, FKEY

Program Example

create subtable ORD207 (pkID1,p1PRODNO,pkCOLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL PRODNO,COLOR,QTY
primary key pkID1,p1PRODNO,pkCOLOR
foreign key pkID1,p1PRODNO references ORD107;

ORD208: NL2 Subtable, UNNEST NL_ALL field, FKEY

Program Example

create subtable ORD208 (ID1,p1PRODNO,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL PRODNO,COLOR,QTY
foreign key ID1,p1PRODNO references ORD107;

ORD209: NL2 Subtable, UNNEST field, GENERATED PKEY, FKEY

Program Example

create subtable ORD209 (pkID1,pkPRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,PRODNO,NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest PRODNO,COLOR,QTY
primary key pkID1,pkPRODNO,p2COLOR
foreign key pkID1,pkPRODNO references ORD101;

214 UniData SQL Commands Reference


CREATE SUBTABLE Examples

ORD210: NL2 Subtable, UNNEST field, FKEY

Program Example

create subtable ORD210 (ID1,PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,PRODNO,NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest PRODNO,COLOR,QTY
foreign key ID1,PRODNO references ORD101;

ORD211: NL2 Subtable, UNNEST NL_ALL field, GENERATED


PKEY, FKEY

Program Example

create subtable ORD211 (pkID1,pkPRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,PRODNO,NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL PRODNO,COLOR,QTY
primary key pkID1,pkPRODNO,p2COLOR
foreign key pkID1,pkPRODNO references ORD101;

ORD212: NL2 Subtable, UNNEST NL_ALL field, FKEY

Program Example

create subtable ORD212 (ID1,PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,PRODNO,NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL PRODNO,COLOR,QTY
foreign key ID1,PRODNO references ORD101;

UniData SQL Commands Reference 215


Appendix C - Creating Subtables

ORD213: NL2 Subtable, UNNEST field, GENERATED PKEY, FKEY

Program Example

create subtable ORD213 (pkID1,p1PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest PRODNO,COLOR,QTY
primary key pkID1,p1PRODNO,p2COLOR
foreign key pkID1,p1PRODNO references ORD107;

ORD214: NL2 Subtable, UNNEST field, FKEY

Program Example

create subtable ORD214 (ID1,p1PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest PRODNO,COLOR,QTY
foreign key ID1,p1PRODNO references ORD107;

ORD215: NL2 Subtable, UNNEST NL_ALL field, GENERATED


PKEY, FKEY

Program Example

create subtable ORD215 (pkID1,p1PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL PRODNO,COLOR,QTY
primary key pkID1,p1PRODNO,p2COLOR
foreign key pkID1,p1PRODNO references ORD107;

216 UniData SQL Commands Reference


CREATE SUBTABLE Examples

ORD216: NL2 Subtable, UNNEST NL_ALL field, FKEY

Program Example

create subtable ORD216 (ID1,p1PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL PRODNO,COLOR,QTY
foreign key ID1,p1PRODNO references ORD107;

ORD217: NL2 Subtable, UNNEST assoc, UNIQUE PKEY, FKEY

Program Example

create subtable ORD217 (pkID1,pkPRODNO,pkCOLOR,QTY,PRICE) as


select ID1,PRODNO,COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,pkPRODNO,pkCOLOR
foreign key pkID1,pkPRODNO references ORD101;

ORD218: NL2 Subtable, UNNEST assoc, FKEY

Program Example

create subtable ORD218 (ID1,PRODNO,COLOR,QTY,PRICE) as


select ID1,PRODNO,COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
foreign key ID1,PRODNO references ORD101;

UniData SQL Commands Reference 217


Appendix C - Creating Subtables

ORD219: NL2 Subtable, UNNEST NL_ALL assoc, UNIQUE PKEY,


FKEY

Program Example

create subtable ORD219 (pkID1,pkPRODNO,pkCOLOR,QTY,PRICE) as


select ID1,PRODNO,COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL LINE_ITEMS
primary key pkID1,pkPRODNO,pkCOLOR
foreign key pkID1,pkPRODNO references ORD101;

ORD220: NL2 Subtable, UNNEST NL_ALL assoc, FKEY

Program Example

create subtable ORD220 (ID1,PRODNO,COLOR,QTY,PRICE) as


select ID1,PRODNO,COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL LINE_ITEMS
foreign key ID1,PRODNO references ORD101;

ORD221: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD221 (pkID1,p1PRODNO,pkCOLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,p1PRODNO,pkCOLOR
foreign key pkID1,p1PRODNO references ORD107;

218 UniData SQL Commands Reference


CREATE SUBTABLE Examples

ORD222: NL2 Subtable, UNNEST assoc, FKEY

Program Example

create subtable ORD222 (ID1,p1PRODNO,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
foreign key ID1,p1PRODNO references ORD107;

ORD223: NL2 Subtable, UNNEST NL_ALL assoc, GENERATED


PKEY, FKEY

Program Example

create subtable ORD223 (pkID1,p1PRODNO,pkCOLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL LINE_ITEMS
primary key pkID1,p1PRODNO,pkCOLOR
foreign key pkID1,p1PRODNO references ORD107;

ORD224: NL2 Subtable, UNNEST NL_ALL assoc, FKEY

Program Example

create subtable ORD224 (ID1,p1PRODNO,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL LINE_ITEMS
foreign key ID1,p1PRODNO references ORD107;

UniData SQL Commands Reference 219


Appendix C - Creating Subtables

ORD225: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD225 (pkID1,pkPRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,PRODNO,NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,pkPRODNO,p2COLOR
foreign key pkID1,pkPRODNO references ORD101;

ORD226: NL2 Subtable, UNNEST assoc, FKEY

Program Example

create subtable ORD226 (ID1,PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,PRODNO,NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
foreign key ID1,PRODNO references ORD101;

ORD227: NL2 Subtable, UNNEST NL_ALL assoc, GENERATED


PKEY, FKEY

Program Example

create subtable ORD227 (pkID1,pkPRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,PRODNO,NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL LINE_ITEMS
primary key pkID1,pkPRODNO,p2COLOR
foreign key pkID1,pkPRODNO references ORD101;

220 UniData SQL Commands Reference


CREATE SUBTABLE Examples

ORD228: NL2 Subtable, UNNEST NL_ALL assoc, FKEY

Program Example

create subtable ORD228 (ID1,PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,PRODNO,NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL LINE_ITEMS
foreign key ID1,PRODNO references ORD101;

ORD229: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD229 (pkID1,p1PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,p1PRODNO,p2COLOR
foreign key pkID1,p1PRODNO references ORD107;

ORD230: NL2 Subtable, UNNEST assoc, FKEY

Program Example

create subtable ORD230 (ID1,p1PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
foreign key ID1,p1PRODNO references ORD107;

UniData SQL Commands Reference 221


Appendix C - Creating Subtables

ORD231: NL2 Subtable, UNNEST NL_ALL assoc, GENERATED


PKEY, FKEY

Program Example

create subtable ORD231 (pkID1,p1PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL LINE_ITEMS
primary key pkID1,p1PRODNO,p2COLOR
foreign key pkID1,p1PRODNO references ORD107;

ORD232: NL2 Subtable, UNNEST NL_ALL assoc, FKEY

Program Example

create subtable ORD232 (ID1,p1PRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,NL1_KEY(PRODNO),NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest NL_ALL LINE_ITEMS
foreign key ID1,p1PRODNO references ORD107;

ORD233: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD233 (pkID1,p1COLOR_PRODNO,p2COLOR,COLOR) as


select ID1,NL1_KEY(COLOR,PRODNO),NL2_KEY(COLOR),COLOR
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,p1COLOR_PRODNO,p2COLOR
foreign key pkID1,p1COLOR_PRODNO references ORD117;

222 UniData SQL Commands Reference


CREATE SUBTABLE Examples

ORD234: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD234 (pkID1,p1COLOR_PRODNO,pkCOLOR) as


select ID1,NL1_KEY(COLOR,PRODNO),COLOR
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,p1COLOR_PRODNO,pkCOLOR
foreign key pkID1,p1COLOR_PRODNO references ORD117;

ORD235: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD235 (pkID1,p1COLOR_PRODNO,p2COLOR_PRODNO,QTY,PRICE) as


select ID1,NL1_KEY(COLOR,PRODNO),NL2_KEY(COLOR,PRODNO),QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,p1COLOR_PRODNO,p2COLOR_PRODNO
foreign key pkID1,p1COLOR_PRODNO references ORD117;

UniData SQL Commands Reference 223


Appendix C - Creating Subtables

ORD236: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD236 (pkID1,p1QTY_COLOR_PRODNO,pkCOLOR,QTY,PRICE) as


select ID1,NL1_KEY(QTY,COLOR,PRODNO),COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,p1QTY_COLOR_PRODNO,pkCOLOR
foreign key pkID1,p1QTY_COLOR_PRODNO references ORD118;

ORD237: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD237 (pkID1,p1QTY_COLOR_PRODNO,p2QTY_COLOR_PRODNO,


COLOR,QTY,PRICE) as
select ID1,NL1_KEY(QTY,COLOR,PRODNO),NL2_KEY(QTY,COLOR,PRODNO),
COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,p1QTY_COLOR_PRODNO,p2QTY_COLOR_PRODNO
foreign key pkID1,p1QTY_COLOR_PRODNO references ORD118;

224 UniData SQL Commands Reference


CREATE SUBTABLE Examples

ORD238: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD238 (QTY,PRICE,COLOR,p2QTY_COLOR_PRODNO,p1QTY_COLOR_PRODNO,


pkID1) as
select QTY,PRICE,COLOR,NL2_KEY(QTY,COLOR,PRODNO),NL1_KEY(QTY,COLOR,PRODNO),
ID1
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,p1QTY_COLOR_PRODNO,p2QTY_COLOR_PRODNO
foreign key pkID1,p1QTY_COLOR_PRODNO references ORD118;

ORD239: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD239 (pkID1,pkPRODNO,p2QTY,COLOR,QTY,PRICE) as


select ID1,PRODNO,NL2_KEY(QTY),COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,pkPRODNO,p2QTY
foreign key pkID1,pkPRODNO references ORD101;

UniData SQL Commands Reference 225


Appendix C - Creating Subtables

ORD240: NL2 Subtable, UNNEST assoc, GENERATED PKEY,


FKEY

Program Example

create subtable ORD240 (pkID1,pkPRODNO,p2COLOR,COLOR,QTY,PRICE) as


select ID1,PRODNO,NL2_KEY(COLOR),COLOR,QTY,PRICE
from T_ORDERS
unnest LINE_ITEMS
primary key pkID1,pkPRODNO,p2COLOR
foreign key pkID1,pkPRODNO references ORD101;

ORD241: NL2 Subtable w/Virtual fld, UNNEST field, UNIQUE


PKEY, FKEY

Program Example

create subtable ORD241 (pkID1,pkPRODNO,pkCOLOR,QTY,PRICE,vEPRICE) as


select ID1,PRODNO,COLOR,QTY,PRICE,EPRICE
from T_ORDERS
unnest PRODNO,COLOR
primary key pkID1,pkPRODNO,pkCOLOR
foreign key pkID1,pkPRODNO references ORD101;

226 UniData SQL Commands Reference


Appendix D - Arithmetic
Functions and
Operators

Arithmetic functions and operators, along with constants and attribute names, make up UniData
SQL expressions. The following commands include expressions in their syntax:

UniData SQL Commands


BREAK COMPUTE CREATE TABLE SELECT
COLUMN CREATE SUBTABLE INSERT UPDATE

Commands that Accept Expressions

For further information on writing expressions, see Using UniData SQL.

Reminder
UniData SQL expressions are made up of attribute names, constants, arithmetic functions, and
arithmetic operators.

UniData SQL Commands Reference 227


Appendix D - Arithmetic Functions and 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

228 UniData SQL Commands Reference


Arithmetic Operators

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

UniData SQL Commands Reference 229


Appendix D - Arithmetic Functions and Operators

230 UniData SQL Commands Reference


Index

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

UniData SQL Commands Reference 231


Index

ALTER TABLE command maximum number in SELECT statement, 13


ADD keyword with, 15 multi-subvalued (M), 175
DELETE keyword with, 17 multivalued (MV), 175
described, 14 name, 77, 163
MODIFY keyword with, 16 singlevalued (S), 175
MODULO keyword with, 19 type, 175
AND keyword, 114 virtual, 170
APPEND keyword AUTO COMMIT command
COMO command with, 46 described, 21
arithmetic functions, 228 averages, computing, 50
arithmetic operators, 110, 229 AVG keyword
ASIN arithmetic function, 228 COMPUTE command with, 49
assigning
alias to attribute, 37
association name B
modifying, 16
base tables, creating, 67
associations
BETWEEN keyword, 114
limitations of, 13
BREAK command
ATAN arithmetic function, 228
See also COLUMN command, COMPUTE com-
attribute values
mand
avoiding truncated, 39
described, 23
displaying in report heading , 36
BREAK keyword
printing in report heading, 38
CLEAR command with, 35
summing in report, 50
BSKIP keyword
attribute_definition
BREAK command with, 23
SELECT command with, 69
BTITLE command
attribute_label
described, 26
copying, 38
BTITLE keyword
defined, 110
SHOW command and, 143
attribute_spec
BUILD.INDEX ECL command
COLUMN command with, 37
UniData SQL equivalent, 54
query_spec parameter in SELECT command,
building indexes, 54
110, 114
select_stmt parameter in SELECT command, 117
attributes C
data type, 164
defining, 161 canceling

232 UniData SQL Commands Reference


Index

BREAK, COLUMN, COMPUTE, 35 connection management, 10


transaction, 107 constraints in UniData SQL, 13
changing copying
attribute in table, 16 attribute formatting, 38
modulo, 19 COS arithmetic function, 228
CHAR data type, 164 COUNT keyword
character formatting options, 39 COMPUTE command with, 49
CLEAR command counting
described, 35 values in a row, 50
CLEAR keyword CREATE INDEX command
COLUMN command with, 37 described, 54
clearing CREATE SUBTABLE command
COLUMN setting, 37 described, 57
COLUMN command CREATE TABLE command
See also BREAK command, COMPUTE com- described, 67
mand CREATE VIEW command
described, 36 described, 76
turning settings off/on, 38 CREATE.INDEX ECL command
COLUMN keyword UniData SQL equivalent, 54
CLEAR command with, 35 creating
COLUMN statement dynamic table, 69
limitations in, 13 recoverable table, 70
column_format report title, 147
COLUMN command with, 39
commands summary, 9
COMMIT command D
described, 43
data
commits, forcing, 21
recovering, 17
COMO command
data control language (DCL), 10
described, 45
data definition language (DDL), 9
COMPUTE command
data manipulation language (DML), 10, 57
See also BREAK command, COLUMN com-
data types
mand
CHAR, 164
described, 49
DATE, 164
COMPUTE keyword
LONG, 167
CLEAR command with, 35
NUMBER, 165
concluding transactions, 43
DATE data type, 165

UniData SQL Commands Reference 233


Index

dates DUPL keyword


format options for, 39 BREAK command with, 23
deadlocks duplicate records, preventing , 23
forcing rollback, 107 DYNAMIC keyword
DEFAULT_ISO_LEVEL environment variable, CREATE TABLE command with, 69
133
defaults
column setting, 37 E
defining
ending
column headings, 37
transaction, 43
DELETE command
UniData SQL session, 103
described, 79
EVERY keyword
DELETE keyword
SELECT command with, 114
ALTER TABLE command with, 14
exclusive locks
COMO command with, 45
setting in UniData SQL, 102
granting privileges, 91, 105
EXIT command
deleting
described, 89
attribute from table, 17
EXP arithmetic function, 228
dictionary
expressions, 110
listing for table, 99
directing
query results, 119 F
DISP element in attribute definition, 172
display name, 172 file permissions
displaying See privileges
attribute values formatted, 39 footers
report option settings, 143 creating, 26
DISTINCT keyword, 109 foreign keys, 57
division arithmetic operator, 229 FORMAT element in attribute definition, 173
DROP INDEX command formatting
described, 83 data type in report, 39
DROP SUBTABLE command query result, 36
described, 84 FROM keyword
DROP TABLE command limitations in SELECT statement, 13
described, 85 SELECT command with, 110
DROP VIEW command functions, UniData SQL, 110
described, 87

234 UniData SQL Commands Reference


Index

G SELECT command with, 118


IS [ NOT ] NULL keyword
GRANT command SELECT command with, 114
described, 90 isolation levels
GROUP BY keyword setting, 133
SELECT command with, 114
guide to unnesting, 116
gutters, creating in reports, 132 J
joins
H creating view with, 76
justification, text, 173
HEADING keyword JUSTIFY keyword
COLUMN command with, 37 COLUMN command with, 38
SET command with, 130
SHOW command with, 144
HEADSEP keyword K
SHOW command with, 144
KEYDATA keyword
CREATE TABLE command with, 70
I KEYONLY keyword
CREATE TABLE command with, 69
ID_list, 156 keys
IN keyword primary and foreign in subtables , 58
limitations in SELECT statement, 13 unique and generated, 59
SELECT command with, 114
indexes
creating and building, 54 L
dropping, 83
initiating LIKE keyword
interactive SQL session, 146 COLUMN command with, 38
INSERT keyword SELECT command with, 114
granting privileges, 91, 105 limitations in UniData SQL, 13
INT arithmetic function, 228 line breaks
interactive SQL session, initiating, 146 entering in reports, 38
INTERSECT keyword LINESIZE keyword
SELECT command with, 114 SET command with, 131
INTO/TO keyword SHOW command with, 144
linking

UniData SQL Commands Reference 235


Index

subtables through primary/foreign keys, 58 moving


LIST keyword column text in report, 39
COMO command with, 45 MS (multi-subvalued) attribute type , 175
LISTDICT command multiplication arithmetic operator, 229
described, 99 multi-subvalued attributes
listing adding to table, 157
COMO FILES, 45 representing in subtable, 57
LN arithmetic function, 228 multivalued attributes
LOCK TABLE command adding to table, 157
described, 101 representing in subtable, 57
locking errors resulting in rollback, 107 MV (multivalued) attribute type, 175
locks
overriding, 101
LONG data type, 167 N
newline in report, 23
NEWLINE keyword
M COLUMN command with, 38
MARGIN keyword NEWPAGE keyword
SET command with, 131 SET command with, 131
SHOW command with, 144 SHOW command with, 144
MAX keyword NODUP keyword
COMPUTE command with, 49 BREAK command with, 23
message display, turning on/off, 132 NOPRINT keyword
MIN keyword COLUMN command with, 38
COMPUTE command with, 49 NOT keyword
MOD arithmetic function, 228 SELECT command with, 114
MODIFY keyword notifying
ALTER TABLE command with, 14 transaction start/commit, 132
modifying NOWAIT keyword
tables, 16 LOCK TABLE command with, 102
modulo NULL keyword
assigning, 67 COLUMN command with, 38
changing, 19 SET command with, 131
determining optimum, 72 null value
MODULO keyword assigning character for display, 38, 131
ALTER TABLE command with, 14 showing character for display, 144
CREATE TABLE command with, 67 NUMBER data type, 165

236 UniData SQL Commands Reference


Index

NUMBER keyword SHOW command with, 144


COMPUTE command with, 50 PAUSE keyword
numeric format options, 39 SET command with, 131
SHOW command with, 144
performance
O improving with indexes, 54
permissions
O_filename, 45
See privileges
OF keyword
PH attribute, 16
COMPUTE command with, 49
_PH_ directory, 45
OFF keyword
_PH_ table, 45
COLUMN command with, 38
POWER arithmetic function, 228
COMO command with, 45
preventing duplicate records, 23
OLD_VALUE keyword
primary key, 57, 58
COLUMN command with, 38
PRIMENUMBER command
ON keyword
described, 72
COLUMN command with, 38
PRINT keyword
COMO command with, 45
COLUMN command with, 38
COMPUTE command with, 49
print_clause
operators
BTITLE command with, 26
arithmetic, 110, 229
TTITLE command with, 147
relational, 114
printing
OR keyword
attribute value, 38
SELECT command with, 114
COMO file, 45
ORDER BY clause
query result, 119
limitations in SELECT statement, 13
privileges
ORDER BY keyword
granting, 90
SELECT command with, 117
PUBLIC keyword
revoking privileges, 105
P
page breaks Q
in reports, 23
query_spec
PAGE keyword
CREATE SUBTABLE command with, 57
BREAK command with, 23
CREATE VIEW command with, 76
PAGESIZE keyword
formatting results, 36
SET command with, 131
INSERT command with, 97

UniData SQL Commands Reference 237


Index

SELECT command with, 108 smallest data value, 50


QUIT command REVOKE command
See also EXIT described, 104
described, 103 ROLLBACK command
described, 107
ROUND arithmetic function, 228
R ROW keyword
BREAK command with, 23
READ ONLY keyword
COMPUTE command with, 51
SELECT command with, 133
READ WRITE keyword
SELECT command with, 133
records
S
counting, 50 S (singlevalued) attribute type, 175
RECOVERABLE keyword saving
CREATE TABLE command with, 70 terminal interaction, 45
REFERENCES keyword search_condition
CREATE TABLE command with, 57 DELETE command with, 80
relational operators SELECT command with, 114
SELECT command with, 114 UPDATE command with, 155
removing SELECT clause
COLUMN settings, 37 in CREATE SUBTABLE, 60
REPORT keyword SELECT command
BREAK command with, 23 described, 108
COMPUTE command with, 51 SELECT keyword
report titles granting privileges, 91, 105
creating, 147 SELECT statements
reports elements of, 12
formatting formatting output from, 23, 26, 36
BREAK command and, 23 limitations of, 13
BTITLE command and, 26 select_stmt, 108
COLUMN command and, 36 SET command
COMPUTE command and, 49 described, 130
summary of commands, 11 SET keyword
representing single, multi, and multi-subvalues , 57 UPDATE command with, 155
resizing tables, 19 SET TRANSACTION, 22
returning See also AUTO COMMIT
largest attribute value, 50 setting

238 UniData SQL Commands Reference


Index

break field for report, 23 query results, 118


column wrap, 132 strings
heading display on/off, 130 format options for, 39
left margin, 131 structured query language (SQL), 7
null value display character/string, 131 subqueries
page length, 131 INSERT command with, 97
shared lock, 102 SELECT command with, 114
space between columns, 132 subtables
underline character, 132 creating, 57
shared locks dropping, 84
setting, 102 granting access privilege, 90
SHOW command subtraction arithmetic operator, 229
described, 143 SUM keyword
SIGN arithmetic function, 228 COMPUTE command with, 49
SIN arithmetic function, 228 summing
singlevalued attributes attribute values, 50
representing in subtable, 57 supplementary commands, 11
SKIP keyword suppressing
BREAK command with, 23 form feed, 131
SM (value code specifier), 175 pause at page end, 131
smallest attribute value, returning, 50 syntax, format of UniData, 8
sorting
SELECT command and, 118
SPACE keyword T
SET command with, 132
table_name
SHOW command with, 144
SELECT command with, 68
SPOOL keyword
table_spec
COMO command with, 45
UPDATE command with, 156
spooling
tables
COMO files, 45
accessing from the desktop, 57
SQL
assigning modulo, 70
initiating interactive, 146
creating, 67
SQRT arithmetic function, 228
granting access privilege, 90
standard deviation, computing, 50
listing dictionary, 99
STD keyword
naming, 68
COMPUTE command with, 49
resizing, 15
storing
TAN arithmetic function, 228

UniData SQL Commands Reference 239


Index

text justification, 173 UPDATE keyword


TRANSACTION keyword granting privileges, 91, 105
CREATE TABLE command with, 70 updating
SET command with, 133 adding multivalues and multi-subvalues, 157
transaction processing users
AUTO COMMIT, 21 revoking privileges for, 105
transactions
aborting when record is locked, 102
commiting, 43 V
TRUNC arithmetic function, 228
value code specifier, 175
truncated attribute values, avoiding , 39
VALUE keyword
TRUNCATED keyword
BREAK command with, 23
COLUMN command with, 39
VALUES keyword
TTITLE command
INSERT command with, 96
described, 147
VARIANCE keyword
TTITLE keyword
COMPUTE command with, 49
SHOW command with, 143
variances
computing, 50
view
U creating, 76
UNDERLINE keyword granting access privilege, 90
SET command with, 132 updatable (SUBTABLE), 57
SHOW command with, 144 virtual attributes
UniData SQL defining, 170
reports, formatting, 36
session, ending, 89
UNION keyword W
SELECT command with, 117
WHERE keyword
UNNEST clause
DELETE command with, 80
limitations of, 13
SELECT command with, 114
UNNEST keyword
UPDATE command with, 157
SELECT command with, 113
WORD_WRAPPED keyword
unnesting
COLUMN command with, 39
2NF database, 116
WORK keyword
attributes in CREATE SUBTABLE, 62
COMMIT command with, 43
UPDATE command
WRAP keyword
described, 155

240 UniData SQL Commands Reference


Index

SET command with, 132


SHOW command with, 144
WRAPPED keyword
COLUMN command with, 39
wrapping column text, 39

UniData SQL Commands Reference 241


Index

242 UniData SQL Commands Reference

You might also like