IBM i Global

IBM i Global

Connect, learn, share, and engage with IBM Power.

 View Only
Expand all | Collapse all

SQL Query for DB2400

  • 1.  SQL Query for DB2400

    Posted Fri April 18, 2025 12:53 PM
    Hi,  

     Is there an SQL query that can be used to fetch and extract existing DB2 iSeries (IBM i) schema details - including table structures, data types, constraints, primary/foreign key relationships, and indexes?


    Thanks...


  • 2.  RE: SQL Query for DB2400

    Posted Fri April 18, 2025 02:48 PM

    Jerry - there are a number of catalog tables you can query for the above - give this a shot ->IBM i catalog tables and views - IBM Documentation



    ------------------------------
    Rich Malloy
    Principal Systems Engineer - IBMi
    Cox Automotive
    Draper UT
    ------------------------------



  • 3.  RE: SQL Query for DB2400

    Posted Fri April 18, 2025 04:01 PM

    What if I need to use the best among these available meeting all these details using single SQL Query here ?

    Thanks...




  • 4.  RE: SQL Query for DB2400

    Posted Sat April 19, 2025 03:31 AM

    Appreciate prompt response from experts here.

    Thanks..




  • 5.  RE: SQL Query for DB2400

    Posted Sat April 19, 2025 07:53 AM

    I mean using a single SQL query can all these desired details bd Obtained if yes then could someone please share that SQL query here?

    Thanks..




  • 6.  RE: SQL Query for DB2400

    Posted Mon April 21, 2025 05:14 PM

    I guess you can write your own SELECT statement joining the desired tables to get a single answer.  Anyway, you can search Internet for samples. Most of the examples will be based on DB2 for other platforms (z or LUW), but in most of the cases changing SYSIBM by QSYS2 will be enough to get the expected results, except when you are searching for very specific IBM i matters, such as MEMBERs and System Names



    ------------------------------
    Daniel Jose Lema Guanziroli
    ------------------------------



  • 7.  RE: SQL Query for DB2400

    Posted Mon April 21, 2025 01:15 AM
    Edited by Satid S Mon April 21, 2025 01:20 AM

    Dear Jerry

    There is no single query that does what you asked about. But you can write multiple SQL statements that are bundled into a single "compound" statement (encapsulated in  BEGIN and END) that run as one.   

    Your question reminds me of a GUI tool in the old IBM i Navigator tool that came with the old IBM i Access For Windows. This tool is called DB Navigator and you can invoke it at the entire Database or Schema level of IBM i Navigator.  This tool makes queries to Db2i catalog views and presents a graphical "network map" of the DB objects and their relationship (indicted by lines that link nodes).  You can explore each objects in the network map that looks like the sample below.  Somehow, this tool was abandoned from IBM i Access Client Solutions.

    ------------------------------
    Satid S
    ------------------------------



  • 8.  RE: SQL Query for DB2400

    Posted Mon April 21, 2025 06:29 PM

    Adding to what @Satid said, you can also use an external Entity Relationship Modelling software such as the very popular Erwin Data Modeler, that is able to make a complete (or partial if you wish) reverse engineering over your DB2 for IBM i database.



    ------------------------------
    Daniel Jose Lema Guanziroli
    ------------------------------



  • 9.  RE: SQL Query for DB2400

    Posted Tue April 22, 2025 03:43 AM

    One thing  I just want to add is dont expect any of the magic diagrams to draw pretty pictures if its defined by DDS. 

    In my own experience all these diagrams only work accurately if they are defined by the database constructs which people normally assume are there and there might be a mixture of the two DDS vs DDL Constructs around on some installations that attempted database migration. 

    If that is the case which you might find yourself in then these tools are the ones that normally will assist in those diagrams : 

    https://xcasefori.com/ 

    https://freschesolutions.com/products/x-analysis-suite/

    Hope it helps. 



    ------------------------------
    Marius le Roux theIBMiGuy
    Owner , IBM i Consultant & Technology Strategist
    MLR Consulting
    ------------------------------



  • 10.  RE: SQL Query for DB2400

    Posted Wed April 23, 2025 03:48 AM

    It is worth noting that such tools will also use the program source code (RPG or COBOL) logic to determine inferred relationships between entities.  That can be essential for legacy applications where the database referential integrity is managed in logic and not defined as a database constraint.  

    https://freschesolutions.com/products/x-analysis-suite/



    ------------------------------
    Steve Cast
    IBM Champion
    Practice Director Fresche Solutions

    ------------------------------