iSeries database frequently asked questions

You can check the database FAQ for answers to your DB2® and Structured Query Language (SQL) questions. Topics in the FAQ include finding informative database resources, data sharing and migration, and several query topics.

DB2 Universal Database™ for iSeries™ fundamentals

  1. What is DB2 UDB for iSeries?
  2. Is the iSeries server part of the DB2 family?
  3. How does DB2 UDB for iSeries relate to other DB2 products?
  4. What level of DB2 do I have?
  5. Does iSeries provide any sample databases?
  6. How do I install DB2?
  7. How do I authorize users to DB2?
  8. How do I administer DB2 UDB for iSeries?
  9. Can I assign my own long and short names to tables and columns?

Database resources in the iSeries Information Center

  1. Where are the DB2 manuals located?
  2. I'm having trouble printing a PDF. What should I do?
  3. What other resources exist to help me use the information center?

Data sharing and database migration

  1. How do I move data between DB2 and other systems?
  2. How do I migrate existing databases to DB2 UDB for iSeries?
  3. Can I store XML data in DB2 UDB for iSeries?
  4. Can I connect to a DB2 database that is on a non-iSeries server from my iSeries server?

Query for iSeries

  1. How can I find all the queries that accessed a specific file?
  2. Does IBM® provide any graphical query interfaces for the iSeries server?

SQL-based queries

  1. How can I join two members of the same table?
  2. How can I run SQL statements from a text file?
  3. How can I write an SQL query that lists a set of detail records with a total at the bottom?
  4. How can I select rows based on the current date in numeric or character fields?
  5. Why is my query performing poorly after an upgrade to a newer release of i5/OS™?
  6. Start of changeCan I create an alias on a server for a table, view, or physical file that is on another server?End of change
  7. Start of changeWhen the first member of a multimember database file has the same name as the file, it is the only member of the file that you can access using SQL. How can I access another member using SQL?End of change

SQL messages

  1. When are SQL messages displayed?
  2. What does SQL0901 message code mean?
  3. Where can I find a listing of SQL messages and SQL codes?

SQL packages

  1. What are SQL packages?
  2. What are the advantages of using SQL packages?
  3. What data is stored in an SQL package?
  4. How can I tell what statements are in an SQL package?
  5. How can I tell if the SQL package is being used?

Stored procedures

  1. How can I view the contents of a result set and the output parameters from a stored procedure call?
  2. Can existing RPG or COBOL programs be used as stored procedures?
  3. I do a CREATE PROCEDURE that contains SQL statements that reference user-defined functions. Before calling the procedure, I do a SET PATH so the functions are found. Why aren't the functions found when I call the procedure?
  4. How do I find out if a stored procedure exists, in what library it exists, and what the attributes of the stored procedure are?

Triggers

  1. What is a trigger?
  2. Why does my trigger program not work after upgrading i5/OS?

DB2 Universal Database for iSeries fundamentals

  1. What is DB2 UDB for iSeries?

    DB2 UDB for iSeries is the relational database manager that is fully integrated on your iSeries server. Because it is integrated, DB2 UDB for iSeries is easy to use and manage. DB2 UDB for iSeries also provides functions such as triggers, stored procedures, and dynamic bitmapped indexing that serve a wide variety of application types. These applications range from traditional host-based applications to client/server solutions to business intelligence applications.

    The history of DB2 UDB for iSeries began in the late 1980s with the integration of a fully relational, though nameless, database on the first AS/400® systems. In 1995, this database joined the DB2 brand, adopting the name DB2/400. In 1999, the DB2 UDB branding was added.

    As an interface to DB2 UDB for iSeries, the DB2 Query Manager and SQL Development Kit for iSeries adds an interactive query and report writing interface, as well as precompilers and tools to assist in writing SQL application programs in high-level programming languages. Conforming to the industry standard SQL, the SQL implementation for i5/OS allows you to define, manipulate, query, and control access to your iSeries data. It works equally well with i5/OS files and SQL tables.

    Back to questions

  2. Is the iSeries server part of the DB2 family?

    Yes. DB2 UDB for iSeries is the newest member of the DB2 UDB product line, which also includes DB2 UDB and DB2 Universal Database™ for zSeries®. DB2 UDB, the founding member of the product line, is the single product available across all UNIX®, Windows NT®, and OS/2® operating systems.

    Back to questions

  3. How does DB2 UDB for iSeries relate to other DB2 products?

    Each member of the DB2 UDB product line has its own unique code-base, functions, and different SQL syntax. There is, however, technology sharing across the DB2 UDB brand members. To learn about the relationships between the DB2 UDB products, see the following information:

    Back to questions

  4. What level of DB2 do I have?

    If you are using an iSeries server, you have DB2 UDB for iSeries. The level of DB2 UDB for iSeries is based on the i5/OS operating system, and is independent of the DB2 versioning scheme. Because DB2 UDB for iSeries is included with the i5/OS operating system, the version, release, and modification level of DB2 is the same as that of your operating system. This is typically expressed as VxRyMz, where x is the version, y is the release, and m is the modification. If you do not know what version, release, and modification of i5/OS you have, use the following steps:

    1. In iSeries Navigator, right click your server.
    2. Select Properties.
    3. If it is not already selected, click the General tab.

    Back to questions

  5. Does the iSeries server provide any sample databases?

    Yes. You can find the sample tables and the system-provided stored procedure to create them in DB2 UDB for iSeries sample tables of the SQL programming topic.

    Back to questions

  6. How do I install DB2?

    You don't need to install DB2. It is shipped as a part of i5/OS at every release.

    Back to questions

  7. How do I authorize users to DB2?

    DB2 object access can be controlled using SQL GRANT and REVOKE statements along with i5/OS security interfaces. See Secure a database in the Database programming topic. iSeries Navigator can also be used to authorize users. For more information, see Authorize a user or group using iSeries Navigator.

    Back to questions

  8. How do I administer DB2 UDB for iSeries?

    You can administer DB2 UDB for iSeries using iSeries Navigator. Within iSeries Navigator there is a tool for working with databases. You can work either from a traditional tree view of you database, or from a visual representation of the database objects called Database Navigator. For details about using Database Navigator, see Map your database using Database Navigator maps.

    Back to questions

  9. Can I assign my own long and short names to tables and columns?

    Yes. See Co-existing with "long" SQL table and column namesLink outside information center for instructions.

    Back to questions

Database resources in the iSeries Information Center

  1. Where are the DB2 manuals located?

    The Softcopy Library was integrated into the iSeries Information Center in V5R1. You can find database manuals by following the (PDFs) link in the information center navigation bar under the Database topic.

    Back to questions

  2. I'm having trouble printing a PDF. What should I do?

    It is recommended that you save PDF files locally for ease in viewing and printing. To save the PDF, follow these steps:

    1. Right-click the PDF in your browser.
    2. Click Save Target As...
    3. Navigate to the directory in which to save the PDF.
    4. Click Save.

    Back to questions

  3. What other resources exist to help me use the information center?

    See the Frequently asked questions about the information center topic. This FAQ contains tips that make using the information center easier. You can also find help by clicking the help button in the upper right of your screen.

    Back to questions

Data sharing and database migration

  1. How do I move data between DB2 and other systems?

    You can use the Copy From Import File (CPYFRMIMPF) and Copy To Import File (CPYTOIMPF) commands to import (load) or export (unload) data from and to the iSeries server. See the Import and export data between systems topic for instructions.

    Back to questions

  2. How do I migrate existing databases to DB2 UDB for iSeries?

    IBM provides several guides to help you move data into DB2 UDB for iSeries from other databases, such as Oracle and SQL Server. See DB2 Porting InformationLink outside information center for the guides.

    Back to questions

  3. Can I store XML data in DB2 UDB for iSeries?

    Yes. See the XML Extender Administration and ProgrammingLink to PDF manual for tutorials on how to set up a database using provided sample data, how to map SQL data to an XML document, how to store XML documents in the database, and how to search and extract data from the XML documents.

    Back to questions

  4. Can I connect to a DB2 database that is on a non-iSeries server from my iSeries server?

    Yes. You can learn more in User FAQs of the Distributed database programming topic.

    Back to questions

Query for iSeries

  1. How can I find all the queries that accessed a specific file?

    You can follow these steps to produce a report of all the queries containing the file name:

    1. Copy the code in Example: Find the queries that accessed a specific file, replacing &LIBRARY and &FILE with your library and file names.
    2. Create the command FFINQ using the Create Command (CRTCMD) command.
    3. Specify GETQRYPRM as the program to process command.

    Back to questions

  2. Does IBM provide any graphical query interfaces for the iSeries server?

    The graphical query interface software provided for iSeries includes DB2 Query Management FacilityLink outside information center and DB2 Web Query ToolLink outside information center.

    Back to questions

SQL-based queries

  1. How can I join two members of the same table?

    You can join two members of the same table by creating an alias for one of the members and joining them using the alias. To create an alias using SQL, see the Create and use ALIAS names or Create database objects topic.

    Back to questions

  2. How can I run SQL statements from a text file?

    You can run SQL statements from a text file using the Run SQL Statements (RUNSQLSTM) command. Or, you can use Run SQL Scripts from iSeries Navigator to run a text file on your PC or in the integrated file system. See Query your database using the Run SQL Scripts interface.

    Back to questions

  3. How can I write an SQL query that lists a set of detail rows with a total at the bottom?
    You can use a UNION operation to append the total as a row at the end of the list of items, as illustrated in the following example:
    SELECT 'ITEM' AS ROWTYPE, PARTID, PRICE
        FROM PART
    UNION
    SELECT 'TOTAL' AS ROWTYPE, 0 AS PARTID, SUM( PRICE ) AS PRICE
        FROM PART 
    ORDER BY ROWTYPE, PARTID

    To make sure that the total row is at the end of the result set, you must include the Order By clause.

    Back to questions

  4. How can I select rows based on the current date in numeric or character fields?

    The SQL CurDate function returns a date value, which cannot be directly compared to a number or an unformatted character value. You must do some conversion before the comparison. Use SQL functions to get the year, month, and day of the date as integers, and then create a numeric date in the form YYYYMMDD. See the code in Example: Select records based on the current date.

    Back to questions

  5. Why is my query performing poorly after an upgrade to a newer release of i5/OS?

    There can be some query performance problems if you recently upgraded from V4R4 to a newer release or version. See IBM DB2 UDB Query Performance Behavior Changes Since R440Link outside information center for a possible solution.

    Back to questions

  6. Start of changeCan I create an alias on a server for a table, view, or physical file that is on another server?

    No. When you create an alias, make sure that the table, view, or physical file you create it for is on the current server. For more information, see CREATE ALIAS, with some syntax examples.

    Back to questions

    End of change
  7. Start of changeWhen the first member of a multimember database file has the same name as the file, it is the only member of the file that you can access using SQL. How can I access another member using SQL?

    You can create an alias to point at the first member you want to access.

    Example 2: Create an alias named SALES_JANUARY on the JANUARY member of the SALES table. The sales table has 12 members (one for each month of the year).
    CREATE ALIAS SALES_JANUARY
      FOR SALES(JANUARY)
    For the complete example in the SQL reference, see CREATE ALIAS.

    Back to questions

    End of change

SQL messages

  1. When are SQL messages displayed?

    SQL messages are displayed when a DB2 UDB for iSeries returns an error or code to the application that uses it. The message text is displayed or logged at run time.

    Back to questions

  2. What does the SQL0901 message mean?

    SQL0901: An SQL system error has occurred. This is the general message for all errors. For more information about SQL0901, see the SQL messages and codes topic.

    Back to questions

  3. Where can I find a list of SQL messages and SQL codes?

    You can find a complete list of SQL messages and codes in the SQL messages and codes topic. Or use SQL message finder.

    An application can also send the SQL message corresponding to any SQLCODE to the job log by specifying the message ID and the replacement text on the CL commands Retrieve Message (RTVMSG), Send Program Message (SNDPGMMSG), and Send User Message (SNDUSRMSG).

    Back to questions

SQL packages

  1. What are SQL packages?

    SQL packages are permanent objects that are used to store information related to prepared SQL statements. They are used by open database connectivity (ODBC) support when the Extended Dynamic box is checked on a data source. They are also used by applications that use an API.

    Back to questions

  2. What are the advantages of using SQL packages?

    Because SQL packages are a shared resource, when a statement is prepared, the information is available to all the users of the package. This saves processing time, especially in an environment when many users are using the same or similar statements. Because SQL packages are permanent, this information is also saved across job initiation and end, and is also saved across system restarts. In fact, SQL packages can be saved and restored on other systems. By comparison, dynamic SQL requires that each user go through the preparatory processing for a particular statement, and this must be done every time the user starts the application.

    SQL packages also allow the system to accumulate statistical information about the SQL statements that result in better decisions about how long to keep cursors open internally and how to best process the data needed for the query. This information is shared across users and retained for future use. In the case of dynamic SQL, this information must be gathered by every job and every user.

    Back to questions

  3. What data is stored in an SQL package?

    The SQL package contains all the necessary information to run the prepared statement. This includes registry of the statement name, the statement text, the internal parse tree for the statement, definitions of all the tables and fields involved in the statement, and the query access plan needed to access the tables at run time.

    Back to questions

  4. How can I tell what statements are in an SQL package?

    Use the Print SQL Information (PRTSQLINF) command to produce a formatted report that shows the SQL statement and information about the access plan used to access the data.

    Back to questions

  5. How can I tell if the SQL package is being used?
    Use the Print SQL Information (PRTSQLINF) command to produce a formatted report that shows the SQL statement and information about the access plan used to access the data. Use the database monitor to log information about SQL processing on the system. It includes the name of the package in the SQL summary records. The following statement shows the package, the SQL operation, and the statement text:
    SELECT qqc103, qqc21, qq1000 from <db monitor file>

    For ODBC, you can also look in the job log for the message Extended Dynamic has been disabled to determine if ODBC was unable to use an SQL package.

    Back to questions

For more SQL package FAQs, see the DB2 Universal Database for iSeries Frequently Asked Questions: Improving Performance with SQL PackagesLink outside information center.

Stored procedures

  1. How can I view the contents of a result set and the output parameters from a stored procedure call?

    Use Run SQL Scripts to run the procedure in iSeries Navigator. First, open the Run SQL Scripts window. Then, call the stored procedure using the CALL statement, pass the parameters to the statement, and then run the procedure. The parameters are returned to the Result Set tab, and the output parameters are returned to the Messages tab.

    Back to questions

  2. Can existing RPG or COBOL programs be used as stored procedures?

    Yes. DB2 UDB for iSeries supports external stored procedures, which allows existing high-level programs to be called as stored procedures. The CREATE PROCEDURE statement is used to register these programs as stored procedures.

    Back to questions

  3. I do a CREATE PROCEDURE that contains SQL statements that reference user-defined functions. Before calling the procedure, I do a SET PATH so the functions are found. Why aren't the functions found when I call the procedure?

    The SET PATH statement must be done before the CREATE PROCEDURE statement. The path for static statements in a precompiled program is determined when the program is created. In the case of CREATE PROCEDURE, we create an SQL C program. Dynamic statements in the procedure use the current path, but the static statements in the procedure use the path that was used at the time of creation. This is also true for the CREATE FUNCTION statement.

    Back to questions

  4. How do I find out if a stored procedure exists, in what library it exists, and what the attributes of the stored procedure are?
    To see the stored procedures on the system, you need to query the SYSPROCS catalog view. For example:
    SELECT * from sysprocs where routine_name = 'MYPROC' and routine_schema = 'MYLIB'
    This checks to see if there is a stored procedure named myproc in mylib. If you do not know the library, do not include the routine_schema part of the search condition in the query. See iSeries catalog tables and views in the SQL reference topic for the definition of all the columns for the SYSPROCS catalog. You might also be interested in the SYSPARMS catalog, which contains the parameter definitions for a procedure.

    Back to questions

Triggers

  1. What is a trigger?

    A trigger is a set of actions that are run automatically when a specified change or read operation is performed on a specified table or on a specified physical database file. For more information, see Trigger automatic events in your database.

    Beginning in V5R1, you can also use SQL triggers. The SQL CREATE TRIGGER statement provides a way for the database management system to actively control, monitor, and manage a group of tables whenever an insert, update, or delete operation is performed. The statements specified in the SQL trigger are run each time an SQL insert, update, or delete operation is performed. An SQL trigger can call stored procedures or user-defined functions to perform additional processing when the trigger is run. For more information, see SQL triggers.

    Back to questions

  2. Why does my trigger program not work after upgrading i5/OS?

    The offset of your record might have changed. For several releases in the past, the offset did not change. It did, however, change for V5R1 and might change in subsequent releases. The easiest solution is to always code your trigger programs to use the offsets and lengths passed in the trigger buffer. For a summary of fields in the trigger buffer, see Trigger buffer field descriptions.

    Back to questions