SQLBase SQL Language Reference

SQLBase

SQL Language Reference

20-2107-1005

Trademarks

Centura, Centura Ranger, the Centura logo, Centura Web Developer, Gupta, the Gupta logo, Gupta Powered, the Gupta Powered logo, Fast Facts, Object Nationalizer, Quest, Quest/Web, QuickObjects, SQL/API, SQLBase, SQLConsole, SQLGateway, SQLHost, SQLNetwork, SQLRouter, SQLTalk, and Team Object Manager are trademarks of Centura Software Corporation and may be registered in the United States of America and/or other countries. SQLWindows is a registered trademark and TeamWindows, ReportWindows and EditWindows are trademarks exclusively used and licensed by Centura Software Corporation.

Microsoft, Win32, Windows, Windows NT and Visual Basic are either registered trademarks or trademarks of Microsoft Corporation in the United States of America and/or other countries.

Java is a trademark of Sun Microsystems Inc.

All other product or service names mentioned herein are trademarks or registered trademarks of their respective owners.

Copyright

Copyright ? 1997 by Centura Software Corporation. All rights reserved. SQL Language Reference 20-2107-1005 November 1997

SQL Language Reference

Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix

Who should read this manual . . . . . . . . . . . . . . . . . xx Summary of chapters . . . . . . . . . . . . . . . . . . . . . . . xx Syntax diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi Notation conventions . . . . . . . . . . . . . . . . . . . . . xxiii Other helpful resources . . . . . . . . . . . . . . . . . . . xxiv Send comments to.... . . . . . . . . . . . . . . . . . . . . . xxiv

1 Introduction to SQL. . . . . . . . . . . . . . . . . . . . . 1-1

What is SQL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 SQL history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Why is SQL used? . . . . . . . . . . . . . . . . . . . . . . . . 1-3 How you use SQL. . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Who uses SQL? . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Types of SQL commands . . . . . . . . . . . . . . . . . . . 1-4 Example of a SQL command . . . . . . . . . . . . . . . . 1-7

What are SQL objects? . . . . . . . . . . . . . . . . . . . . . . . . 1-7 Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Synonyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9 Stored commands and procedures. . . . . . . . . . . 1-10 External functions . . . . . . . . . . . . . . . . . . . . . . . . 1-10 Triggers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-10

System catalog tables . . . . . . . . . . . . . . . . . . . . . . . . 1-11

SQL Language Reference iii

Contents

SQL command processing . . . . . . . . . . . . . . . . . . . . 1-11 Optimizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12 DML Execution Model. . . . . . . . . . . . . . . . . . . . . 1-12

2 SQL Elements . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1

Names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Examples of names . . . . . . . . . . . . . . . . . . . . . . . 2-2 Types of names . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 Summary of naming requirements . . . . . . . . . . . . 2-6

Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7 Null values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7

Character data types. . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 CHAR (or VARCHAR) . . . . . . . . . . . . . . . . . . . . . 2-8 LONG VARCHAR (or LONG) . . . . . . . . . . . . . . . . 2-9

Numeric data types . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9 NUMBER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 DECIMAL (or DEC). . . . . . . . . . . . . . . . . . . . . . . 2-10 Currency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13 INTEGER (or INT) . . . . . . . . . . . . . . . . . . . . . . . 2-13 SMALLINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13 DOUBLE PRECISION . . . . . . . . . . . . . . . . . . . . 2-14 FLOAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14 REAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14

Date/Time data types . . . . . . . . . . . . . . . . . . . . . . . . 2-15 DATETIME (or TIMESTAMP) . . . . . . . . . . . . . . . 2-15 DATE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16 TIME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16

Data type conversions. . . . . . . . . . . . . . . . . . . . . . . . 2-16 Data type conversions in assignments . . . . . . . . 2-16 Data type conversions in functions . . . . . . . . . . . 2-17

Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17 String constants . . . . . . . . . . . . . . . . . . . . . . . . . 2-17 Numeric constants . . . . . . . . . . . . . . . . . . . . . . . 2-17

iv SQL Language Reference

Date/Time constants. . . . . . . . . . . . . . . . . . . . . . 2-17 Examples of constants . . . . . . . . . . . . . . . . . . . . 2-18 System keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18 Using SYSDBTRANSID keyword . . . . . . . . . . . . 2-19 Database sequence objects . . . . . . . . . . . . . . . . . . . 2-20 Using SYSDBSequence . . . . . . . . . . . . . . . . . . . 2-20 Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22 Null values in expressions . . . . . . . . . . . . . . . . . 2-23 String concatenation operator ( || ) . . . . . . . . . . . 2-23 Precedence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 Examples of expressions . . . . . . . . . . . . . . . . . . 2-24 Search conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 Nulls and search conditions . . . . . . . . . . . . . . . . 2-26 Examples of search conditions . . . . . . . . . . . . . . 2-26 Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27 Relational predicate . . . . . . . . . . . . . . . . . . . . . . 2-27 BETWEEN predicate . . . . . . . . . . . . . . . . . . . . . 2-30 NULL predicate. . . . . . . . . . . . . . . . . . . . . . . . . . 2-30 EXISTS predicate . . . . . . . . . . . . . . . . . . . . . . . . 2-30 LIKE predicate . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31 IN predicate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31 Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32 Date/Time values . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33 Entering date/time values . . . . . . . . . . . . . . . . . . 2-33 Date/time system keywords . . . . . . . . . . . . . . . . 2-35 Resolution for time keywords . . . . . . . . . . . . . . . 2-36 Time zones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37 Date/Time expressions . . . . . . . . . . . . . . . . . . . . 2-37 Examples of date/time expressions . . . . . . . . . . 2-38 Joins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38 Types of joins . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-40 Number of joins. . . . . . . . . . . . . . . . . . . . . . . . . . 2-43

SQL Language Reference v

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download