Thursday 31 May 2018

DB2 Federation between two DB2 databases on same instance

Step 1:
 
Go to db2 prompt
 
db2=>

Step 2: (Optional) Create database if necessary
 
create database Tom
 
create database Jerry
Step 3: Connect to DB1 and create table (Example Tom) (Optional)
 
connect to tom
 
create table db2inst1.tab1 (cod1 int)
 
insert into db2inst1.tab1 values (1)

Step 4: Connect to DB2 and create table (Example Jerry)
 
connect to jerry
 
create table db2inst1.tab2 (name1 char)
 
insert into db2inst1.tab2 values ('a')

Step 5: Create server and mappings in 1st DB (Tom) to access 2nd DB (Jerry)
connect to tom
 

create server fedserver TYPE DB2/UDB VERSION 10.5 WRAPPER drda  AUTHORIZATION "db2inst1" password "password" OPTIONS(DBNAME 'jerry')
 
create user mapping for db2inst1 SERVER fedserver OPTIONS(REMOTE_AUTHID 'db2inst1',REMOTE_PASSWORD 'password')
create nickname mytable for fedserver.db2inst1.tab1

Step 6: 

Executing Select statement from 1st Db (Tom) to query results from 2nd DB (Jerry)
 
select * from mytable

--
Regards
Sandeep C