rissqlug

Embed Size (px)

Citation preview

  • for 32-Bit ApplicationsRIS SQL Users GuideAugust 1996

    DNA111660Version 5.4

  • Warranties and Liabilities

    All warranties given by Intergraph Corporation about equipment or software are set forth in your purchase contract,and nothing stated in, or implied by, this document or its contents shall be considered or deemed a modification oramendment of such warranties.

    The information and the software discussed in this document are subject to change without notice and should not beconsidered commitments by Intergraph Corporation. Intergraph Corporation assumes no responsibility for anyerror that may appear in this document.

    The software discussed in this document is furnished under a license and may be used or copied only in accordancewith the terms of this license.

    No responsibility is assumed by Intergraph for the use or reliability of software on equipment that is not supplied byIntergraph or its affiliated companies.

    TrademarksInterAct, Intergraph, and RIS are registered trademarks of Intergraph Corporation. DIALOG, InterServe, and TD1are trademarks of Intergraph Corporation. All other brands and product names are trademarks of their respectiveowners.

    Copyright 1996 Intergraph CorporationAll Rights Reserved

    Including software, file formats, and audiovisual displays; may be used pursuant to applicable software licenseagreement; contains confidential and proprietary information of Intergraph and/or third parties which is protectedby copyright and trade secret law and may not be provided or otherwise made available without properauthorization.

    RESTRICTED RIGHTS LEGEND

    Use, duplication, or disclosure by the government is subject to restrictions as set forth in subparagraph (c) (1) (ii) ofThe Rights in Technical Data and Computer Software clause at DFARS 252.227-7013 or subparagraphs (c) (1) and(2) of Commercial Computer Software Restricted Rights at 48 CFR 52.227-19, as applicable.

    Unpublished rights reserved under the copyright laws of the United States.

    Intergraph CorporationHuntsville, Alabama 35894-0001

  • Table of Contents__________________________________________________________________________________________________________________________________________________

  • __________________________________________________________________________________________________________________________________________________Table of Contents

    1. Before You Begin .................................................................................................. 1 - 3

    1.1 Document Purpose ....................................................................................... 1 - 31.2 Audience ....................................................................................................... 1 - 31.3 Document Prerequisites .............................................................................. 1 - 31.4 Related Documentation ............................................................................... 1 - 31.5 Using On-line Help ...................................................................................... 1 - 6

    1.5.1 Parts of the Help Window ................................................................ 1 - 6

    2. Introduction to RIS ............................................................................................... 2 - 3

    2.1 Features of RIS ............................................................................................ 2 - 32.2 Application Support ..................................................................................... 2 - 42.3 Network Support .......................................................................................... 2 - 42.4 Performance ................................................................................................. 2 - 42.5 Hardware and Software Platforms ............................................................. 2 - 52.6 RIS Installation for Windows NT ................................................................ 2 - 5

    3. RIS Overview ........................................................................................................ 3 - 3

    3.1 Databases ..................................................................................................... 3 - 3

    3.1.1 Database Users ................................................................................. 3 - 3

    3.2 RIS Dictionary .............................................................................................. 3 - 43.3 Schemas ........................................................................................................ 3 - 5

    3.3.1 Standard Schema ............................................................................. 3 - 53.3.2 Secure Schema .................................................................................. 3 - 63.3.3 Schema Names ................................................................................. 3 - 73.3.4 Default Schema ................................................................................ 3 - 83.3.5 Declare Schema ................................................................................ 3 - 83.3.6 Relating Databases, Users, and Schemas ....................................... 3 - 9

    3.4 Tables ........................................................................................................... 3 - 10

    3.4.1 Creating Tables ................................................................................ 3 - 11

    3.4.1.1 Data Types ......................................................................... 3 - 113.4.1.2 not null Clause ................................................................... 3 - 133.4.1.3 extern Clause ..................................................................... 3 - 13

  • 3.4.2 Altering Tables ................................................................................. 3 - 143.4.3 Dropping Tables ............................................................................... 3 - 143.4.4 Selecting Tables ................................................................................ 3 - 153.4.5 Joining Tables ................................................................................... 3 - 153.4.6 Inserting Rows .................................................................................. 3 - 17

    3.4.6.1 Inserting a Single Row ...................................................... 3 - 173.4.6.2 Inserting Rows Using a Select Statement ........................ 3 - 18

    3.4.7 Updating Rows ................................................................................. 3 - 183.4.8 Deleting Rows ................................................................................... 3 - 19

    3.5 Views ............................................................................................................ 3 - 19

    3.5.1 Creating Views ................................................................................. 3 - 203.5.2 Dropping Views ................................................................................ 3 - 203.5.3 Manipulating View Data .................................................................. 3 - 21

    3.5.3.1 Inserting View Data .......................................................... 3 - 213.5.3.2 Updating View Data .......................................................... 3 - 223.5.3.3 Deleting View Data ............................................................ 3 - 23

    3.6 Privileges ...................................................................................................... 3 - 23

    3.6.1 Database Privileges .......................................................................... 3 - 233.6.2 Relation Privileges ........................................................................... 3 - 233.6.3 Using Privileges ................................................................................ 3 - 24

    3.6.3.1 Creating the Employee Table ............................................ 3 - 243.6.3.2 Creating the Maintenance Schema ................................... 3 - 253.6.3.3 Creating a Supervisor Schema .......................................... 3 - 253.6.3.4 Creating an Employee Schema ......................................... 3 - 26

    3.6.4 The Grant Option ............................................................................. 3 - 27

    3.7 Transactions ................................................................................................. 3 - 28

    3.7.1 Data Definition Language (DDL) Statements ................................ 3 - 293.7.2 Data Manipulation Language (DML) Statements .......................... 3 - 293.7.3 Miscellaneous Statements ............................................................... 3 - 303.7.4 Enabling and Disabling Transaction Autocommit .......................... 3 - 303.7.5 Starting and Ending Transactions .................................................. 3 - 303.7.6 Committing Transactions ................................................................ 3 - 313.7.7 Rolling Back Transactions ............................................................... 3 - 323.7.8 Locking Tables .................................................................................. 3 - 343.7.9 Using Multiple Transactions ........................................................... 3 - 35

    3.8 Set Network Verification ............................................................................. 3 - 353.9 Indexes ......................................................................................................... 3 - 363.10 Examples .................................................................................................... 3 - 37

  • 3.10.1 Using a Secure Schema ................................................................ 3 - 373.10.2 Using a Shared Dictionary ........................................................... 3 - 393.10.3 Using External Objects ................................................................ 3 - 39

    4. SQL Database Language Reference .................................................................... 4 - 3

    4.1 List of Identifiers .......................................................................................... 4 - 34.2 Supported SQL Statements ......................................................................... 4 - 6

    4.2.1 alter schema ...................................................................................... 4 - 74.2.2 alter table .......................................................................................... 4 - 104.2.3 close schema ..................................................................................... 4 - 124.2.4 commit ............................................................................................... 4 - 134.2.5 create index ....................................................................................... 4 - 154.2.6 create schema ................................................................................... 4 - 17

    4.2.6.1 create schema (INFORMIX Database Descriptor) ........... 4 - 214.2.6.2 create schema (ORACLE Database Descriptor) ............... 4 - 244.2.6.3 create schema (DB2 Database Descriptor) ....................... 4 - 264.2.6.4 create schema (SYBASE Database Descriptor) ................ 4 - 294.2.6.5 create schema (Microsoft SQL Server Database

    Descriptor) .......................................................................... 4 - 31

    4.2.7 create table ....................................................................................... 4 - 334.2.8 create view ........................................................................................ 4 - 354.2.9 declare schema .................................................................................. 4 - 374.2.10 declare table .................................................................................... 4 - 404.2.11 declare view .................................................................................... 4 - 424.2.12 default schema ................................................................................ 4 - 444.2.13 delete ............................................................................................... 4 - 454.2.14 drop index ....................................................................................... 4 - 474.2.15 drop schema .................................................................................... 4 - 484.2.16 drop table ........................................................................................ 4 - 504.2.17 drop view ......................................................................................... 4 - 514.2.18 exec .................................................................................................. 4 - 524.2.19 grant ................................................................................................ 4 - 54

    4.2.19.1 grant (to schema) ........................................................... 4 - 554.2.19.2 grant (to user) ................................................................ 4 - 57

    4.2.20 insert ............................................................................................... 4 - 594.2.21 lock tables ....................................................................................... 4 - 614.2.22 open schema .................................................................................... 4 - 634.2.23 revoke .............................................................................................. 4 - 65

    4.2.23.1 revoke (from schema) ..................................................... 4 - 664.2.23.2 revoke (from user) .......................................................... 4 - 68

    4.2.24 rollback ........................................................................................... 4 - 704.2.25 select ............................................................................................... 4 - 72

  • 4.2.26 set database .................................................................................... 4 - 744.2.27 set mode .......................................................................................... 4 - 754.2.28 set network verification .................................................................. 4 - 774.2.29 set transaction ................................................................................ 4 - 804.2.30 undeclare schema ........................................................................... 4 - 814.2.31 undeclare table ............................................................................... 4 - 824.2.32 undeclare view ................................................................................ 4 - 834.2.33 union ............................................................................................... 4 - 844.2.34 update ............................................................................................. 4 - 864.2.35 where ............................................................................................... 4 - 88

    4.3 Nested Query ............................................................................................... 4 - 924.4 SQL Functions ............................................................................................. 4 - 94

    5. Troubleshooting .................................................................................................... 5 - 3

    Appendix A: RIS and Vendor DBMS Reserved Words ............................................ A - 3

    A.1 RIS Reserved Words .......................................................................................... A - 3A.2 DB2 Reserved Words ......................................................................................... A - 5A.3 INFORMIX Reserved Words ............................................................................. A - 5A.4 ORACLE Reserved Words ................................................................................. A - 9A.5 SYBASE Reserved Words .................................................................................. A - 11A.6 Microsoft SQL Reserved Words ......................................................................... A - 12

    Appendix B: RIS Data Types ................................................................................... B - 3

    Appendix C: RIS Dictionary Views .......................................................................... C - 3

    C.1 RIS-Supported Dictionary Views ...................................................................... C - 4

    C.1.1 RIS5COLUMN_PRIVS .......................................................................... C - 4C.1.2 RIS5COLUMNS ..................................................................................... C - 5C.1.3 RIS5DBMS_COLUMNS ........................................................................ C - 7C.1.4 RIS5DBMS_INDEXES .......................................................................... C - 8C.1.5 RIS5DBMS_TABLES ............................................................................ C - 9C.1.6 RIS5DBMS_USERS ............................................................................... C - 9C.1.7 RIS5DBMS_VIEWS ............................................................................... C - 10C.1.8 RIS5DBS ................................................................................................ C - 11C.1.9 RIS5INDEX_COLUMNS ....................................................................... C - 14C.1.10 RIS5INDEXES ..................................................................................... C - 15C.1.11 RIS5SCHEMAS ................................................................................... C - 16C.1.12 RIS5SCHPRIV ..................................................................................... C - 17C.1.13 RIS5TABLE_PRIVS ............................................................................ C - 17C.1.14 RIS5TABLES ....................................................................................... C - 18C.1.15 RIS5USERS ......................................................................................... C - 19C.1.16 RIS5VIEWS .......................................................................................... C - 20

    C.2 RIS V5 Schema and Dictionary Converter ....................................................... C - 22

  • Appendix D: Vendor-Specific Information ............................................................... D - 3

    D.1 General Notes on Data Types ........................................................................... D - 3

    D.1.1 Data type Mappings .............................................................................. D - 4

    D.2 DB2 ..................................................................................................................... D - 5

    D.2.1 RIS-To-DB2 Mapping ............................................................................ D - 5D.2.2 DB2-To-RIS Mapping ............................................................................ D - 6

    D.3 INFORMIX ......................................................................................................... D - 7

    D.3.1 Schemas and Unique Identifiers .......................................................... D - 7D.3.2 Transactions .......................................................................................... D - 7D.3.3 Moving Databases ................................................................................. D - 7D.3.4 RIS-To-INFORMIX Mapping ................................................................ D - 8D.3.5 INFORMIX-To-RIS Mapping ................................................................ D - 8

    D.4 ORACLE ............................................................................................................. D - 9

    D.4.1 RIS-To-ORACLE Mapping .................................................................... D - 9D.4.2 ORACLE-To-RIS Mapping .................................................................... D - 9

    D.5 SYBASE ............................................................................................................. D - 11

    D.5.1 RIS-To-SYBASE Mapping ..................................................................... D - 11D.5.2 SYBASE-To-RIS Mapping ..................................................................... D - 12

    D.6 MSSQL ............................................................................................................... D - 13

    D.6.1 RIS-To-MSSQL Mapping ...................................................................... D - 13D.6.2 MSSQL-To-RIS Mapping ...................................................................... D - 14

    Appendix E: RIS Limits ............................................................................................ E - 3

    Appendix F: Parameters File ................................................................................... F - 3

    F.1 SHARED_MEMORY .......................................................................................... F - 5F.2 MAX_LOCAL_SERVERS .................................................................................. F - 6F.3 MAX_ROWS ....................................................................................................... F - 6F.4 MAX_BUFFER_SIZE ......................................................................................... F - 6F.5 MAX_STATIC_STMTS ...................................................................................... F - 7F.6 MAX_USER_STMTS .......................................................................................... F - 7F.7 MAX_SECONDARY_SCHEMAS ...................................................................... F - 7F.8 MAX_TRANSACTIONS ..................................................................................... F - 7F.9 MAX_TABLES_IN_MEM .................................................................................. F - 8F.10 Network Verification Parameters ................................................................... F - 8F.11 Schema Definition File Location ..................................................................... F - 10F.12 LOCK_FILE_RETRY ....................................................................................... F - 11

  • F.13 Client Process Location .................................................................................... F - 11

    Appendix G: Schema Definition File ....................................................................... G - 3

    Appendix H: Language Configuration File ............................................................. H - 3

    Appendix I: Changes to This Version of RIS ........................................................... I - 3

    I.1 RDBMS Versions ................................................................................................. I - 3I.2 UNION and UNION ALL Supported ................................................................. I - 3I.3 Objects of Different Owners Within a Schema .................................................. I - 3I.4 Object Aliases ...................................................................................................... I - 4I.5 Multi-User/Secure Schemas ............................................................................... I - 5I.6 Shared Dictionaries ............................................................................................. I - 6I.7 Dictionary Objects ............................................................................................... I - 6I.8 Dictionary Views ................................................................................................. I - 7I.9 RIS_BLOB/RIS_TEXT ........................................................................................ I - 8I.10 Interoperability ................................................................................................. I - 11I.11 Upgrade Utility ................................................................................................. I - 12I.12 Utilities .............................................................................................................. I - 12I.13 Parameters ........................................................................................................ I - 12I.14 Internationalization .......................................................................................... I - 13

    Glossary ....................................................................................................................... GL - 3

    Index ............................................................................................................................ IN - 3

  • Before You Begin 1 - 1

    Before You Begin__________________________________________________________________________________________________________________________________________________

  • 1 - 2 Before You Begin

  • Before You Begin 1 - 3

    __________________________________________________________________________________________________________________________________________________1.

    Before You Begin

    1.1 Document Purpose

    The RIS for Windows NT SQL Users Guide gives RIS users an explanation of RelationalDatabase concepts and descriptions of all Structured Query Language (SQL) statementssupported by RIS.

    If you are currently using a version of RIS earlier than Version 5.0, you shouldread the section Changes to This Version of RIS before using RIS Version 5.Important changes have been made to the software.

    1.2 Audience

    This document was written for application users, application designers, and computersoftware specialists.

    1.3 Document Prerequisites

    This document assumes a basic understanding of Windows NT, PC operations, and relationaldatabase management system (RDBMS) software.

    1.4 Related Documentation

    DNA1151 RIS Installation Guide for 32-Bit ApplicationsDNA1190 RIS Programmers Guide for 32-Bit ApplicationsDNA1117 RIS Utilities Guide for 32-Bit ApplicationsDNA1003 RIS SQL Commands Quick ReferenceDNA1009 RIS Programmers Quick Reference

    For information on SQL terms and database structure, refer to documents related to specificrelational database management systems (INFORMIX, ORACLE, DB2, SYBASE, orMicrosoft SQL Server).

    For a description of relational theory and implementation, refer to a textbook and/or user andreference manuals for the vendor database management system. The following is a list ofreferences:

  • 1 - 4 Before You Begin

    Introduction to Database SystemsC.J. DateISBN: 0-201-14474-3

    Database: Structured Techniques for Design, Performance, andManagement.Shaku AtreISBN: 0-471-85251-1

    Managing the Database EnvironmentJames MartinISBN: 0-13-550582-8

    Document Conventions

    Filenames and directory paths appear in italic typeface. However, the italic typeface isalso used for emphasis of new words or important phrases. For example:

    c:\windows

    Command names, menu names, tools, system prompts and messages, and keys mayappear in boldface type. For example:

    File menu

    OR

    Press Enter

    The word mouse refers to the 2-button or 3-button mouse.

    The word select means to select a command by pressing the left mouse button over amenu command or by pressing the Alt key and the underlined charactersimultaneously.

    The word choose means to choose a button or icon by pressing the left mouse buttonover a Toolbar button, or application icon.

    The word reset means to terminate a command initiated with the mouse. Reset bypressing the right mouse button.

    The word identify means to define an area or place graphic elements in a graphics file.For PCs, identify with the left mouse button.

    The phrase key in generally means to enter data into a field on a dialog box. Toadvance to the next field, use the Tab key.

    Do not use the Enter key to advance to the next field. This key is mostlyused as the default key to accept a dialog box instead of pressing the OKbutton.

  • Before You Begin 1 - 5

    System key-ins, keywords, and programming code segments, appear in monospacedtype. For example:

    main ( )

    OR

    commit

    In actual usage, keywords can be in either upper or lowercase.

    Words that appear in angle brackets, < >, are identifiers or names that you mustsupply, or dynamic information that can change for each error message. For example:

    ERROR: Error opening the file

    Phrases in square brackets, [ ], are optional phrases.

    Curly braces contain several options (used in conjunction with a logical OR symbol ( | ))or phrases that can be repeated (used in conjunction with [, ...]). A comma followed by aseries of three periods in square brackets ([, ...]) indicates that the last phrase containedwithin curly braces ({}), or the last item, can be repeated numerous times (separated bycommas).

    For example: { } [, ...] means that numerous column names andassociated data types can be specified (separated by commas).

    The logical or symbol ( | ) separates phrases or keywords within curly braces ({}) thatcan be used alone but not together.

    For example: { user | database } means that either the user keyword or thedatabase keyword can be specified, but not both.

    This symbol notes important information.

    This symbol cautions about operations that can cause limited damage.

    This symbol warns about operations that can cause severe damage.

  • 1 - 6 Before You Begin

    Additional Information

    For additional information on RIS, see the file called README.TXT delivered with the RISsoftware. The default location for this file is in the c:\Program Files\CommonFiles\Intergraph\ris05.nn directory. The README.TXT file provides product informationand describes changes and additions to the product since the last release.

    There is also a PROD.INI file delivered in the same directory that lists all dependencies andrelated parts for the product.

    There is also a MANIFEST.TXT file delivered in the same directory that contains a list of allthe files delivered with the product.

    1.5 Using On-line Help

    On-line Help is an on-line reference tool accessible at any time the application is in use. Theon-line Help contains a description for each command and tool and step-by-step proceduresfor common tasks. For example, if you need to perform a certain task, search and display thetopic. You can move or resize your application and Help windows so that they are next toeach other. This lets you follow the procedures without having to search for the pages in thedocumentation.

  • Before You Begin 1 - 7

    1.5.1 Parts of the Help Window

    To view the on-line Help, select Contents from the Help menu. To get more specificinformation, select one of the major topics or perform a search on a specific topic.

  • 1 - 8 Before You Begin

    Use To

    Contents Display a listing of the table of contents forthe on-line Help file.

    Search Locate information about a certain topic thatyou enter in the Search box.

    Back Take you back to the previous Help topics youhave already viewed.

    History Display a sequential list of every Help topicyou have viewed during your current Windowssession.

    Find Display a dialog box used to retrieve partial orfull text strings in the help file. Use theHints button for information on constructingyour search query.

    > View the next topic in a series of relatedtopics. The button is dimmed when you reachthe last topic in the series.

    If the graphics in the on-line Help appear distorted, check your graphics driver.If you are using an Intergraph TD1 machine, the S3 1024x768 256 color (LargeFont) distorts the graphics slightly. Changing to the (Small Font) versioncorrects the display. If you are using other drivers, check with your PC manualfor information about available graphics drivers.

  • Introduction to RIS 2 - 1

    Introduction to RIS__________________________________________________________________________________________________________________________________________________

  • 2 - 2 Introduction to RIS

  • Introduction to RIS 2 - 3

    __________________________________________________________________________________________________________________________________________________2.

    Introduction to RIS RIS is an acronym for Relational Interface System. RIS is Intergraph Corporations genericrelational database interface. It isolates applications and users from the differences inspecific vendors relational database management systems (RDBMSs). It also permitsnetwork access to popular RDBMSs using various network protocols.

    With the availability of numerous relational database management systems on Intergraphmachines, application developers are faced with the choice of which RDBMS to use with theirapplication. RIS is a good long-term solution for any group requiring relational databaseflexibility. It provides a low cost interface to popular RDBMSs, while freeing the user fromthe details of supporting and understanding the subtle and not so subtle differences in eachof these systems.

    RIS Version 5.3.1 and later support 16-bit or multi-byte languages. (Most 16-bit languages are Asian.) In the RIS documentation, the maximum size allowedfor table names, view names, index names, schema names, column widths, andcharacter data is specified as x bytes, where x is an integer. For those usingmultibyte languages, the maximum number of characters should be interpretedas the maximum size in bytes. Therefore, the normal maximum of 18characters translates into 9 16-bit characters.

    2.1 Features of RIS

    The following are features of RIS:

    RIS permits developers to develop applications that are independent of the relationaldatabase they use. This means that they do not have to maintain multiple copies of thesource code for interfacing with different databases.

    RIS supports multiple databases on the network.

    RIS supports multiple communication protocols.

    RIS reduces the number and cost of database runtime licenses required.

    RIS provides protection of any previous investment in a relational databasemanagement system.

    RIS permits design flexibility, providing for possible future interfacing to other popularrelational databases.

  • 2 - 4 Introduction to RIS

    RIS includes an interactive query utility.

    RIS includes a schema manager based on the Intergraph/User Interface DevelopmentToolkit, Shamrock.

    RIS includes a bulk data loader.

    2.2 Application Support

    If there is a requirement for an application to run on any of the available commercialRDBMSs, application developers are faced with the high cost of developing and maintainingseparate versions of code to interface with each of those database systems. This is due to thegreat differences in the user interfaces, as well as differences in dialects of the StructuredQuery Language (SQL) supported by the different relational database systems. All of thesevariables add to the complexity of supporting each database system.

    RIS is a generic relational database interface that isolates an application from the RDBMS.RIS lets application developers concentrate on the application, not on writing and supportingmultiple versions of code for every brand of RDBMS. The RIS interface is based on theAmerican National Standards Institute (ANSI) SQL Standard and is therefore compatiblewith all RDBMSs that are compatible with the standard.

    2.3 Network Support

    RIS provides networking capabilities that let applications spread their data across networknodes or isolate all their data on one central node. Isolating the data and using RIS as adatabase server can enhance an applications data management capabilities and reduce anapplications cost by reducing the number of database licenses required. The application canrun on one machine while the database actually exists on another node. This is especiallyuseful in a networked environment where the database is on a central server node accessedby numerous applications running on machines that must access the same data. Only onecopy of the RDBMS is needed for the server.

    RIS currently supports the TCP/IP and LU6.2 networks.

    2.4 Performance

    As with any additional software layer, there is some performance degradation when usingRIS. RIS stores some dictionary information in memory, resulting in some initializationoverhead. This overhead varies directly with the number of relational database tables usedin the application. SQL statement processing is slightly slower than when directly issuingthe SQL statement on the vendor database. However, by storing and precompiling the SQLstatements, RIS minimizes the amount of SQL statement degradation. Typical querydegradation is less than five percent (5%).

  • Introduction to RIS 2 - 5

    2.5 Hardware and Software Platforms

    RIS currently supports INFORMIX, ORACLE, DB2, SYBASE, and Microsoft SQL Server.

    RIS is fully supported on Intergraph machines, Intel-based PC machines. Both theapplication using RIS and the databases accessed by the application can reside on thesemachines. See the RDBMS table in the RIS Installation Guide for 32-bit Applications formore information.

    Programs linked with RIS can run on PCs running MS-DOS or Windows NT and remotelyaccess databases on machines with a RIS server.

    Contact Intergraph for information regarding the current hardware and software platformsand relational database management systems supported by RIS as they are continuing toexpand.

    2.6 RIS Installation for Windows NT

    RIS installation on Microsoft NT or Windows 95 is accomplished using standard Windowssetup procedures. Double click on the setup.exe for the desired product and respond to anyprompts. Be sure to have your serial number available.

    The following lists the RIS products, when they are required, and where they can be located.

    The RIS Shared Component is the basic RIS product needed for any application to useRIS on Windows NT. Any Intergraph-developed application automatically loads theShared Component if it is required by the application. Customers who develop RIS-based applications will have to distribute copies of the Shared Component as requiredby their applications.

    The setup utility places the Shared Component in the c:\Program Files\CommonFiles\Intergraph\ris05.nn directory and nn.nn is the product version number.

    The product RISDP only needs to be loaded if you are planning to develop applicationsthat need to use embedded RIS SQL statements. The shared component isautomatically loaded with the RISDP product.

    By default, the setup utility places RISDP in the c:\Program Files\risdp directory.

    All of the RIS Data Server products are used in conjunction with a specific DBMS.These products must be loaded on the machine where the DBMS is located. The SharedComponent is automatically loaded with the RIS Data Servers. Select only theproducts associated with the DBMS you intend to use.

    RIS Data Server products are located, by default, in the c:\Program Files\risdpdirectory.

  • 2 - 6 Introduction to RIS

    The products and their associated DBMSs are:

    32-Bit RIS Product DBMS

    RISINFDS, RISINFNS INFORMIX

    RISORADS, RISORANS ORACLE

    RISDB2DS IBM,DB2

    RISSYBDS SYBASE System10

    RISMSFDS Microsoft SQLServer

    The RIS**NET products include all the functionality of the non-NET products andadditional networking capability for communicating with databases residing on non-Intergraph platforms (in conjunction with additional software DBMS).

  • RIS Overview 3 - 1

    RIS Overview__________________________________________________________________________________________________________________________________________________

  • 3 - 2 RIS Overview

  • RIS Overview 3 - 3

    __________________________________________________________________________________________________________________________________________________3.

    RIS Overview The following sections provide an overview of RIS and database concepts.

    3.1 Databases

    RIS lets applications build and manipulate a body of information specific to the application.This body of information is called a database. A database is actually a collection of datawhich may or may not be related. The data is usually stored in one or more data files or diskpartitions in such a way that it can be recalled at any time in a variety of ways. Databasesare usually created immediately after the installation of the RDBMS.

    The software that performs the organization, storage, and manipulation of data in adatabase is called a Database Management System (DBMS). DBMSs differ in many ways,the most important of which is in the way the data is organized. One of the most popularDBMSs is the Relational Database Management System (RDBMS).

    As its name implies, RIS is an interface to RDBMSs. RIS uses ANSI Standard SQL as itsinterface language to the relational database systems.

    3.1.1 Database Users

    The RDBMS controls access to a database through a concept known as the user. A databaseuser is similar to an operating system (OS) user. An OS user is recognized by a uniqueusername and possibly a password. OS users have a home directory, file ownership, andhave file access privileges defined for them.

    Like operating system users, database users are recognized by a username and possibly apassword. Database users do not necessarily have a home directory, but they do haveownership of and access privileges to the data in the database.

  • 3 - 4 RIS Overview

    In the following figure, database A has two users defined on it: Joe and Sally.

    The concept of a user is not always the same to the different vendor RDBMSs.For example, a user in an INFORMIX database must also be a valid operatingsystem user; this is not necessary for ORACLE.

    3.2 RIS Dictionary

    A RIS dictionary is a set of tables and views created by RIS for a particular database. Itserves the same purpose as the data dictionary of the underlying database, but is consistentfrom one brand of RDBMS to another. The RIS dictionary provides information about theschema - table names, column names, data types, and so forth. (Schemas are described indetail in the next section.)

    For each database known to RIS, there is at least one RIS dictionary created when the firstschema is created on the database. The user who creates the first schema becomes thedictionary owner. Subsequent schemas can be created that share this dictionary. This iscalled a shared dictionary. The using clause in a create schema statement creates aschema with a shared dictionary.

    All schemas that share a dictionary should be on the same database.

    A dictionary that is associated with only one schema is called an exclusive dictionary. In thiscase, there is a RIS dictionary for each schema. Shared dictionaries and exclusivedictionaries can be used on the same database (as long as the underlying RDBMS letsdifferent users have tables of the same name).

    All RIS users must have a RIS schema and all RIS schemas must have access to a RISdictionary created for the database they want to manipulate. The figure following shows twodictionaries created on a database. Dictionary1 is a shared dictionary and Dictionary2 is anexclusive dictionary. Note that UserC both owns one dictionary and shares another throughdifferent schemas.

  • RIS Overview 3 - 5

    Before a dictionary can be shared, the dictionary owner must grant adequate privileges tovalid database users.

    The grant schema statement grants all the necessary database level privileges on thedictionary tables to let the grantee share the dictionary. Users with schema privilege cancreate other schemas that can share the same RIS dictionary.

    A shared dictionary minimizes table creation in environments where there are manyschemas.

    3.3 Schemas

    As defined by the ANSI SQL standard, a schema is a collection (or group) of tables, views,and privileges. However, most RDBMSs do not implement schemas at all.

    RIS defines a schema as a named collection of tables, views, and indexes on a particulardatabase associated with a RIS dictionary. There are two types of RIS schemas, a standardschema and a secure schema. Information about schemas is maintained in the RISdictionary.

    3.3.1 Standard Schema

    A standard schema is a collection of tables, views, and privileges owned or shared by a useron a database. A standard schema is associated with one database user and every connectionto this schema appears to the underlying database as a connection by the same user. WithinRIS, the tables, views, and privileges are contained in, created by, and owned by the schema.

    Since most RDBMSs do not implement schemas at all, database users create and own alltables and views. This is particularly important if the database is accessed outside RIS(using the vendor supplied query program, for example). At the level of the RDBMS userscreate and own the tables and views. The RDBMS knows nothing of the schemas

  • 3 - 6 RIS Overview

    created within, or by, RIS. However, the RDBMS is aware of the tables and views thatconstitute the RIS dictionary.

    In the following figure, the database has four users, UserA, UserB, UserC, and UserD. Allfour schemas are standard schemas since there is one user per schema. Schema1, Schema2,and Schema3, share the dictionary owned by UserA. Schema4 has an exclusive dictionary.

    3.3.2 Secure Schema

    A secure schema is a multiuser schema. A secure schema requires a username and passwordbefore RIS can connect to the schemas database. The username and password are valid forthe underlying RDBMS and are not stored by RIS. Though connected to the same schema,users appear distinct to the underlying database.

    Before a user can be added to a secure schema, (with the create schema statement)adequate privileges must be granted to the user with either the grant connect or grantresource statement. The privileges are granted by the schema owner; that is, the databaseuser specified in the create schema statement. The following defines the two types ofprivileges:

    connect Users with connect privilege can connect to a schema and manipulate data butcannot issue data definition language (DDL) statements to modify the structure of thedatabase.

    resource Users with resource privilege assume connect privilege and can issue DDLstatements on the database.

    In the following figure, Schema1 is a secure schema used by UserA, UserB, and UserC. Twostandard schemas, Schema2, and Schema3 also appear in the figure. Schema2 shares adictionary with the secure schema and Schema3 is a standard schema with an exclusivedictionary. All schemas access the same database.

  • RIS Overview 3 - 7

    3.3.3 Schema Names

    Schema names must be 1-18 characters in length in ANSI mode, (up to 31 characters inother modes, depending on the underlying DBMS) consisting of alphabetic characters,digits, and the underscore character ( _ ).

    Schema names must begin with an alphabetic character, but the remaining characterscan be any combination of the above.

    RIS is not case sensitive, although schema names appear in all lower case characters inthe dictionary tables.

    Schemas may also have an associated password, having the same length and contentrequirements as schema names.

    Furthermore, schema names must be unique to RIS. The following schema names areincorrect:

    Name Incorrect because...

    _schema1 A schema name cannot begin with the underscore ( _ ) character.

    1_schema A schema name cannot begin with a digit.

    schema-1 The dash ( - ) character is not allowed in a schema name. Onlyalphabetic characters, digits, and the underscore ( _ ) characterare allowed.

  • 3 - 8 RIS Overview

    3.3.4 Default Schema

    Requests to read from or write to a database are made using SQL statements. Except wherenoted, SQL statements are executed on the default schema. The default schema is theuser/database combination that is said to be active at any given time. Most of the SQL andEmbedded SQL statements read from or write to relations in the default schema.

    The default schema can be changed with the default schema statement. For example:

    default schema my_schema;

    The default schema statement also opens the schema. Opening a schema causes RIS toread in information about it and permits it to be accessed. You cannot access a closedschema (including its relations).

    You can work on relations created in other schemas by explicitly identifying the schema inwhich the relation was created. This is done by preceding the relation name with the schemaname and a period (.) (for example: schemaOne.tableOne). However, the default schemamust have privilege to work on the target relation and the target schema must be open. RISautomatically opens schemas when they are referenced. For more information on accessingrelations in schemas other than the default schema, see the sections Tables and Views. Formore information on privileges, see the section Privileges.

    Relations can be created only in the default schema. These relations are associated with theschema in which they were created until deleted. Other schemas must be granted specificprivileges to access these relations. A relation can also be included in schemas through thealter schema statement. Then the relations become accessible in those schemas subject toRDBMS level privileges. For more information on granting privileges, see the sectionPrivileges or the grant statement description in the section SQL Database LanguageReference.

    3.3.5 Declare Schema

    Before you connect to a secure schema, you must supply a database username and passwordand, for some RDBMSs, an OS username and password. This must be done with thedeclare schema statement. For example:

    declare schema my_secure user john.passwd1;

    This statement associates the user john with the schema my_secure so that a subsequentdefault schema statement cannot use this information to open the schema. The declareschema statement specifies schema parameters before the schema is created or opened. Thisis valid for both standard and secure schemas, although it is only required for secureschemas.

  • RIS Overview 3 - 9

    3.3.6 Relating Databases, Users, and Schemas

    Relationships between databases, user definitions, and schemas in RIS are establishedthrough the create schema statement. Databases are associated with new schemas usingthe create schema statement. Databases and users must exist to create schemas.Schemas can be deleted with the drop schema statement.

    The create schema statement associates existing databases with new schema definitions.The database can be local (on the same machine as the application using RIS) or remote (onan Intergraph system, a VAX/VMS machine, a Sun SPARC or SUNOS, an HP, an ISMP, oron an IBM mainframe).

    In this document, the terms local and remote refer to the location of the serverwith respect to the client.

    For example, to create a new schema, issue the following statements:

    create schema new_schemaon database( oracle, dbname ORCL, dir c:\orant,osuser Ed [.passwd], ostype nt, remote (tcp oracnode) )user Ed.pass [.passwd];

    This statement creates a new standard schema, new_schema, on an ORACLE databasenamed ORCL and is located on the node oracnode.

    The following statement creates a new local secure schema named local_stuff:create secure schema local_stuff

    on database ( oracle, dir c:\orant, osuser Keith.pass,ostype nt, dbname ORCL )user Bob.pass;

    This statement creates a schema, local_stuff, on an ORACLE database on the local node.

    The following statement creates a schema with access to a remote database named ORA7:

    create schema good_stuffon database

    ( oracle, dbname ORA7, dir /usr/oracle,osuser Harper.passwd, ostype unix, remote (tcp stuffnode) )

    user bonnie.pass;

    This statement creates a new schema, good_stuff, on an ORACLE database namedlots_o_stuff and is located on the node stuffnode.

    See the create schema statement description for more information on creating schemasand the various options.

    Multiple schemas can be created, opened, and accessed concurrently from anapplication, but only one schema can be accessed within a single SQLstatement.

  • 3 - 10 RIS Overview

    For Example:

    Whenever a schema is successfully created, the default schema is set to the schema created.Any tables or views created are created in that schema, and any tables or views referenced inother SQL statements reference tables or views in that schema. For example: if there aretwo schemas, schema1 and schema2 which both have a table, table1, in them and the defaultschema is set to schema1, any select, insert, update, delete, or drop statementreferencing table1 refers to schema1.table1. Schema2.table1 is not affected.

    If Table1 in both schemas refers to the same table in the underlying database,then the changes to Schema1.Table1 would affect Schema2.Table1.

    3.4 Tables

    The basic unit in which RDBMSs group information and the basic result of many SQLstatements is the table, also referred to as a relation. The table is a collection of rows andcolumns of data. Each row represents a unit of related information sometimes referred to asa record or tuple. Each row is made up of one or more columns representing a part of therecord. The columns are sometimes referred to as fields or attributes.

    For example, a table could consist of names and phone numbers. The rows would be thename and number combination associated with each person represented. Also, the tablewould consist of two columns: name and phone. The following figure shows the table phoneswith some sample data.

    At the level of the RDBMS, a user creates a table in a database. The user then owns thetable, and access to that table by other users is restricted. The following figure shows theusers, Joe and Sally, on database A each with several relations. The RDBMS considers therelations to be owned by the users who created them.

  • RIS Overview 3 - 11

    Certain SQL statements let users work with tables. These statements include create, alter,drop, select, insert, update, and delete.

    3.4.1 Creating Tables

    Tables are created with the create table statement. The table is created in the defaultschema. The user must specify the name of the table and the name of each column alongwith its data type. For example, the following statement creates the phones table previouslymentioned.

    create table phones ( name char(25), phone char(12) );

    This statement creates a table named phones in the default schema. The table is createdwith two columns: the name column and the phone column. The data type of the namecolumn is defined as a character string with a length of 25. A maximum of 25 characters canbe inserted into this column. The phone column is defined as a character string of length 12which means that a maximum of 12 characters can be inserted into this column.

    3.4.1.1 Data Types

    The data type of a column specifies the type of information that a column stores. A columncan only store data of the type for which it is defined. Therefore, a row or record can containseveral data types, but a column can contain only one data type.

  • 3 - 12 RIS Overview

    RIS recognizes the following ANSI SQL data types:

    Data Type Description

    char[acter](n) Stores one or more bytes of data. Each byte usuallyrepresents an ASCII character, but is not limited to ASCII.The number of characters that a column can store is defined,when the table is created, by a length specified in parenthesesafter the keyword char. Trailing blanks are dropped.

    int[eger] Stores an integer value in the range of -2,147,483,648 to2,147,483,647 (The minimum value for INFORMIX integer is-2,147,483,647).

    smallint Stores an integer value in the range of 32767 to -32768 (Theminimum value for INFORMIX smallint is -32767).

    double [precision] Stores a floating point value in double precision format.

    real Stores a floating point value in single precision format.

    timestamp Stores a timestamp consisting of year, month, day, hour,minute, second as in yyyy-mm-dd:hh:mm:ss. A timestampliteral must be specified with the syntax: timestamp yyyy-mm-dd:hh:mm:ss or current_timestamp to specify the currentsystem time. For example,

    insert into values(timestamp 1995-08-12:16:24:15);

    insert into values(current_timestamp);

    decimal Stores a fixed point decimal number with precision and scale.Maximum precision is 15. The scale must be less than theprecision. The default precision is 8 and the default scale is 0.

    ris_blob(n) This data type can store up to 2 gigabytes of binary data. Thesize in bytes is specified in parentheses after the keyword.The default is zero. The ris_blob data is not interpreted. Formore information on this data type refer to the section UsingBinary and Text Data in the RIS Programmers Guide.

    ris_text(n) This data type can store up to 2 gigabytes of variable lengthcharacter data. The size in bytes is specified in parenthesesafter the keyword. The default is zero. The ris_text data isinterpreted by RIS when moving between different systems.For more information on this data type refer to the sectionUsing Binary and Text Data in the RIS Programmers Guide.

  • RIS Overview 3 - 13

    The following statement creates a table to store employee information:

    create table employee_info ( name char(25), id int, wage real );

    The statement creates the table employee_info in the default schema with three columns: aname column of data type char, an id column of data type int, and a wage column of datatype real.

    3.4.1.2 not null Clause

    The absence of data in the field of a record is a NULL value. When a row or record isdisplayed by the RIS interactive program, a NULL value is displayed as NULL.

    NULL is not the same as a zero for numeric data types or blanks in a charactercolumn.

    By default, RIS lets data be inserted into one, more than one, or all of the fields of a record.If values are placed in one or more (but not all) of the fields, NULL values are inserted intothe remaining fields. Many times it is necessary to create tables in which certain fields arerequired if a record is to be valid; therefore, the default can be omitted on a per-column basis.This is accomplished by creating the table with the not null clause for specific fields.

    For example, in the sample phones table, it would be worthless to have a record thatcontained only a name or number. The following statement is used to create the phones tableand to specify that the name and phone columns cannot contain NULL values.

    create table phones ( name char(25) not null, phone char(12) not null );

    3.4.1.3 extern Clause

    RIS lets users specify external names for tables and columns with the extern clause. Theexternal names used by the underlying RDBMS may be different from the name used by RIS.For example:

    create table phone (name char(25) not null, phone char(12) not null )extern tab1 (col1, col2);

    In this statement, phone is a RIS table name, and name and phone are RIS column names.The external names are tab1 for the table and col1 and col2 for the columns.

  • 3 - 14 RIS Overview

    An external name, external to RIS, is the name in the underlying database.

    The name used by RIS is an alias. This lets RIS-based applications use namesdifferent from the underlying database, as well as longer names than arepermitted by the underlying database.

    By default, when there is no extern clause, both RIS names and external names are thesame.

    3.4.2 Altering Tables

    Currently, you can change tables only by adding columns using the alter tablestatement. The alter table statement adds one column to a table. If you want to addmore than one column, alter table must be issued once for every column.

    To add a column, alter table requires the table name, the name of the column to beadded, and the data type of the column to be added. Also, the not null clause can be usedto specify that RIS does not allow NULL values in the column.

    The following statement adds a column ext to the phones table:

    alter table phones add ext char(4);

    Since the not null clause was not specified, RIS allows NULL values in that column.

    The phones table now contains the following rows and columns:

    The not null clause in an alter table statement can only be used if the table does notcontain any data at the time the statement is issued.

    3.4.3 Dropping Tables

    You can drop tables from a database with the drop table statement. After you drop atable it no longer exists in the database, nor does it exist to RIS. For example, the followingstatement drops the employee_info table defined previously:

    drop table employee_info;

    If a table is referenced by one or more views, the views may not be dropped andthe underlying DBMS may issue an error when the views are referenced.Whether an error is issued is dependent upon the type of DBMS. For moreinformation on views, see the section Views. For more information on errorsand error handling, see the section Error Reporting.

  • RIS Overview 3 - 15

    3.4.4 Selecting Tables

    You can extract data from tables by selecting rows and columns from the table according tosome criteria. Selecting is accomplished with the select statement. Columns are selectedby a list of column names. Any column whose name appears in the list is in the resultingtable. Rows are selected by setting conditions. If the data in a row meets that condition, it isincluded in the resulting table. For example: Suppose the phones table mentionedpreviously contained the following rows and columns:

    A select statement to extract the row containing the name John is as follows:

    select * from phones where name = John;

    The asterisk (*) specifies that all columns from the phones table should be included in theresult. The selection criteria appears in the where clause. Any row in which the namecolumn contains John should be included in the result. Since only one row in the phonestable matches the criteria, the result table appears as follows:

    3.4.5 Joining Tables

    Relational database systems can relate the data in two or more tables. This is done bymerging the tables to temporarily form a virtual table and is called joining. For example,consider a database with two tables: the phones table and the addresses table. The phonestable consists of two columns: name and phone. The addresses table consists of two columnsalso: name and address. The two tables are related by the name column. It would be asimple matter to join the tables into a table with the name, phone, and address columns byusing a select statement to extract rows and columns from both tables.

    Each row from each table is tested independently for the condition. Because ofthis, the data in each table does not have to be in the same order. The properselect condition relates the rows from each table.

  • 3 - 16 RIS Overview

    For example: Suppose the phones and addresses tables contained the following data:

    To join the two tables and relate the rows containing the same name, you would specify aselect statement similar to the following:

    select * from phones, addresses where phones.name = addresses.name;

    The select condition is phones.name = addresses.name. This condition relates thenames in the phones table (and the corresponding phone numbers) to the names in theaddresses table (and the corresponding address). The resulting table contains the followingdata:

    Notice that the resulting table contains two name columns. In the previous select statement,the column list is specified as an asterisk (*). This specifies that all columns from each of thetables be included. To select only specific columns, the select statement could be changedsimilar to this:

    select phones.name, phones.phone, addresses.address where ...

  • RIS Overview 3 - 17

    This specifies that both columns from the phones table and only the address column from theaddresses table be included. The resulting table would appear as follows:

    3.4.6 Inserting Rows

    You can insert a single row or multiple rows using SQL statements.

    3.4.6.1 Inserting a Single Row

    The insert statement adds one row to a table. The values to be placed in the columns canbe specified in a values list or derived from a select statement. In either case, if thenumber of values (specified or derived) does not equal the number of columns in the relation,a column list must be specified. The following insert statement adds a new entry to theexample phones table.

    insert into phones values ( Jerry, 555-4000 );

    Notice that no column list is specified in the previous example. The list is not necessarybecause the number of columns in the phones table is equal to the number of values in thevalues list, and they are in the same order. The phones table now contains the followingrows and columns:

  • 3 - 18 RIS Overview

    If the ordering of the values is not the same as the ordering of the columns, a column listmust be specified. The column list must specify a column name for each value and must bein the same order as the values.

    insert into phones (phone, name) values (555-5000, Joe) ;

    3.4.6.2 Inserting Rows Using a Select Statement

    The following statement uses a select statement to insert values into a table.

    insert into addresses (name)select name from phones where phones.phone = 555-4000;

    The select statement returns the name Jerry since that row contains the phone number.The insert statement then adds a new row to the addresses table with the name Jerry.Notice that the select statement only returns the name column; the number of values thatare to be inserted into the addresses table is not equal to the number of columns. Therefore,the column list must be specified. In this example, only the name value is inserted. Theaddress column is set to NULL. The addresses table now contains the following rows andcolumns:

    RIS lets you insert multiple rows. In the previous example, if the where clause is left out, theselect statement would return all the names from the phones table and insert them intothe addresses table.

    insert into addresses (name)select name from phones;

    3.4.7 Updating Rows

    The update statement changes the data in one or more columns in one or more rows. Therows affected are limited by a where clause much like selecting. The following statementupdates the address column of the row whose name column contains Jerry:

    update addresses set address = Louisville, KYwhere name = Jerry;

  • RIS Overview 3 - 19

    The addresses table now contains the following rows and columns:

    3.4.8 Deleting Rows

    The delete statement removes one or more rows from a table. The following statementremoves the row from the phones table where the name column contains Jack:

    delete from phones where name = Jack;

    The phones table now contains the following rows and columns:

    3.5 Views

    A view is a window into tables and is sometimes called a virtual table. Through the view,you can select data to look at or to perform other operations. When a table appears in a view,the view is said to reference the table. A view can reference one or more tables and canreference all or selected columns from each table.

    There are two uses for views:

    1. Views can be used to logically combine tables to make them appear as one.

    2. Views can be used to limit the columns selected from one or more tables to restrictaccess to sensitive data.

  • 3 - 20 RIS Overview

    3.5.1 Creating Views

    Views are created with the create view statement. The tables and columns that are to bereferenced by the view are chosen in a regular select statement. The columns in the viewcan optionally be given names different from the columns they reference. If virtual namesare given to the columns, the original names of the columns can no longer be used whenreferencing the view. The column names in the physical tables do not change.

    The create view statement also lets you use the extern clause to specify externalnames for the views and columns.

    The view only references the selected tables. The view does not actually containthe data. If the data is changed in the physical table, then the view reflectsthat change.

    A view can be defined in terms of another view.

    The following statement creates a view from the sample phones and addresses tables:

    create view infoview asselect phones.name, phones.phone, addresses.addressfrom phones, addresses

    where phones.name = addresses.name;

    The statement creates a view called infoview that references the name and phone columns ofthe phones table and the address column of the addresses table. The view infoview wouldnow display the following rows and columns:

    3.5.2 Dropping Views

    Views can be removed using the drop view statement. Dropping a view does not affect thedata that it references; it only removes the view definition from the data dictionary.

    For example, the following statement removes the view infoview:

    drop view infoview;

  • RIS Overview 3 - 21

    The following statement creates a view called dbview.

    create view dbview (phone_num, extension) asselect (phone, ext) from phones;

    The following statement removes the view dbview:

    drop view dbview;

    3.5.3 Manipulating View Data

    Manipulating data referenced by a view is more restrictive than manipulating data in tables.The following rules apply when issuing the insert, update, and delete statements on aview:

    1. The insert, update, and delete statements can be issued only on views thatreference one table. If a view references more than one table, the data referenced bythe view cannot be changed through the view.

    2. The insert, update, and delete statements cannot be issued on views that containan order by, a group by, a having clause, or a nested query in the view definition.

    3. If the table that a view references contains a column defined with the not nullclause, and the view does not reference that column, there is no way to insert a recordthrough that view. This is due to the fact that, through the view, no value can bespecified for the column defined as not null and therefore, a valid record cannot beinserted.

    3.5.3.1 Inserting View Data

    Consider the following statements:

    create table cars ( number int, make char(15),model char(15), color char(10), year int );

    This statement creates a table named cars with the following rows and columns:

    create view models (number, model) asselect number, model from cars;

    This statement creates a view named models which references the following columns in thecars table.

  • 3 - 22 RIS Overview

    The following statement inserts a car number and model into the cars table through themodels view:

    insert into models (number,model) values ( 10145, Badcar LX );

    The cars table now contains the following data:

    Selecting from the models view reveals the following data:

    3.5.3.2 Updating View Data

    You can update data referenced by a view in the same way you update data in a table. Theonly exception is that updates to a view are subject to the same restrictions as inserts.

    The following statement changes the model of Badcar LX to Leopard ZG.

    update models set model=Leopard ZG where model=Badcar LX;

    The models view now references the following data:

  • RIS Overview 3 - 23

    3.5.3.3 Deleting View Data

    You can delete data from views subject to the same restrictions as inserting and updating.The following statement deletes a record from the cars table through the models view.

    delete from models where number = 10145;

    3.6 Privileges

    All database privileges are dependent upon the privileges granted to the underlying users. Ifthe user is not the owner of the database, then the owner of the database has to grantprivileges for the user to create a RIS schema. Privileges you have are the same as theschema privileges. There are two types of database privileges: database privileges andrelation privileges.

    3.6.1 Database Privileges

    Database management systems have three database privileges:

    1. The connect privilege lets you access, connect to, or log in to a database and issueData Manipulation Language (DML) statements. You must have at least connectprivilege in order to create a schema using a shared dictionary.

    2. The resource privilege lets a user issue Data Definition Language (DDL)statements. This privilege adds the capability to create, alter, and drop relations. As apart of creating a schema, RIS needs to create tables; therefore, you must have at leastresource privilege in order to create a schema and a dictionary.

    3. The dba privilege is the highest database privilege. DBA is an acronym fordatabase administrator. A user with database administrator privileges has access to allstatements and to the entire database. This user usually has the responsibility ofperforming administrative duties.

    You must set up database privileges in the underlying RDBMS, not throughRIS.

    For a complete list of DML and DDL statements, see the sections Data Definition Language(DDL) Statements and Data Manipulation Language (DML) Statements.

    3.6.2 Relation Privileges

    Granting access to relations lets schemas access tables and views defined in other schemas.Each relation privilege grants access to perform a specific type of statement. Likewise,revoking relation privileges results in the restriction of access to the relation from thespecified schema.

    Relation privileges can be granted to, or revoked from, one or more schemas with the grantor revoke statements and from all schemas by using the public keyword in a grant orrevoke statement. These privileges can be granted in any combination, except for all,

  • 3 - 24 RIS Overview

    which must be used alone. Likewise, these privileges can be revoked in any combinationusing the revoke statement.

    There are five relation privileges:

    1. The delete privilege lets a schema execute the delete statement on the targetrelation.

    2. The insert privilege lets a schema execute the insert statement on the targetrelation, thus adding rows to the relation.

    3. The select privilege lets a schema execute the select statement on the targetrelation.

    4. The update privilege lets a schema execute the update statement on the targetrelation, thus modifying existing rows.

    5. The all relation privilege grants or revokes all of the other relation privileges.

    3.6.3 Using Privileges

    As an example of using relation privileges, consider the development of this simple employeedatabase.

    First, a schema is created which is used by the employee database administrator. Thedatabase administrator has the responsibility of creating, altering, and dropping schemasand relations with the schema management utility. Creation of databases and users isvendor-specific and must be done outside of RIS.

    create schema p_adminon database ( oracle, dir c:\orant, dbname ORCL, ostype NT,

    osuser Karen.pass)user p_admin;

    This statement creates a schema named p_admin (personnel administrator) on a databasenamed p_info (personnel information).

    3.6.3.1 Creating the Employee Table

    This statement creates the employee table.

    create table employee_info ( name char(25) not null,id int not null,position char(20) not null,wage real not null,location char(15),ext int,other1 int,other2 int,other3 int );

  • RIS Overview 3 - 25

    3.6.3.2 Creating the Maintenance Schema

    Next, a schema is created to provide employees in the personnel department access to modifythe data in the database. The users of this schema maintain the data in the database byinserting, deleting, and updating employee records. Also, the users of this schema do notneed to create or modify any relations as this is done by the administrator.

    create schema p_maint user p_maint;

    This statement created a schema name p_maint (personnel maintenance) on the samedatabase as the p_admin. This is because the statement that created the p_admin schemaalso set the default schema. Therefore, the on database clause is not needed in this instance.

    As created, the p_maint schema can only connect to RIS. It has no privilege to access anyrelations. To give this schema access to some relations, the next step would be to grant itsome privileges.

    The users of this schema need to insert, delete, update, and, most likely, select records fromthe database. Using the following statements:

    1. Set the default schema back to p_admin since the previous statement set the defaultschema to p_maint.

    default schema p_admin;

    2. Grant the proper privileges to the p_maint schema.

    grant select, insert, update, delete on employee_infoto p_maint;

    Now p_maint schema can select, insert, update and delete from the table employee_info. Inaddition, it can create and manage relations of its own.

    3.6.3.3 Creating a Supervisor Schema

    If company supervisors or managers need access to some of the data in the employeedatabase, but they should not be given access to all of it, they could be allowed (and belimited) to view the data in the name, id, position, wage, location and ext columns.

    This can be accomplished by creating a supervisor schema, creating a view in theadministrator schema, and granting access on that view to the supervisor schema. Usingthis solution, the supervisor would not have access to the actual table in which the data isstored, but would have access to the data referenced by the view.

  • 3 - 26 RIS Overview

    Also, there could be a need for supervisors to create and maintain some relations. To allowfor this, the user (of supervisor schema) must be given resource access.

    1. Create a view onto the employee_info table.

    create view super_view( name, id, position, wage, location, ext )as select name, id, position, wage, location, ext

    from employee_info;

    2. Create the supervisor schema with resource privilege.

    create schema p_super user p_super;

    3. Set the default schema back to p_admin since the previous statement set it to the newschema.

    default schema p_admin;

    4. Grant the supervisor schema access to the view.

    grant select on super_view to p_super;

    The new view is called super_view and references the name, id, position, wage, location, andext columns of the employee_info table.

    The new schema is called p_super. This schema can only select from the view super_view,but can create and maintain relations of its own.

    3.6.3.4 Creating an Employee Schema

    Suppose there is a need for employees to access a limited amount of data in the employeedatabase. This can be accomplished by creating a view onto the employee_info table, creatingan employee schema, and granting access on the view to the employee schema.

    Using the following statements:

    1. Create a view on the employee database that lets employees see the name, id, location,and ext columns.

    create view employ_view ( name, id, location, ext )as select name, id, location, ext from employee_info;

    2. Create a schema for employee access.

    create schema p_employ user p_employ;

  • RIS Overview 3 - 27

    3. Set the default schema back to p_admin because the previous statement set it to the

    new schema.

    default schema p_admin;

    4. Grant access on the employee view to the employee schema.

    grant select on employ_view to p_employ;

    The new view is named employ_view and references the name, id, location, and ext columnsof the employee_info table.

    The new schema is named p_employ and can select from the employ_view view. In addition,it can create and manage relations of its own.

    3.6.4 The Grant Option

    When a relation privilege is granted to a schema, it can also be granted the privilege to grantprivileges itself. This is made possible by the grant option and is specified with the withgrant option clause in the grant statement. A schema which has been grantedrelational privileges with the grant option not only possesses the privileges, but can grantthem to other schemas as well.

    For example: Schema A grants insert, update, and select privileges to Schema B with thegrant option. Schema B can now grant insert, update, or select privileges to other schemas.Schema B can also grant these privileges with the grant option. However, Schema B cannotgrant delete, or all privileges since it does not possess those privileges.

    Privileges granted by a schema that has been granted that privilege (along with the grantoption) can be revoked from a schema by any schema before it in the chain. This creates acascading effect of revoking the privilege from all schemas in the chain after the schemawhich executed the revoke.

    For example, Schema B grants insert, update, and select privileges to Schema C. If SchemaA revokes the update privilege from Schema B, then it is also revoked from Schema C.

  • 3 - 28 RIS Overview

    3.7 Transactions

    Transactions let you group a set of one or more SQL statements as a single logical unit ofwork. The transaction mechanism provided by RIS lets the set of one or more SQLstatements be:

    1. An atomic unit: either all or none of the SQL statements of a transaction affect thedatabase permanently.

    2. A consistent unit: simultaneous queries and data updates from different transactions donot interfere with each other.

    The transaction-related commands in RIS include commit, rollback, lock tables, andset transaction.

    The commit statement makes all the changes in a transaction permanent in the databaseand the rollback statement makes none of its changes present in the database. The locktables statement prevents other transactions from reading or overwriting the partialchanges or the temporary results of this transaction. So, the commit statement and therollback statement guarantee the atomicity property of a transaction and the locktables statement ensures the consistency property.

    The set transaction autocommit statement controls transaction autocommit mode. Ifthe transaction autocommit mode is enabled (by default), a transaction consists of only onestatement and RIS issues a commit statement implicitly after each SQL statement.Otherwise, a transaction may have more than one SQL statements and a commit statementor a rollback statement is required to end the transaction.

    A transaction in RIS allows access to the tables within only one schema. To enhance thedistributed and parallel processing abilities, RIS lets users work simultaneously on multipletransactions on different schemas in one program or one interactive session. This ability ofthe multiple transactions is specified by the parameter MAX_TRANSACTIONS in the parmsfile. The parameter specifies the maximum number of transactions a user can work onconcurrently in one program or one interactive session.

    To completely understand transactions and multiple transactions, you must understand thatthere are three categories of statements in ANSI SQL:

  • RIS Overview 3 - 29

    1. Data Definition Language (DDL)statements

    2. Data Manipulation Language (DML) statements

    3. Miscellaneous statements

    3.7.1 Data Definition Language (DDL) Statements

    Data Definition Language statements can generally be described as statements thatmanipulate database object structures and user access (the data dictionary). In relationaldatabases, the data dictionary catalogs all database object information. For example, tablesthat make up the data dictionary contain records of tables and columns that define thattable. Furthermore, the data dictionary contains information pertaining to user access of thedatabase. When a table is created, the data dictionary contains a record with the table nameand records containing the column names, data types, and whether or not these columnsmust or can not contain information.

    The most obvious of the DDL statements are the create and drop statements. Asschemas, tables, views, and indexes are created, the information describing them is enteredinto the data dictionary. Likewise, this information is deleted from the data dictionary whenthey are dropped.

    Because DDL statements affect the data dictionary and the actual composition of thedatabase, they cannot be included in a transaction. Once a DML statement has been issued,no DDL statements can be issued until a transaction is ended with a commit, rollback, orset transaction autocommit on statement. However, if no statements are pending in atransaction, such as immediately after a commit, rollback, or set transactionautocommit statement, or if the transaction autocommit mode is enabled, DDL statementscan be issued as needed.

    This is a complete list of DDL statements:

    alter schema alter table create indexcreate schema create table create viewdrop index drop schema drop tabledrop view grant revoke

    3.7.2 Data Manipulation Language (DML) Statements

    Data Manipulation Language statements manipulate data in the tables, views, and indexesdefined in schemas. DML statements can be issued in any combination and in any orderwithin a transaction. DML statements can be made effective with the commit statement orcanceled with the rollback statement.

    This is a complete list of DML statements:

    delete insert selectunion update

  • 3 - 30 RIS Overview

    3.7.3 Miscellaneous Statements

    The following miscellaneous statements do not fit into the data dictionary or datamanipulation categories:

    close schema commit declare schemadeclare table declare view default schemalock tables open schema rollbackset database set mode set transaction autocommitundeclare schema undeclare table undeclare viewexec set network

    3.7.4 Enabling and Disabling Transaction Autocommit

    The transaction autocommit mode can be enabled or disabled with the set transactionautocommit statement. If the autocommit mode is on, a transaction consists of only oneSQL statement, and RIS automatically issues a commit statement after every statement.

    Likewise, the transaction autocommit mode can be disabled by setting the autocommit modeto off. When the autocommit mode is off, RIS does not end transactions on behalf of the user.The user must end the transaction explicitly with a commit or rollback statement.

    There are some exceptions to this rule that provide the user with some degree ofsafety.

    1. If RIS is terminated with a transaction still in progress, RIS issues a rollbackstatement to prevent the possibility of corrupting data.

    2. If an error occurs during the execution of any DML statement, RIS issues arollback statement to prevent the corruption of data.

    3.7.5 Starting and Ending Transactions

    When the transaction autocommit mode is enabled, a transaction consists of only one SQLstatement and, therefore, the transaction starts and ends at the statement.

    When the transaction autocommit mode is disabled, a transaction may have more than oneSQL statement and the transaction begins when the first SQL statement is executed afterthe set transaction command.

    A transaction ends (if the transaction autocommit mode is disabled) when:

    1. A commit or rollback is invoked.

    OR

  • RIS Overview 3 - 31

    2. The transaction autocommit mode is switched to enabled from disabled (the transaction

    is committed).

    OR

    3. Termination of a user process (the transaction is ended with the rollback statement).

    After one transaction ends, the next SQL statement a