Using three-part names, Insert statements can now reference objects from more than one IBM i system.
The GA version of the DB2 for i 7.1 release simplified access to DB2 objects on remote systems by eliminating the need for explicit remote connections with the new three-part name support. Instead of developers having to use an extra CONNECT or SET CONNECTION statement to explicitly connect statement, they can now simply run an SQL statement like the following to retrieve data from a table on a different system or partition.
SELECT lastname, address, city FROM rmtsystem.datalib.customer
WHERE state='IA'
The SELECT statement in this example accesses a remote table with a three-part name value of rmtsystem.rmtschema.customers. The first part of the name is the remote database server name: rmtsystem. This value must correspond to an entry in the IBM i relational database directory entry that was added with the Add Relational Database Directory Entry (ADDRDBDIRE) command. The second component is the schema name, datalib, on the remote server. The final part of the three-part name is the name of the DB2 object, customer, on the remote server. Whenever an SQL statement references an object with a three-part name that resides on a different system, DB2 starts an implicit Distributed Relational Database Architecture (DRDA) connection to enable the DB2 object on the remote server to be accessed.
This initial support in 7.1 also included the ability to create an alias that points to a remote DB2 object. This provides functionality quite similar to a Distributed Data Management (DDM) file. The following set of SQL statements creates an alias and then uses the alias to retrieve data from the same remote customer table that was accessed in the previous example.
CREATE ALIAS datalib.customer FOR rmtsystem.datalib.customer
SELECT lastname, phone FROM datalib.customer
While this new 7.1 support was a great improvement, the functionality was limited by the fact that an SQL statement could only reference objects from a single IBM i system. The latest IBM i Technology Refresh for the 7.1 release lifts this restriction for INSERT statements to simplify data transfer operations involving three-part names. This new capability makes it easy for a table on your local system to be populated with data from another system, as the following INSERT statement demonstrates.
INSERT INTO locallib.customers
SELECT lastname, address, city
FROM rmtsystem.datalib.customer WHERE state='IA'
The embedded SELECT statement uses a three-part name to reference data on a remote system, and the result of that SELECT statement is inserted into the customer table on the local system. The SELECT statement also could reference an alias that points a remote DB2 object. This ability to transfer data directly into a table eliminates the need to first copy the data into some type of temporary staging area like a data structure or array.
Only IBM i 7.1 systems that have Level #14 of the Database Group PTF installed can run an INSERT statement that references DB2 objects from more than one system. The embedded SELECT statement can reference DB2 objects on IBM i systems that are running one of the following operating system versions: V5R4, 6.1, or 7.1.
LATEST COMMENTS
MC Press Online