Sei sulla pagina 1di 338
Rocket UniVerse SQL Reference Version 11.2.5 July 2015 UNV-1125-SQLR-1

Rocket UniVerse

SQL Reference

Version 11.2.5

July 2015

UNV-1125-SQLR-1

Rocket UniVerse SQL Reference Version 11.2.5 July 2015 UNV-1125-SQLR-1

Notices

Edition

Publication date: July 2015

Book number: UNV-1125-SQLR-1

Product version: Rocket UniVerse V11.2.5

Copyright

© Rocket Software, Inc. or its affiliates 1985-2015. All Rights Reserved.

Trademarks

Rocket is a registered trademark of Rocket Software, Inc. For a list of Rocket registered trademarks go to: www.rocketsoftware.com/about/legal. All other products or services mentioned in this document may be covered by the trademarks, service marks, or product names of their respective owners.

Examples

This information might contain examples of data and reports. The examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to the names and addresses used by an actual business enterprise is entirely coincidental.

License agreement

This software and the associated documentation are proprietary and confidential to Rocket Software, Inc. or its affiliates, are furnished under license, and may be used and copied only in accordance with the terms of such license.

Note: This product may contain encryption technology. Many countries prohibit or restrict the use, import, or export of encryption technologies, and current use, import, and export regulations should be followed when exporting this product.

Corporate information

Rocket Software, Inc. develops enterprise infrastructure products in four key areas: storage, networks, and compliance; database servers and tools; business information and analytics; and application development, integration, and modernization.

Website: www.rocketsoftware.com

Rocket Global Headquarters 77 4th Avenue, Suite 100 Waltham, MA 02451-1468 USA

To contact Rocket Software by telephone for any reason, including obtaining pre-sales information and technical support, use one of the following telephone numbers.

Country

Toll-free telephone number

United States

1-855-577-4323

Australia

1-800-823-405

Belgium

0800-266-65

Canada

1-855-577-4323

China

800-720-1170

France

0800-180-0882

Germany

08-05-08-05-62

Italy

800-878-295

Japan

0800-170-5464

Netherlands

0-800-022-2961

New Zealand

0800-003210

South Africa

0-800-980-818

United Kingdom

0800-520-0439

Contacting technical support

The Rocket Customer Portal is the primary method of obtaining support. If you have current support and maintenance agreements with Rocket Software, you can access the Rocket Customer Portal and report a problem, download an update, or find answers in the U2 Knowledgebase. To log into the Rocket Customer Portal or to request a Rocket Customer Portal account, go to www.rocketsoftware.com/support.

In addition to using the Rocket Customer Portal to obtain support, you can send email to u2support@rocketsoftware.com or use one of the following telephone numbers.

Country North America United Kingdom/France Europe/Africa Australia New Zealand

Toll-free telephone number +1 800 729 3553 +44(0) 800 773 771 or +44(0) 20 8867 3691 +44 (0) 20 88673692 +1 800 707 703 or +61 (0) 29412 5450 +0800 505 515

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

Beta

 

Table of

Contents

 

Table of Contents

 

Chapter 1

 

Chapter 1: Introduction

 

UniVerse SQL syntax conventions .

.

.

.

.

.

.

.

.

.

.

.

.

1-3

Examples used in this book .

. The UniVerse demonstration database .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

1-4

1-4

The Circus database .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

1-4

Chapter 2

 

Chapter 2: The SQL catalog

 

What Is the SQL catalog? .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2-3

Structure of the SQL catalog .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2-4

UV_ASSOC

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2-5

UV_COLUMNS .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2-7

UV_SCHEMA.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2-10

UV_TABLES

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2-11

UV_USERS .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2-13

. Using the SQL catalog .

UV_VIEWS.

.

. Finding SQL catalog inconsistencies Fixing SQL catalog inconsistencies .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2-14

2-15

2-15

.

.

.

.

.

.

.

.

.

.

2-16

Chapter 3

 

Chapter 3: Data types

 

UniVerse SQL data categories

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-3

SQL data types

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-5

BIT .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-6

CHAR .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-7

DATE .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-7

. DOUBLE PRECISION

DEC

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-7

3-8

FLOAT

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-8

INT .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-9

NCHAR

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-10

C:\U2Doc\UniVerse\11.2\Source\sqlref\SqlrefTOC.doc (bookTOC.template) March 25, 2014 12:30 pm

NUMERIC

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-10

NVARCHAR.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-11

REAL

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-12

SMALLINT .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-12

TIME

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-13

VARBIT

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-13

VARCHAR

.

. Data types and data categories . Data types and conversion codes.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3-13

3-15

3-16

Chapter 4

Chapter 4: UniVerse SQL in client programs

Programming with ODBC.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

4-3

. Multivalued columns and associations.

.

.

.

.

.

.

.

.

.

4-3

Using SQL statements in programs

.

.

.

.

.

.

.

.

.

.

.

.

4-4

. SELECT statements in programmatic SQL

SQL syntax in programs .

. Using parameter markers in DML statements

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

4-5

4-6

4-8

Chapter 5

Chapter 5: Triggers

Applying business rules

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5-2

Using triggers

When does a trigger fire?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5-3

5-3

What events fire a trigger? .

.

.

Creating triggers .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5-3

5-5

Modifying triggers.

.

.

.

.

.

.

.

.

5-5

Listing information about triggers .

.

.

.

.

.

.

.

.

.

.

.

.

5-6

Trigger programs

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5-8

Transactions .

.

.

.

.

.

.

.

.

5-9

Opening files Handling errors.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5-10

5-11

Handling record and file locks

.

.

.

.

.

.

.

.

5-12

Order of operations

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5-12

Nested triggers and trigger recursion

Some examples

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5-13

5-16

Extending referential integrity.

.

.

.

.

.

.

.

.

5-16

Preventing deletions .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5-17

Validating data

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5-18

Changing a record before writing it .

.

.

.

.

.

.

.

.

.

.

5-18

Auditing changes .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

5-19

Chapter 6

Chapter 6: UniVerse SQL statements

Statement page layout

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-6

ALTER TABLE

.

.

.

.

.

.

.

.

.

.

.

.

6-7

ADD clause: Column

.

.

.

.

.

.

.

.

.

.

.

.

6-8

ADD clause: Column Synonym .

.

.

.

.

.

.

.

.

.

.

.

6-9

ADD clause: Association .

.

.

.

.

.

.

.

.

.

.

.

.

.

6-10

ADD clause: Table Constraint

.

.

.

.

.

.

.

.

.

.

.

.

6-11

DROP clause: Association.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-11

DROP clause: Integrity Constraint .

.

.

.

.

.

.

.

.

.

.

6-12

ALTER clause: SET DEFAULT

.

.

.

.

.

.

.

.

.

.

.

.

6-13

ALTER clause: DROP DEFAULT

.

.

.

.

.

.

.

.

.

.

.

6-13

TRIGGER clause .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-14

CALL

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-15

CREATE INDEX

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-17

CREATE SCHEMA

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-20

CREATE TABLE

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-24

Column definition

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-29

ASSOC clause .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-41

Table constraints .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-43

CREATE TRIGGER

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-49

CREATE VIEW .

.

.

.

.

.

.

.

.

.

.

.

.

6-52

DELETE

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-61

DROP INDEX

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-67

DROP SCHEMA

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-68

DROP TABLE

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-70

DROP TRIGGER

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-72

DROP VIEW .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-73

GRANT

. Database privileges .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-75

6-76

Table privileges

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-78

INSERT.

. Specifying columns .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-81

6-83

Specifying values

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-85

. Query specification .

VALUES clause

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-85

6-86

REVOKE

.

. Database privileges .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-88

6-89

Table privileges

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-91

SELECT

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-94

SELECT clause

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6-95

WHERE clause .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 6-114

WHEN clause

GROUP BY clause .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 6-124

. 6-129

HAVING clause

ORDER BY clause .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 6-130

. 6-131

FOR UPDATE clause .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 6-133

. Processing qualifiers .

Report qualifiers

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 6-135

. 6-142

UNION operator

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 6-145

UPDATE.

. Set expressions .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 6-148

. 6-151

WHERE clause .

.

.

.

.

.

.

.

.

.

.

.

.

. 6-153

WHEN clause

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 6-154

Referential integrity actions

.

Column .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

. 6-154

. 6-157

EVAL expressions .

.

.

.

.

.

.

.

.

.

.

.

.

. 6-159

Condition

. Comparing values .

.

.

.

.

.

.

.

.

.

.

.

.

.