VAX Rdb/VMS Guide to Using RDO, RDBPRE, and RDML
Total Page:16
File Type:pdf, Size:1020Kb
AA–N038F–TE VAX Rdb/VMS Guide to Using RDO, RDBPRE, and RDML December 1990 This manual provides information about data manipulation and programming with relational databases using the following VAX Rdb/VMS interfaces: interactive RDO, Callable RDO, and the RDBPRE and RDML preprocessors. Revision/Update Information: This manual is a revision and supersedes previous versions. Operating System: VMS Software Version: VAX Rdb/VMS Version 4.0 digital equipment corporation maynard, massachusetts The information in this document is subject to change without notice and should not be construed as a commitment by Digital Equipment Corporation. Digital Equipment Corporation assumes no responsibility for any errors that may appear in this document. Any software described in this document is furnished under a license and may be used or copied only in accordance with the terms of such license. No responsibility is assumed for the use or reliability of software or equipment that is not supplied by Digital Equipment Corporation or its affiliated companies. Restricted Rights: Use, duplication, or disclosure by the U.S. Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013. © Digital Equipment Corporation 1989,1990. All rights reserved. Printed in U.S.A. The Reader’s Comments forms at the end of this document request your critical evaluation to assist in preparing future documentation. The following are trademarks of Digital Equipment Corporation: ALL–IN–1, CDD/Plus, DEC, DEC/CMS, DECdecision, DECdtm, DECforms, DECintact, DEC/MMS, DECnet, DECtp, DECtrace, DECwindows, MicroVAX, ULTRIX, UNIBUS, VAX, VAX ACMS, VAX Ada, VAX BASIC, VAX C, VAX CDD, VAXcluster, VAX COBOL, VAX DATATRIEVE, VAX DBMS, VAXELN, VAX FMS, VAX FORTRAN, VAX Pascal, VAX RALLY, VAX Rdb/ELN, VAX Rdb/VMS, VAX RMS, VAX SPM, VAXstation, VAX TEAMDATA, VIDA, VMS, VT, and the DIGITAL Logo. MS-DOS is a registered trademark of Microsoft Corporation. OS/2 is a trademark of International Business Machine Corporation. This document is available in printed and online versions. This document was prepared using VAX DOCUMENT, Version 1.2. Contents Preface ..................................................... xxv Technical Changes and New Features ................... xxxi 1 Introduction to VAX Rdb/VMS Data Manipulation 1.1 What Is a Relational Database? ........................... 1–2 1.1.1 Single-File and Multifile Databases . .................... 1–3 1.1.2 Using Normalization to Eliminate Data Redundancy . .... 1–3 1.2 Using RDO ........................................... 1–4 1.2.1 Beginning an RDO Session ........................... 1–5 1.2.2 Getting Online Help in RDO .......................... 1–6 1.2.3 Using Record Selection Expressions . .................... 1–6 1.2.4 Using Multiline Statements in RDO .................... 1–7 1.2.5 Exiting from RDO .................................. 1–8 1.3 Using the Sample Database . ............................. 1–8 1.3.1 Creating the Sample Database ......................... 1–9 1.4 Using Rdb/VMS Statements in Programs ................... 1–11 1.5 Internationalization Support ............................. 1–14 1.5.1 Controlling Input and Display Format ................... 1–14 1.5.2 Specifying Collating Sequence ......................... 1–14 iii 2 Accessing a Database and Using Transactions 2.1 Invoking a Database ................................... 2–1 2.1.1 Accessing the Database by File Name ................... 2–2 2.1.2 Accessing the Database by Dictionary Path Name .......... 2–2 2.1.3 Accessing the Database from a Remote Node . ............ 2–3 2.1.4 Accessing Data ..................................... 2–3 2.2 Using Transactions .................................... 2–4 2.3 Specifying the Transaction Mode .......................... 2–6 2.3.1 Read-Only Transactions . ............................. 2–7 2.3.2 Read/Write Transactions ............................. 2–8 2.3.3 Batch-Update Transactions ........................... 2–9 2.3.4 Reserving Options .................................. 2–11 2.3.4.1 Auto-Locking ................................... 2–13 2.3.4.2 Shared Read Reserving Option . .................... 2–15 2.3.4.3 Shared Write Reserving Option . .................... 2–15 2.3.4.4 Protected Read Reserving Option .................... 2–15 2.3.4.5 Protected Write Reserving Option ................... 2–16 2.3.4.6 Exclusive Read Reserving Option .................... 2–16 2.3.4.7 Exclusive Write Reserving Option ................... 2–16 2.3.5 Locking and Lock Conflict Resolution ................... 2–17 2.3.6 Other START_TRANSACTION Options .................. 2–19 2.3.6.1 Evaluating Constraints at Verb Time ................. 2–19 2.3.6.2 Evaluating Constraints at Commit Time . ............ 2–20 2.3.6.3 Wait and Nowait Options .......................... 2–21 2.3.6.4 Consistency and Concurrency Options ................ 2–23 2.3.7 Indexes ........................................... 2–23 2.3.8 Transaction Scope .................................. 2–24 2.3.9 Ending a Transaction . ............................. 2–25 2.4 The Query Optimizer ................................... 2–28 2.5 Sample Interactive Session Using the START_TRANSACTION Statement ........................................... 2–30 3 Using Record Selection Expressions 3.1 Forming Streams of Records ............................. 3–1 3.2 Retrieving All the Records in a Relation .................... 3–2 3.3 Displaying Records in Sorted Order ........................ 3–4 3.3.1 Indicating Ascending or Descending Sort Order ............ 3–5 3.3.2 Using Value Expressions as Sort Keys ................... 3–6 3.4 Restricting the Number of Records: The FIRST Clause ......... 3–7 3.5 Specifying Conditions to Retrieve Records: Relational and Logical Operators ............................................ 3–7 3.5.1 Retrieving Records That Satisfy a Single Condition ......... 3–10 iv 3.5.2 Specifying Compound Conditions for Records . ............ 3–11 3.5.2.1 Retrieving Records That Satisfy Two or More Conditions: AND Operator .................................. 3–11 3.5.2.2 Retrieving Records That Satisfy One of Several Conditions: OR Operator ................................... 3–12 3.5.2.3 Retrieving Records That Do Not Satisfy a Condition: NOT Operator . ..................................... 3–13 3.5.2.4 Using the ANY and NOT ANY Operators . ............ 3–14 3.5.3 Retrieving Records That Match a Substring or Pattern . .... 3–15 3.5.4 Using Limited Matching: STARTING WITH and CONTAINING Operators ............................. 3–17 3.6 Eliminating Duplicate Values: REDUCED TO Clause .......... 3–18 3.7 Testing for a Single Record Occurrence: UNIQUE Operator . .... 3–20 3.8 Retrieving Segmented Strings ............................ 3–21 4 Retrieving Records and Joining Relations 4.1 Joining Relations Using the CROSS Clause .................. 4–1 4.1.1 Joining Records from Two Relations .................... 4–2 4.1.1.1 One-to-One and One-to-Many Joins .................. 4–4 4.1.1.2 Many-to-Many Joins ............................. 4–5 4.1.2 Joining Records from More Than Two Relations ........... 4–6 4.1.3 Joining One Relation on Itself ......................... 4–7 4.2 Using Nested FOR Loops . ............................. 4–9 5 Defining and Using Views 5.1 Creating the View Definition ............................. 5–2 5.2 Joining Relations in a View Definition . .................... 5–4 6 Storing, Modifying, and Erasing Data 6.1 Storing Data in an Rdb/VMS Database . .................... 6–1 6.1.1 Storing Values in One Relation ........................ 6–2 6.1.2 Storing Values in Multiple Relations .................... 6–2 6.2 Modifying Data . ..................................... 6–4 6.2.1 Changing Data in a Single Relation . .................... 6–4 6.2.2 Changing Data in Multiple Relations .................... 6–6 6.3 Erasing Data Records in a Relation ........................ 6–7 6.4 Updating by Selecting Data from the Record Stream ........... 6–8 6.5 Using Missing Values ................................... 6–12 v 6.5.1 Retrieving Records with a Missing Field Value ............ 6–12 6.5.1.1 Using Nested FOR Loops, Outer Joins, and the MISSING Clause . ..................................... 6–14 6.5.2 Storing Missing Values . ............................. 6–15 6.5.3 Missing Value Contrasted with SQL Default Value ......... 6–15 6.6 Referential Integrity and Triggers ......................... 6–16 6.6.1 Using Constraints to Enforce Referential Integrity ......... 6–16 6.6.2 Using Triggers ..................................... 6–17 6.7 Summary ............................................ 6–19 7 Introduction to Rdb/VMS Programming 7.1 The Programming Interfaces ............................. 7–1 7.2 Designing a Prototype Using RDO ......................... 7–3 7.3 Developing Your Queries with an Interactive Interface ......... 7–3 7.3.1 Using the RDO SHOW Statements . .................... 7–4 7.3.2 Determining Which Relations and Views to Use ........... 7–5 7.3.3 Determining Data Types of Database Fields . ............ 7–6 7.3.3.1 Determining Data Validation Checks Defined for the Database . ..................................... 7–7 7.3.3.2 Using the RDO SET OUTPUT Statement . ............ 7–8 7.3.3.3 Statement Testing in RDO ......................... 7–9 8 Data Type Compatibility 8.1 Rdb/VMS Data Types ................................... 8–2 8.2 The Segmented String Data Type ........................