home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / visdb2tk.zip / FTBEAS01.HLP (.txt) < prev    next >
OS/2 Help File  |  1995-09-27  |  39KB  |  1,240 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. The Visualizer DB2 Toolkit ΓòÉΓòÉΓòÉ
  3.  
  4. This toolkit has been developed by the IBM EAS Product Support to give ease of 
  5. access to some of the powerful new capabilities in Version 2 of IBM's Database 
  6. 2 for OS/2 and Database 2 for AIX products. The toolkit provides the following 
  7. capabilities: 
  8.  
  9. o   Creation of Tables 
  10.  
  11. o   Creation and Maintenance of Triggers 
  12.  
  13. o   Creation of User Defined Types 
  14.  
  15.  
  16. This toolkit should be used in conjunction with Visualizer Query for OS/2, 
  17. Version 1 Release 2 or later, or with Visualizer Query for AIX Version 1 
  18. Release 2 or later.  The toolkit can be used with any DB2 Version 2 database, 
  19. utilising the capabilities of the DB2 Client/Server Family. 
  20.  
  21.  
  22. ΓòÉΓòÉΓòÉ 2. Table Creation Capabilities ΓòÉΓòÉΓòÉ
  23.  
  24. The Visualizer SQLTable object provides capabilities for the creation and 
  25. copying of SQL tables within a database. The utility supplied in the toolkit 
  26. provides the following additional capabilities, to exploit new features of 
  27. Version 2 of the databases. 
  28.  
  29. o   Specify Check Constraints 
  30.  
  31. o   Specify User Defined Data Types 
  32.  
  33. o   Specify TableSpace options 
  34.  
  35. o   Rapidly create the same table definition in multiple databases 
  36.  
  37. o   Name all constraints 
  38.  
  39. o   Rapidly copy an existing table definition to any DB2 Version 2 database 
  40.  
  41. o   Save the Create Table SQL as plain text 
  42.  
  43.     Note:  These files are suitable for use as an input file to the DB2 Command 
  44.     Line Processor 
  45.  
  46. o   Use either an existing table or saved SQL as input for future table 
  47.     creation 
  48.  
  49. o   Create (and modify) the Data Definition Language for any existing table, 
  50.     including keys, indexes and constraints 
  51.  
  52. Examples 
  53.  
  54. Create DB2 Table - General 
  55.  
  56.  
  57. ΓòÉΓòÉΓòÉ 2.1. Table Creation Examples ΓòÉΓòÉΓòÉ
  58.  
  59. The following are ways in which you can use the utility. 
  60.  
  61. 1.  From an existing DB2 Version 2 table, automatically generate the SQL Create 
  62.     Table statement that would create an identical table, and save it as plain 
  63.     text for use as input to the DB2 command line processor, using the -f 
  64.     parameter. 
  65.  
  66. 2.  Load the table definition from an existing table, modify it and apply it 
  67.     rapidly to multiple databases, making any changes necessary to accommodate 
  68.     differences in TableSpace structures. 
  69.  
  70. 3.  Specify all table and column constraints which can be applied. 
  71.  
  72. 4.  Select a table to be used for a Referential Constraint, and pick, from 
  73.     selection lists, the compatible columns from the table being created to use 
  74.     as a Foreign Key. 
  75.  
  76. 5.  Specify meaningful names for all constraints which will appear in any error 
  77.     messages resulting from attempts to break the constraint rules. 
  78.  
  79. 6.  View, Update and Modify an SQL Create Table Statement which was generated 
  80.     by the utility. 
  81.  
  82.  
  83. ΓòÉΓòÉΓòÉ 2.2. Create DB2 Table - General ΓòÉΓòÉΓòÉ
  84.  
  85. This panel allow general details of a table to be set: The following 
  86. information must be selected. 
  87.  
  88. Database 
  89.  
  90.            Select the database in which you wish to create the new table from 
  91.            the list of locally catalogued databases. 
  92.  
  93. Table Schema 
  94.  
  95.            Enter the schema in which the table should be created.  This will 
  96.            default to the current authorization ID.  Unless the current 
  97.            authorization ID has DBADM authority, you should not specify a value 
  98.            here. 
  99.  
  100. Table Name 
  101.  
  102.            Enter the name with which the table should be created. 
  103.  
  104. Table Comment 
  105.  
  106.            Enter up to 254 characters of information which will represent a 
  107.            description of the table. 
  108.  
  109. TableSpace Details 
  110.  
  111.            You may allow the database to choose a default TableSpace.  If you 
  112.            choose to specify a TableSpace, you can select a TableSpace from the 
  113.            list box.  If the TableSpace you choose is a DMS (Database Managed 
  114.            TableSpace) you can also choose an INDEX TableSpace and a LONG 
  115.            TableSpace.  Any indexes created on the table will be located in the 
  116.            INDEX TableSpace, while VARCHAR, LONG VARCHAR and LOB data will be 
  117.            located in the LONG TableSpace.  If not specified, INDEX and LONG 
  118.            data are stored in the first TableSpace specified. 
  119.  
  120. Data Capture 
  121.  
  122.            You should only select DATA CAPTURE CHANGES if you wish to store 
  123.            details of changes to the table for use with a data propagator. 
  124.  
  125. Panel Pushbuttons 
  126.  
  127. Create DB2 Table - Column Details 
  128.  
  129. Create DB2 Table - Constraints 
  130.  
  131.  
  132. ΓòÉΓòÉΓòÉ 2.3. Create DB2 Table - Column Details ΓòÉΓòÉΓòÉ
  133.  
  134. At least one column definition must be entered before a table can be created. 
  135. If you are modelling the new table on an existing table, or you have previously 
  136. entered column details, the list box will be populated with the details of 
  137. existing columns. You can select an existing column as the basis of your new 
  138. column definition. When you have entered the complete column definition, you 
  139. can select MODIFY, which will modify the selected column definition, or ADD to 
  140. add a new column. 
  141.  
  142. Column Name 
  143.  
  144.            Enter the column name.  Column names are case sensitive, and will be 
  145.            passed to DB2 exactly as typed. 
  146.  
  147. Position 
  148.  
  149.            Choose the relative position for the column in the table.  Note that 
  150.            when a new name is entered in the column name field, the position 
  151.            will be updated automatically to one greater than the number of 
  152.            columns already defined.  When Add or Modify is selected, the 
  153.            existing columns will be rearranged if necessary to accomodate the column.
  154.  
  155. Type Schema 
  156.  
  157.            Select the appropriate schema for the data type to be used for the 
  158.            column. Built in data types are in the SYSIBM schema.  User defined 
  159.            distinct types may exist in other schemas. 
  160.  
  161. Type Name 
  162.  
  163.            All types in the selected schema will be displayed.  Select the 
  164.            required type. 
  165.  
  166. Length 
  167.  
  168.            A length can only be entered for data types where length is 
  169.            supported.  For LOBs, only enter the numeric portion of the length. 
  170.  
  171. Scale 
  172.  
  173.            For decimal columns, scale specifies the number of decimal places. 
  174.            For LOBs, specify one of 
  175.  
  176.            K Kilobytes 
  177.  
  178.            M Megabytes 
  179.  
  180.            G Gigabytes 
  181.  
  182. Treatment of Nulls 
  183.  
  184.            A column can be specified to accept null values or reject null values.
  185.  
  186. With Default 
  187.  
  188.            When this option is specified, any null data inserted into the 
  189.            column will be replaced with a default for the datatype.  (either 
  190.            spaces or zero). 
  191.  
  192. For Bit Data 
  193.  
  194.            This may only be set for character columns, and ensures that no code 
  195.            page translation is performed on the column.  This ensures that the 
  196.            bit values of the column remains unchanged. 
  197.  
  198. Compact 
  199.  
  200.            This option is only available for large objects.  Although use of 
  201.            this option saves on disk space, it reduces the possibility of 
  202.            applications being able to search the LOBs for matches. 
  203.  
  204. No Logging 
  205.  
  206.            DB2 logs updates made to tables.  However, with large objects this 
  207.            can be impracticable or impossible.  The maximum size of a DB2 log 
  208.            file is 1 Gigabyte.  No LOB of this size or larger can be logged. 
  209.            Logging of large LOBS can consume vast amounts of disk space and 
  210.            fill DB2 logs. 
  211.  
  212. Column Remarks 
  213.  
  214.            Enter up to 255 characters of remarks 
  215.  
  216. Panel Pushbuttons 
  217.  
  218. Create DB2 Table - General 
  219.  
  220. Create DB2 Table - Constraints 
  221.  
  222.  
  223. ΓòÉΓòÉΓòÉ 2.4. Create DB2 Table - Constraints ΓòÉΓòÉΓòÉ
  224.  
  225. This panel is divided into 4 sections 
  226.  
  227. 1.  Primary Key 
  228.  
  229.     The primary key section contains the following elements: 
  230.  
  231.     Constraint Name 
  232.  
  233.                You can supply a name for the primary key constraint, or allow 
  234.                it to default.  There is little value in supplying a name for a 
  235.                Primary Key constraint. 
  236.  
  237.     Available Columns 
  238.  
  239.                Select, in order of precedence, the columns to be included in 
  240.                the primary key, and press the Add> button.  Use the <Remove 
  241.                button if you select columns incorrectly. 
  242.  
  243. 2.  Index 
  244.  
  245.                There may be many indexes defined on a single table.  Select the 
  246.                columns for inclusion in the index, and use the ASC/DSC button 
  247.                to set Ascending or Descending sequence for each column. 
  248.  
  249.                You can specify whether rows within the index must be unique. 
  250.                If you specify the constraint name for the index, that name will 
  251.                appear in any error messages which result from attempts to 
  252.                violate the constraint criteria. 
  253.  
  254. 3.  Check Clause 
  255.  
  256.                By defining check constraints on a table, you can remove the 
  257.                need for application programs to do standard error checking. 
  258.                This has the effect of encapsulating the definition of a table, 
  259.                and the rules that apply to the population of the table, within 
  260.                the database definition.  This reduces the development and 
  261.                maintenance overhead for applications using the data. 
  262.  
  263.                The contents of a check constraint are similar to the WHERE 
  264.                clause of a Select statement.  It is advisable to give the check 
  265.                constraints meaningful names, as the name will appear in any 
  266.                error messages that result from attempts to violate the 
  267.                constraint criteria. 
  268.  
  269.                Check Clause examples 
  270.  
  271.                Rules for Check Constraints 
  272.  
  273. 4.  Table Reference 
  274.  
  275.                Referential Constraints allow the contents of columns in a table 
  276.                to be validated against the contents of columns in another 
  277.                table.  For example, you may want to prevent employees being 
  278.                added to an Employee table unless they have a value for WORKDEPT 
  279.                which is contained in the DEPTNO column of the DEPARTMENT table. 
  280.  
  281.                The table containing the valid values which you wish to 
  282.                reference is known as the parent table.
  283.  
  284.                To create a table reference, you first select the parent table. 
  285.                The columns in the primary key of the parent table will be listed.
  286.  
  287.                For each of these columns you must identify a matching column in 
  288.                the table being created.  To do this, select a key column from 
  289.                the list, and then select a match from the list of potential 
  290.                matches supplied.  Repeat this for each referenced key column.
  291.  
  292.                The columns in the list of selected matches together form a 
  293.                foreign key for the table being created.
  294.  
  295.                You can create multiple constraints from a single table to 
  296.                multiple parent tables.  It is advisable to name the 
  297.                constraints, as the constraint name will appear in the error 
  298.                message resulting from any attempt to violate the constraint. 
  299.  
  300.                You can also supply a comment for the constraint by entering 
  301.                this in the appropriate cell of the listbox. 
  302.  
  303.     Table Schema 
  304.  
  305.                The list of table schemas includes all schemas in the database 
  306.                which contain keyed tables.  Select from the list the schema 
  307.                containing table to which you wish to create a reference. 
  308.  
  309.     Table Name 
  310.  
  311.                The list of table includes all tables within the selected 
  312.                schema.  The authorization ID being used to create the table 
  313.                must have REFERENCES privilege on the table selected. 
  314.  
  315.     Referenced Key Columns 
  316.  
  317.                When a table has been selected, the primary key columns of the 
  318.                table will be displayed in this column.  Select each of the 
  319.                columns in turn. 
  320.  
  321.     Potential Matches 
  322.  
  323.                When a column has been selected from the Referenced Key Columns, 
  324.                this list will include all columns in the current table with a 
  325.                data type compatible with the selected Referenced Key Column. 
  326.                If your database definition is well ordered, it is likely that 
  327.                the columns will have matching names and data types. 
  328.  
  329.     Selected Matches 
  330.  
  331.                When you have selected a column from the potential matches, this 
  332.                will appear in the list of selected matches, in the equivalent 
  333.                position to the matching Referenced Key Column. 
  334.  
  335.     Referential Constraint Rules 
  336.  
  337.     Delete Rule 
  338.  
  339.                Select the appropriate rule from the list. 
  340.  
  341.     Update Rule 
  342.  
  343.                Select the appropriate rule from the list. 
  344.  
  345. Panel Pushbuttons 
  346.  
  347. Create DB2 Table - General 
  348.  
  349. Create DB2 Table - Column Details 
  350.  
  351.  
  352. ΓòÉΓòÉΓòÉ 2.4.1. Check clause examples ΓòÉΓòÉΓòÉ
  353.  
  354. 1.  Ensure that only a range of values can be entered in column DEPT of the 
  355.     table being created. 
  356.  
  357.         DEPT BETWEEN 10 AND 100
  358.  
  359. 2.  Ensure that the values of column JOB in the table being created are in the 
  360.     specified list. 
  361.  
  362.         JOB IN ('Sales','Mgr','Clerk')
  363.  
  364. 3.  The following would NOT be valid, as subqueries are not allowed 
  365.  
  366.         WORKDEPT IN (SELECT DEPNO FROM DEPARTMENT)
  367.  
  368. The valid examples shown above illustrate what should be entered in the entry 
  369. field for check clauses.  The extra syntax required for the Create Table SQL 
  370. statement will be generated by the Visualizer Create DB2 Table utility. 
  371.  
  372.  
  373. ΓòÉΓòÉΓòÉ 2.4.2. Rules for Check Constraints ΓòÉΓòÉΓòÉ
  374.  
  375. A check-condition is a search-condition except as follows: 
  376.  
  377. o   A column reference must be to a column of the table being created. 
  378.  
  379. o   It cannot contain any of the following: 
  380.  
  381.     -   subqueries 
  382.  
  383.     -   column functions 
  384.  
  385.     -   variant user-defined functions 
  386.  
  387.     -   user-defined functions using the EXTERNAL ACTION option 
  388.  
  389.     -   user-defined functions using the SCRATCHPAD option 
  390.  
  391.     -   host variables 
  392.  
  393.     -   parameter markers 
  394.  
  395.     -   special registers 
  396.  
  397.     -   an alias 
  398.  
  399.  
  400. ΓòÉΓòÉΓòÉ 2.4.3. Referential Constraint Rules ΓòÉΓòÉΓòÉ
  401.  
  402. When a referential constraint is being defined as part of table creation using 
  403. the Visualizer Create DB2 Table utility, the table being created is known as 
  404. the dependent table. A referential constraint prevents data values being placed 
  405. in the columns of the dependent table which do not match existing primary key 
  406. values in the referenced table. However, the situation can arise where changes 
  407. are made to the referenced (parent) table, which would result in values 
  408. existing in the referenced table which could not have been created in the 
  409. dependent table because of the constraint rules. This situation can exist when 
  410. one or more rows are deleted from the parent table, or when the values of 
  411. primary key column(s) for one or more rows are updated. DB2 databases provide a 
  412. choice of actions for when these circumstances arise: 
  413.  
  414. o   No Action 
  415.  
  416.     Do not allow the update or deletion of the row in the parent table. 
  417.  
  418. o   Restrict 
  419.  
  420.     Do not allow the update or deletion of the row in the parent table. 
  421.  
  422. o   Set Null 
  423.  
  424.     Available for DELETE only.  Set all nullable columns of the foreign key of 
  425.     the dependent table to NULL. 
  426.  
  427. o   Cascade 
  428.  
  429.     Available for DELETE only.  Delete the matching set of rows from the 
  430.     dependent table. 
  431.  
  432. Note:  There is a subtle difference between NO ACTION and RESTRICT which is 
  433. explained in the explanation for CREATE TABLE in the SQL Reference Manual. 
  434.  
  435.  
  436. ΓòÉΓòÉΓòÉ 2.4.4. Panel Pushbuttons ΓòÉΓòÉΓòÉ
  437.  
  438. The main panel pushbuttons are available from all sections of the main panel. 
  439. These have the following effects: 
  440.  
  441. OK 
  442.  
  443.            Apply the current 'Create Table' and associated SQL statements to 
  444.            the selected database.  If this is successful, exit the panel.  If 
  445.            not successful, report the error and keep the panel open to allow 
  446.            the user to take corrective action. 
  447.  
  448. Apply 
  449.  
  450.            Apply the current 'Create Table' and associated SQL statements to 
  451.            the selected database.  Keep the panel open and populated with the 
  452.            current details. 
  453.  
  454.            Note:  If the schema and name of a table being created are the same 
  455.            as those of an existing table, you will be prompted to overwrite the 
  456.            existing table.  You will also be given the opportunity to save the 
  457.            definition of the existing table to a text file before overwriting 
  458.            it. If the creation of the new table is unsuccessful, the previous 
  459.            trigger definition will be restored. 
  460.  
  461. Save Text 
  462.  
  463.            Save the current 'Create Table' and associated SQL statements to a 
  464.            text file.  The standard files dialog will be invoked to allow 
  465.            specification of the target file name. 
  466.  
  467. Cancel 
  468.  
  469.            End the panel. 
  470.  
  471.  
  472. ΓòÉΓòÉΓòÉ 3. Trigger Maintenance Capabilities ΓòÉΓòÉΓòÉ
  473.  
  474. The trigger function is a powerful new capability of DB2/2 Version 2 and 
  475. DB2/6000 Version 2.  The Visualizer Trigger Utility provides a mechanism for 
  476. creating and maintaining trigger definitions using a simple, end user 
  477. interface. This tool provides the following capabilities: 
  478.  
  479. o   Create a trigger based on 
  480.  
  481.     An empty template 
  482.  
  483.     An existing trigger in a database 
  484.  
  485.     An SQL Create Trigger statement 
  486.  
  487. o   Apply a trigger to a database 
  488.  
  489. o   Save a trigger in text form as 
  490.  
  491.     A Visualizer SQL Statement 
  492.  
  493.     A Plain text SQL Statement 
  494.  
  495.     Note:  Both of these can be used as input to the DB2 command line processor 
  496.  
  497. o   Rapidly apply identical or similar triggers to multiple databases 
  498.  
  499. o   Use existing Visualizer SQL Statements or Queries to assist in the trigger 
  500.     definition. 
  501.  
  502. Visualizer Create DB2 Trigger Utility 
  503.  
  504.  
  505. ΓòÉΓòÉΓòÉ 3.1. Visualizer Create DB2 Trigger Utility ΓòÉΓòÉΓòÉ
  506.  
  507. With the Visualizer Create DB2 Trigger Utility, you can create a completely new 
  508. trigger, or you can model the trigger on an existing trigger. 
  509.  
  510. If you choose to model the trigger on an existing trigger, you can choose the 
  511. model trigger either from the trigger definition in a DB2/2 or DB2/6000 
  512. database, or from SQL previously saved from this utility. 
  513.  
  514. To choose the source of your model trigger, select one of the values of the 
  515. value set: 
  516.  
  517. o   Existing Trigger 
  518.  
  519.     This option allows you to choose a trigger definition from a DB2/2 or 
  520.     DB2/6000 database. 
  521.  
  522.     Having selected this option, you should then select the trigger which you 
  523.     wish to use as a model. 
  524.  
  525.     Database 
  526.  
  527.     An entry will appear in the list for each database catalogued on the local 
  528.     node.  Although you can select any of these databases, usable trigger 
  529.     definitions will only exist in DB2 family databases equivalent to DB2/2 and 
  530.     DB2/6000 or later. Select the database from which you want to select the 
  531.     trigger. 
  532.  
  533.     Trigger Schema 
  534.  
  535.     An entry will appear in the list for each trigger schema in which trigger 
  536.     definitions exist.  Select the schema for the trigger with which you wish 
  537.     to work. 
  538.  
  539.     Trigger Name 
  540.  
  541.     An entry will appear in the list for each trigger which exists in the 
  542.     schema you selected.  Select the name of the trigger with which you wish to 
  543.     work. 
  544.  
  545. o   Saved Text File 
  546.  
  547.     This option allows you to choose a file of SQL previously saved from this 
  548.     utility.  You can use this mechanism if have stored an uncompleted trigger 
  549.     definition, and wish to work with that definition. 
  550.  
  551.     Having select this option, you should enter the path and file name of the 
  552.     file containing the SQL with which you wish to work.  Click on the 
  553.     pushbutton to use the files dialog to locate the file. 
  554.  
  555. o   Template 
  556.  
  557.     This option allows you to create a new trigger from an empty definition. 
  558.  
  559. When you have created a new trigger definition using any of the methods above, 
  560. you can choose to save the trigger using any of the mechanisms supplied on the 
  561. Create DB2 Trigger Details panel, which will be started when you press OK from 
  562. this panel. 
  563.  
  564.  
  565. ΓòÉΓòÉΓòÉ 3.1.1. Create DB2 Trigger Details ΓòÉΓòÉΓòÉ
  566.  
  567. This panel allows you to enter the details of the trigger you wish to create. 
  568. The panel can be divided into 5 major sections. For further explanation see the 
  569. explanation of the Create Trigger statement in the DB2 Version 2 SQL Reference 
  570. which is supplied on line with DB2 products. 
  571.  
  572. 1.  Identification of the Trigger Definition 
  573.  
  574.     This section consists of the following entry fields: 
  575.  
  576.     Database 
  577.  
  578.                Select the database in which you wish to create the new trigger 
  579.                from the list of locally catalogued databases. 
  580.  
  581.     Trigger Schema 
  582.  
  583.                Enter the schema in which the trigger should be created.  This 
  584.                will default to the current authorization ID.  Unless the 
  585.                current authorization ID has DBADM authority, you should not 
  586.                specify a value here. 
  587.  
  588.     Trigger Name 
  589.  
  590.                Enter the name with which the trigger definition should be 
  591.                created. 
  592.  
  593.     Trigger Comment 
  594.  
  595.                Enter up to 254 characters of information which will represent a 
  596.                description of the trigger. 
  597.  
  598. 2.  Defining How to Apply the Trigger 
  599.  
  600.     This section consists of the following fields. 
  601.  
  602.     A single SQL statement being executed against the database may affect more 
  603.     than one row in a table. Select: 
  604.  
  605.     To each row 
  606.  
  607.                if you wish the trigger conditions to be tested and actions to 
  608.                be executed once for each row. 
  609.  
  610.     To each statement 
  611.  
  612.                if you wish the trigger conditions to be tested and actions to 
  613.                be executed only once for the statement. 
  614.  
  615. The trigger may be applied either before or after the database changes. Select: 
  616.  
  617.     Before database changes 
  618.  
  619.                if you wish the trigger conditions to be tested and actions to 
  620.                be executed before database changes have been made. If you 
  621.                choose this option, any updates generated by the trigger actions 
  622.                WILL NOT activate triggers which would normally be updated by 
  623.                those updates.
  624.  
  625.     After database changes 
  626.  
  627.                if you wish the trigger conditions to be tested and actions to 
  628.                be executed after database changes have been made. If you choose 
  629.                this option, any updates generated by the trigger actions WILL 
  630.                activate triggers which would normally be updated by those updates.
  631.  
  632. 3.  Defining the conditions that activate the trigger 
  633.  
  634.     This section consists of the following entry fields. 
  635.  
  636.     Table Schema 
  637.  
  638.                The list provided contains all schemas in the database with 
  639.                tables.  This list may include schemas which contain tables on 
  640.                which the current authorization ID does not have the authority 
  641.                required for trigger creation. 
  642.  
  643.     Table Name 
  644.  
  645.                The list provided contains all table that exist in the selected 
  646.                schema. This list may include tables on which the current 
  647.                authorization ID does not have the authority required for 
  648.                trigger creation. 
  649.  
  650.     Action 
  651.  
  652.                Select one of the following actions: 
  653.  
  654.     Insert     The trigger conditions will be tested and actions executed 
  655.                whenever a row is inserted into the specified table. 
  656.  
  657.     Delete     The trigger conditions will be tested and actions executed 
  658.                whenever a row is deleted from the specified table. 
  659.  
  660.     Update     The trigger conditions will be tested and actions executed when 
  661.                a row is updated in the specified table.  For this option you 
  662.                may select specified columns to activate the trigger. 
  663.  
  664.     Column Names 
  665.  
  666.                You may select one or more column names from the list.  If you 
  667.                select column names, the trigger conditions will be tested and 
  668.                actions executed only when the specified columns are updated. 
  669.                If no columns are selected, the trigger will be activated by 
  670.                updates to any column in the table. 
  671.  
  672.     Additional Conditions 
  673.  
  674.                The additional conditions that may be entered here are similar 
  675.                to those that can be used in the where clause of an SQL Select 
  676.                statement.  Click on the  button to open the Create DB2 Trigger 
  677.                Conditions panel. 
  678.  
  679.                The actions to be taken when the trigger is activated 
  680.  
  681.                This sections consists of the following entry fields: 
  682.  
  683.     SQL statements to be executed 
  684.  
  685.                The SQL statements that may be entered here are similar to those 
  686.                compatible with Execute Immediate processing. Click on the 
  687.                button to open the Create DB2 Trigger Actions panel. 
  688.  
  689. 4.  Action Pushbuttons 
  690.  
  691.     Select one of the following pushbuttons: 
  692.  
  693.     OK 
  694.  
  695.                To apply the changed trigger to the database and close the 
  696.                panel. 
  697.  
  698.     Apply 
  699.  
  700.                To apply the changed trigger to the database and leave the panel 
  701.                open.  This option makes it easy to modify the trigger 
  702.                definition to create a different trigger, or to apply the same 
  703.                trigger to a number of databases. 
  704.  
  705.                Note:  If the schema and name of a trigger being created are the 
  706.                same as those of an existing trigger, you will be prompted to 
  707.                overwrite the existing trigger.  You will also be given the 
  708.                opportunity to save the definition of the existing trigger to a 
  709.                text file before overwriting it. If the creation of the new 
  710.                trigger is unsuccessful, the previous trigger definition will be 
  711.                restored. 
  712.  
  713.     Save Text 
  714.  
  715.                It is recommended that all trigger definitions applied to your 
  716.                databases are stored in a saved text file.  If you select this 
  717.                option you can save the text as a Visualizer SQL Statement 
  718.                object, or as a plain text file.  The saved text can be executed 
  719.                directly from the DB2 command line processor, using -tdx option. 
  720.  
  721.     Cancel 
  722.  
  723.                Will prompt for confirmation if changes have been made.  This 
  724.                button causes the panel to close, and all unapplied and unsaved 
  725.                changes to be abandoned. 
  726.  
  727.     Help 
  728.  
  729.                Invokes this panel. 
  730.  
  731. Create DB2 Trigger Conditions 
  732.  
  733. Create DB2 Trigger Actions 
  734.  
  735.  
  736. ΓòÉΓòÉΓòÉ 3.1.1.1. Authority Required for Trigger Creation ΓòÉΓòÉΓòÉ
  737.  
  738. The privileges held by the current authorization ID must include at least one 
  739. of the following: 
  740.  
  741. o   SYSADM or DBADM authority. 
  742.  
  743. o   All of the following: 
  744.  
  745.     -   ALTER privilege on the table on which the trigger is defined 
  746.  
  747.     -   SELECT privilege on the table on which the trigger is defined, if any 
  748.         transition variables or tables are specified 
  749.  
  750.     -   SELECT privilege on any table or view referenced in the triggered 
  751.         action condition 
  752.  
  753.     -   Necessary privileges to invoke the triggered SQL statements specified. 
  754.  
  755.  
  756. ΓòÉΓòÉΓòÉ 3.1.1.2. Create DB2 Trigger Conditions ΓòÉΓòÉΓòÉ
  757.  
  758. This panel allows correlation names and temporary table names to be set. 
  759. Trigger conditions can also be entered here. 
  760.  
  761. Specify a condition that is true, false, or unknown. The search-condition 
  762. provides a capability to determine whether or not a certain triggered action 
  763. should be executed for a given row or for the statement (depending on the 
  764. granularity of the trigger). 
  765.  
  766. The associated action is performed only if the specified search condition 
  767. evaluates as true. If the WHEN clause is omitted, the trigger actions are 
  768. always performed. 
  769.  
  770. You can drag a Visualizer SQL Statement onto the data entry area, and use all 
  771. or part of that SQL in your trigger conditions. 
  772.  
  773.  
  774. ΓòÉΓòÉΓòÉ 3.1.1.3. Create DB2 Trigger Actions ΓòÉΓòÉΓòÉ
  775.  
  776. One or more SQL statements can be entered here. If the trigger is a BEFORE 
  777. trigger, then a triggered SQL statement must be one of the following: 
  778.  
  779. o   a fullselect 
  780.  
  781. o   a SET transition-variable SQL statement 
  782.  
  783. o   a signal 
  784. If the trigger is an AFTER trigger, then a triggered SQL statement must be one 
  785. of the following: 
  786.  
  787. o   an INSERT SQL statement 
  788.  
  789. o   a searched UPDATE SQL statement 
  790.  
  791. o   a searched DELETE SQL statement 
  792.  
  793. o   a signal 
  794.  
  795. o   a fullselect 
  796. The triggered-SQL-statement can not reference an undefined transition variable 
  797.  
  798.  
  799. ΓòÉΓòÉΓòÉ 3.1.1.4. Correlation names and Temporary table names ΓòÉΓòÉΓòÉ
  800.  
  801. The use of correlation names and temporary table names allows a trigger 
  802. definition to access the rows affected by the triggering SQL operation in their 
  803. state before and after the triggering SQL operation. Correlation names may only 
  804. be used for a trigger defined as FOR EACH ROW.  The correlation names refer to 
  805. two sets of transition variables which represent all of the columns of the 
  806. table being processed.  These transition variables can be referenced as: 
  807.  
  808. oldname.columname
  809.  
  810. and
  811. newname.columname
  812.  
  813. where oldname is the old correlation name specified, newname is the new 
  814. correlation name specified and columnname is the name of the equivalent column 
  815. in the trigger subject table. 
  816.  
  817. Temporary table names may be used in both FOR EACH STATEMENT and FOR EACH ROW 
  818. triggers.  The temporary tables contain the complete set of rows affected by 
  819. the triggering SQL operation in their state before and after that operation. 
  820.  
  821. Rules 
  822.  
  823.  
  824. ΓòÉΓòÉΓòÉ 3.1.1.5. Rules ΓòÉΓòÉΓòÉ
  825.  
  826. o   None of the OLD and NEW correlation names and the OLD_TABLE and NEW_TABLE 
  827.     names can be identical. 
  828.  
  829. o   Only one OLD and one NEW correlation-name may be specified for a trigger. 
  830.  
  831. o   Only one OLD_TABLE and one NEW_TABLE identifier may be specified for a 
  832.     trigger. 
  833.  
  834. o   The OLD correlation-name and the OLD_TABLE identifier, can only be used if 
  835.     the trigger event is either a DELETE operation or an UPDATE operation. If 
  836.     the operation is a DELETE operation, OLD correlation-name captures the 
  837.     value of the deleted row. If it is an UPDATE operation, it captures the 
  838.     value of the row before the UPDATE operation. The same applies to the 
  839.     OLD_TABLE identifier and the set of affected rows. 
  840.  
  841. o   The NEW correlation-name and the NEW_TABLE identifier can only be used if 
  842.     the trigger event is either an INSERT operation or an UPDATE operation. In 
  843.     both operations, the value of NEW captures the new state of the row as 
  844.     provided by the original operation and as modified by any BEFORE trigger 
  845.     that has executed to this point. The same applies to the NEW_TABLE 
  846.     identifier and the set of affected rows. 
  847.  
  848. o   OLD_TABLE and NEW_TABLE identifiers cannot be defined for a BEFORE trigger. 
  849.  
  850. o   OLD and NEW correlation-names cannot be defined for a FOR EACH STATEMENT 
  851.     trigger 
  852.  
  853. o   The scope of each correlation-name and each identifier is the entire 
  854.     trigger definition. 
  855.  
  856.  
  857. ΓòÉΓòÉΓòÉ 4. Creation of User Defined Types ΓòÉΓòÉΓòÉ
  858.  
  859. DB2/2 Version 2 and DB2/6000 version 2 provide the capability to define 
  860. Distinct Data Types.  Distinct data types must be created based on the data 
  861. types built in to the database. When a distinct type is created using this 
  862. utility, the user is offered the opportunity to create versions of all the 
  863. functions that can be used by the base type for use with the user defined 
  864. types. The utility allows user selection of the functions required, and 
  865. generates the SQL to create all of the functions. The user can tailor the SQL 
  866. for individual functions before applying the SQL to one or more databases, or 
  867. saving the complete SQL in text form. The text created can be used directly 
  868. from the DB2 command line processor, using the -f parameter. 
  869.  
  870.  
  871. ΓòÉΓòÉΓòÉ 4.1. Create DB2 Distinct Types ΓòÉΓòÉΓòÉ
  872.  
  873. This panel allows the general details of a user defined distinct type to be 
  874. entered.  The panel comprises the following fields: 
  875.  
  876. Database 
  877.  
  878.            The local alias of the DB2 Version 2 database in which the distinct 
  879.            type is to be created. 
  880.  
  881. Type Schema 
  882.  
  883.            The schema in which the distinct type is to be created.  If not 
  884.            specified, this will default to the authorization ID.  Only 
  885.            authorization IDs with DBADM privilege are allowed to created 
  886.            distinct types in other schemas. 
  887.  
  888. Type Name 
  889.  
  890.            The name of the distinct type to be created. 
  891.  
  892. From Source Data Type 
  893.  
  894. Name 
  895.  
  896.            A user defined distinct type must be based on a built in type. 
  897.            Select the appropriate type from the selection list. 
  898.  
  899. Length 
  900.  
  901.            A distinct type must have a specific length property.  This 
  902.            capability allows distinct types to be created for specific types of 
  903.            data.  The length should be entered as required. 
  904.  
  905. Scale 
  906.  
  907.            For data types based on DECIMAL, this field represents the number of 
  908.            decimal places.  For LOB types, the scale is the unit (K - 
  909.            Kilobytes, M Megabytes, G Gigabytes) of length specified in the 
  910.            length entries. 
  911.  
  912. Replicate Selected Functions 
  913.  
  914. Replicate All Functions 
  915.  
  916.            The functions which may be replicated by this utility are those 
  917.            which accept one or more arguments of the base type.  You may choose 
  918.            to replicate all of the functions which meet these criteria, or to 
  919.            select from the available functions those that you wish to 
  920.            replicate. 
  921.  
  922. Select Functions 
  923.  
  924.            If you chose Replicate Selected Functions above, this button will 
  925.            become available to select the functions you wish to replicate, 
  926.            using the Select functions panel.  Selections already made may also 
  927.            be modified.  Functions that have been selected will appear in the 
  928.            selected functions list on the main window. 
  929.  
  930. Selected Functions List 
  931.  
  932.            Double clicking on an entry in the list will open the Edit SQL 
  933.            panel, allowing the SQL for that function to be viewed or modified. 
  934.  
  935. Create 
  936.  
  937.            Select this push button to create the selected functions in the 
  938.            database. 
  939.  
  940. Save text... 
  941.  
  942.            Select this pushbutton to save the generated SQL to a text file. 
  943.  
  944. Close 
  945.  
  946.            Select the pushbutton to close the window and exit. 
  947.  
  948. Help 
  949.  
  950.            Invoke this help. 
  951.  
  952.  
  953. ΓòÉΓòÉΓòÉ 4.1.1. Select functions ΓòÉΓòÉΓòÉ
  954.  
  955. Function Schema 
  956.  
  957.            An entry will appear in the list for each schema in the database 
  958.            containing function definitions available for replication for the 
  959.            type being created.  When a function schema is selected, each of the 
  960.            available functions in the schema will be listed in the listbox 
  961.            below.  You can then select the individual functions for the 
  962.            selected schema, before selecting any further schemas to process. 
  963.  
  964. Select All 
  965.  
  966.            This pushbutton causes all of the listed functions in the schema to 
  967.            be selected for replication.  You may then deselect individual 
  968.            functions by clicking on the list box, with the Ctrl key pressed. 
  969.  
  970. Deselect All 
  971.  
  972.            This pushbutton causes all of the listed functions in the schema to 
  973.            be deselected for replication.  You may then select individual 
  974.            functions by clicking on the list box. 
  975.  
  976. OK 
  977.  
  978.            Saves the selections you have made and closes the selection dialog. 
  979.  
  980. Cancel 
  981.  
  982.            Abandons the selections you have made and closes the selection 
  983.            dialog. 
  984.  
  985. Help 
  986.  
  987.            Invokes this help. 
  988.  
  989.  
  990. ΓòÉΓòÉΓòÉ 4.1.2. Edit SQL ΓòÉΓòÉΓòÉ
  991.  
  992. SQL for functions 
  993.  
  994.            The panel contains a multi line editable box, which contains the SQL 
  995.            that has been generated for replication of a selected function. 
  996.            There will be one CREATE FUNCTION statement for each unique function 
  997.            generated, with the statements separated by a semi-colon(;).  You 
  998.            may edit the SQL to remove, add or alter function definitions to 
  999.            your requirements. 
  1000.  
  1001. OK 
  1002.  
  1003.            Saves the edited changes as the SQL to be used for the selected 
  1004.            function, in place of the default SQL generated by the utility. 
  1005.  
  1006. Validate 
  1007.  
  1008.            Prepares the SQL against the database, and reports any errors. 
  1009.  
  1010. Default 
  1011.  
  1012.            Replaces the SQL that has been updated by the user with the default 
  1013.            generated by the utility.  This can be done even after the changed 
  1014.            SQL has been saved using OK. 
  1015.  
  1016. Cancel 
  1017.  
  1018.            Abandons any changes made since the panel was opened, and closes the 
  1019.            panel. 
  1020.  
  1021. Help 
  1022.  
  1023.            Invokes this help. 
  1024.  
  1025.  
  1026. ΓòÉΓòÉΓòÉ 5. Using the DB2 Command Line Processor ΓòÉΓòÉΓòÉ
  1027.  
  1028. If you are using DB2 Version 2, you will have access to the DB2 Command Line 
  1029. Processor(CLP).  This facility allows commands and SQL to be applied to the 
  1030. database directly from an operating system prompt.  The CLP is invoked using 
  1031. the command: 
  1032.  
  1033. db2
  1034.  
  1035. The CLP supports many options, which are documented in the DB2 Command 
  1036. Reference.  However, there are some special considerations when using the CLP 
  1037. with files generated by the Visualizer DB2 Toolkit.
  1038.  
  1039.  
  1040. Specifying an Input File to the DB2 CLP 
  1041. Running SQL Saved from Create Type or Create Table 
  1042. Running SQL Saved from Create Trigger 
  1043. Other Useful DB2 CLP Options 
  1044. Changing the Terminator for Create Trigger 
  1045.  
  1046.  
  1047. ΓòÉΓòÉΓòÉ 5.1. Specifying an Input File to the DB2 CLP ΓòÉΓòÉΓòÉ
  1048.  
  1049. To use a file with one command or statement per line as input to the CLP, use 
  1050. the -f option.  For example, to use the file c:\work\sqllines.sql as input to 
  1051. the CLP: 
  1052.  
  1053. db2 -fc:\work\sqllines.sql
  1054.  
  1055.  
  1056. ΓòÉΓòÉΓòÉ 5.2. Running SQL Saved from Create Type or Create Table ΓòÉΓòÉΓòÉ
  1057.  
  1058. SQL statements can be very long, and having the whole of a statement on a 
  1059. single line can be difficult to manage, and may easily exceed the capabilities 
  1060. of many text editors.  The DB2 CLP provides the -t option allows SQL to be 
  1061. split over multiple lines.  This options specifies that a command or  SQL 
  1062. statement may span lines, and will be terminated by the semi-colon(;) 
  1063. character.  Text files saved from the Create Table or Create Type utility are 
  1064. semicolon separated.  To run them use the -t option.  For example: 
  1065.  
  1066. db2 -t -fc:\toolkit\cretab.sql
  1067.  
  1068.  
  1069. ΓòÉΓòÉΓòÉ 5.3. Running SQL Saved from Create Trigger ΓòÉΓòÉΓòÉ
  1070.  
  1071. The actions clause of a Create Trigger statement may contain multiple 
  1072. statements.  When entered, these statement must be separated by semicolons. 
  1073. SQL is generated in the following form: 
  1074.  
  1075. ....
  1076. ....
  1077. begin atomic
  1078. statement1;
  1079. statement2;
  1080. end
  1081.  
  1082.  DB2 allows only the semicolon character to separate action statements in a 
  1083. trigger.  Because of this, the trigger utility terminates the complete Create 
  1084. Trigger statement with the tilde (~) character.  The tilde character must be 
  1085. specified as the terminator to the CLP when you use SQL generated by Create 
  1086. Trigger.  Do this using the -tdx option: 
  1087.  
  1088. db2 -fc:\toolkit\cretab.sql -td~
  1089.  
  1090.  
  1091. ΓòÉΓòÉΓòÉ 5.4. Changing the Terminator for Create Trigger ΓòÉΓòÉΓòÉ
  1092.  
  1093. The terminator character (default tilde(~)) can be changed by altering entry 
  1094. 110 in the file TRGLANG.DAT, which will be in the directory you specified for 
  1095. installation of the toolkit.  See Translating the Toolkit for further information.
  1096.  
  1097.  
  1098. ΓòÉΓòÉΓòÉ 5.5. Other Useful DB2 CLP Options ΓòÉΓòÉΓòÉ
  1099.  
  1100. The -v option allows you to see which commands and SQL are being processed by 
  1101. the CLP.  The -s option causes the CLP to halt in the event of an error. 
  1102.  
  1103.  
  1104. ΓòÉΓòÉΓòÉ 6. National Language Enablement ΓòÉΓòÉΓòÉ
  1105.  
  1106. Each utility has a translatable language file, containing all the text and 
  1107. messages which it uses.  These files have the following names:
  1108.  
  1109. o   TRGLANG.DAT - Create Trigger 
  1110.  
  1111. o   TABLANG.DAT - Create Table 
  1112.  
  1113. o   TYPLANG.DAT - Create Type 
  1114.  
  1115. o   TKTLANG.DAT - Toolkit Launcher (AIX Only)
  1116.  
  1117. For OS/2, these files are installed in the directory where you installed the 
  1118. toolkit, and may be translated to any language of your choice.  If you wish to 
  1119. support multiple languages concurrently, you can install multiple copies of the toolkit.
  1120.  
  1121. For AIX, the toolkit is implemented so that you can support multiple languages 
  1122. concurrently from a single installation of the toolkit.  Because of this, the 
  1123. language files are installed in a subdirectory of the toolkit install 
  1124. directory, matching the locale that was effective when the toolkit was 
  1125. installed.  If you installed the toolkit under locale En_US, to directory 
  1126. /home/toolkit, the install process will create s directory /home/toolkit/En_US 
  1127. and copy the 4 language files listed above to that directory.  The installer 
  1128. will also copy the help and on line documents to the same directory.  The have 
  1129. the names:
  1130.  
  1131. ftbeas01.INF
  1132.  
  1133. You can update these files using a text editor, replacing each line with it's 
  1134. equivalent in the language of your choice.  Any changes will be reflected as 
  1135. soon as the equivalent utility is restarted.
  1136.  
  1137. If you wish to translate the help text or other documentation, please contact EAS.
  1138.  
  1139.  
  1140. ΓòÉΓòÉΓòÉ 7. Definition of Terms ΓòÉΓòÉΓòÉ
  1141.  
  1142.  
  1143. ΓòÉΓòÉΓòÉ 7.1. IBM EAS Product Support ΓòÉΓòÉΓòÉ
  1144.  
  1145. EAS is the worldwide centre of competence on Visualizer, IBM's query and 
  1146. decision support family. EAS provides technical and marketing support to IBM 
  1147. countries.  For further information contact EAS via: 
  1148.  
  1149. IBM Network EASPS at WINVMD 
  1150.  
  1151. IBMMAIL    GBIBM8L2 at IBMMAIL 
  1152.  
  1153. InterNet   GBIBM8L2@IBMMAIL.COM 
  1154.  
  1155. Fax:       44 1926 410764 (01 926 410764 from the UK)
  1156.  
  1157.  
  1158. ΓòÉΓòÉΓòÉ 7.2. Database 2 for OS/2 ΓòÉΓòÉΓòÉ
  1159.  
  1160. Database 2 for OS/2, also known as DB2/2 is the member of the Database 2 Client 
  1161. Server Family which runs on IBM's OS/2 Operating System.  The product is 
  1162. available either standalone or as a server.  DB2/2 Version 2 Servers can 
  1163. support clients running in many environments including DOS, Windows, OS/2, AIX 
  1164. on Risc System/6000, HP-UX, SUN-Solaris, OS/400, VM and MVS. 
  1165.  
  1166.  
  1167. ΓòÉΓòÉΓòÉ 7.3. Database 2 for AIX ΓòÉΓòÉΓòÉ
  1168.  
  1169. Database 2 for AIX, also known as DB2/6000 is the member of the Database 2 
  1170. Client Server Family which runs on IBM's AIX Operating System on Risc 
  1171. System/6000.  The product is available either standalone or as a server. 
  1172. DB2/6000 Version 2 Servers can support clients running in many environments 
  1173. including DOS, Windows, OS/2, AIX on Risc System/6000, HP-UX, SUN-Solaris, 
  1174. OS/400, VM and MVS. 
  1175.  
  1176.  
  1177. ΓòÉΓòÉΓòÉ 7.4. Referential Constraint ΓòÉΓòÉΓòÉ
  1178.  
  1179. See Referential Constraint/Foreign Key.
  1180.  
  1181.  
  1182. ΓòÉΓòÉΓòÉ 7.5. Foreign Key ΓòÉΓòÉΓòÉ
  1183.  
  1184. See Referential Constraint/Foreign Key.
  1185.  
  1186.  
  1187. ΓòÉΓòÉΓòÉ 7.6. Constraint ΓòÉΓòÉΓòÉ
  1188.  
  1189. A constraint is a rule that the database manager enforces. There are two types 
  1190. of constraints:
  1191.  
  1192. o   A referential constraint is a logical rule about values in one or more 
  1193.     columns in one or more tables. For example, a set of tables shares 
  1194.     information about a corporation's suppliers. Occasionally, a supplier's 
  1195.     name changes. A referential constraint could be defined stating that when 
  1196.     one of those tables changes the name of a supplier then the other tables 
  1197.     automatically have that name changed too.
  1198.  
  1199. o   A table check constraint sets restrictions on data added to a specific 
  1200.     table. For example, it could define the salary level for an employee to 
  1201.     never be less than ╨¼20,000.00 when salary data was added to a table 
  1202.     containing personnel information. 
  1203.  
  1204.  
  1205. ΓòÉΓòÉΓòÉ 7.7. Structured Query Language ΓòÉΓòÉΓòÉ
  1206.  
  1207. Structured Query Language (SQL) is a standardised language for defining and 
  1208. manipulating data in a relational database. 
  1209.  
  1210.  
  1211. ΓòÉΓòÉΓòÉ 7.8. DB2 Version 2 ΓòÉΓòÉΓòÉ
  1212.  
  1213. DB2 version 2 includes DB2/2 version 2 and DB2/6000 version 2.  Version 2 of 
  1214. the common server for other operating systems are also included, as these 
  1215. become available.
  1216.  
  1217.  
  1218. ΓòÉΓòÉΓòÉ 7.9. Referential Constraint/Foreign Key ΓòÉΓòÉΓòÉ
  1219.  
  1220. A foreign key is a column or set of columns in a table whose values are 
  1221. required to match at least one primary key value of a row of its parent table. 
  1222. A referential constraint is the rule that the values of the foreign key are 
  1223. valid only if: 
  1224.  
  1225. o   They appear as values of a parent key (primary key), or 
  1226.  
  1227. o   Some component of the foreign key is null.
  1228.  
  1229. The table containing the parent key is called the parent table of the 
  1230. referential constraint, and the table containing the foreign key is said to be 
  1231. a dependent of that table. 
  1232.  
  1233. Referential constraints with a delete or update rule of RESTRICT are enforced 
  1234. before all other referential constraints. Other referential constraints are 
  1235. enforced in an order independent manner. That is, the order does not effect the 
  1236. result of the op.
  1237.  
  1238. Referential constraints with a delete or update rule of NO ACTION behave like 
  1239. RESTRICT in most cases. However, in a complex query there can be a difference. 
  1240.