• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Bringing Home The Data

    April 3, 2013 Michael Sansoterra

    In IBM i 7.1 Technology Refresh 4 (TR4), IBM gave SQL developers the ability to insert data into a local database table from a remote DB2 for i database table within the comfort of a single SQL statement. (See my article Copy Data From A Remote DB2 Database Using DB2 For i 7.1 for more info).

    With Technology Refresh 5, specifically DB2 for i Group PTF Level 18 or later, you can dynamically create a local table and insert data into it directly from a remote DB2 for i database query using the CREATE TABLE … AS statement.

    Recall that DB2 for i can access data from a remote DB2 for i machine or partition by using the three-part naming convention: DB2 remote relational database name/schema (a.k.a. library)/object (table, view, etc.). The remote data will be returned to the local session. In this example, the remote relational database name is RMTDB2:

    SELECT * 
      FROM RMTDB2/DATALIB/ITEM_MASTER IM
    

    When querying a remote database, only one remote system can be accessed. A single query cannot combine data from multiple remote and local systems unless you resort to something fancy like table functions to handle the remote access. (See my article Accessing Multiple DB2 Relational Databases In A Single Query for more info.)

    It was noted with TR4 that IBM allowed the INSERT statement to append rows from a remote database query into a local table:

    INSERT INTO QTEMP/ITEM_MASTER  -- Local Table
    SELECT * 
      FROM RMTDB2/DATALIB/ITEM_MASTER IM -- Remote Table, 
      view or query
    

    Best of all, CREATE TABLE AS now supports creating a table based on a remote relational database query that uses the three part naming convention:

    CREATE TABLE AS QTEMP/ITEM_MASTER (
    SELECT * FROM RMTDB2/DATALIB/ITEM_MASTER  -- Remote Table, 
    view or query
    ) WITH DATA
    

    The attributes of the local QTEMP/ITEM_MASTER table will be defined like the columns in the remote table. This feature opens up new vistas when querying data from multiple systems. Instead of resorting to table functions, PC-based data transfers, DDM, or ugly DRDA programs that constantly swap database connections, a developer can now get the remote data and place it in a local permanent or QTEMP table. From there, the data from the disparate sources can be joined, sorted, and analyzed from the comfort of a single SQL statement.

    Note:

    • CREATE TABLE can only create a local table.
    • Only one remote relational database can be referenced in the statement (unless you use something like a table function).
    • Propagated attributes from the remote query columns include long column name, short (system) column name, data type, length, precision and scale (for numeric columns), CCSID (character), null capable, column heading, and column text.
    • When creating a temporary table in QTEMP, the DECLARE GLOBAL TEMPORARY TABLE statement can be used instead of CREATE TABLE AS.
    • Other column attributes such as the default value, hidden, identity and row change timestamp can be propagated when specified on the copy-option portion of the CREATE TABLE AS statement.

    I hope IBM continues to enhance SQL statements to allow more statements to participate in true heterogeneous queries, where a single statement can combine and even modify data across multiple remote databases.

    For more information on configuring remote DB2 database access, please see the Related Stories listed below.

    Michael Sansoterra is a DBA for Broadway Systems in Grand Rapids, Michigan. Send your questions or comments for Mike via the IT Jungle Contact page.

    RELATED STORIES

    Accessing Multiple DB2 Relational Databases In A Single Query

    Copy Data From A Remote DB2 Database Using DB2 For i 7.1

    Execute SQL Statements on DB2 UDB for Windows from the iSeries

    Using DRDA to Execute SQL Statements on Another iSeries



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    BCD:  Recorded Webinar: How to mine IBM i report data & extract it to Excel
    Northeast User Groups Conference:  23nd Annual Conference, April 22 - 24, Framingham, MA
    COMMON:  Join us at the 2013 Conference & Expo, April 7 -10 in Austin, TX

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ The Reg: More News From ITJ EIC Timothy Prickett Morgan

    Attachmate Delivers Web Client for SFTP Tool Midrange Power7+ Servers: The IBM Sales Pitch

    Leave a Reply Cancel reply

Volume 13, Number 7 -- April 3, 2013
THIS ISSUE SPONSORED BY:

WorksRight Software
SEQUEL Software
Northeast User Groups Conference

Table of Contents

  • Bringing Home The Data
  • Updating Through A Join With SQL, Take Three
  • Admin Alert: A Checklist For Monitoring Your IBM i Environment

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle