How to create a cross-database view in DB2

Source: Internet
Author: User

This article describes how to create a cross-database view in DB2. The following describes the specific procedures for creating a cross-database view in DB2, I hope this will help you in your future studies.

Step 1: connect to the Business Database and execute this statement

 
 
  1. connect to sjsda user db2admin using pass1009;   
  2. --update dbm cfg using federated yes; 

Then restart the db2 service.

 
 
  1. --db2stop force;   
  2. --db2start;  

Step 2: execute the following statement. For example, replace "db2admin." In the following mode with other accounts.

Delete existing objects

 
 
  1. Drop wrapper drda;
  2. -- Create the wrapper ddl statement
  3. Create wrapper "DRDA"
  4. LIBRARY 'db2drda. dll'
  5. OPTIONS (DB2_FENCED 'n'
  6. );
  7. -- Create server ddl statements
  8. -- AUTHORIZATION, PASSWORD, and DBNAME must be replaced, which indicates the database of the platform.
  9. Create server tempserver
  10. TYPE DB2/UDB
  11. VERSION 8.1:
  12. WRAPPER DRDA
  13. AUTHORIZATION "User Name"
  14. PASSWORD "PASSWORD"
  15. OPTIONS
  16. (DBNAME 'testpp'
  17. );

Create user mapping ddl statements

REMOTE_AUTHID and REMOTE_PASSWORD must be replaced, indicating the platform database.

Db2admin in "FOR db2admin" will be used later. It is best to use the business database management account. FOR example, if you use another account, you 'd better replace the following "db2admin." mode.

 
 
  1. Create user mapping for db2admin
  2. SERVER tempserver
  3. OPTIONS
  4. (REMOTE_AUTHID 'username'
  5. , REMOTE_PASSWORD 'Password'
  6. );

Create DDL statements for DB2 cross-database view

View of basic user information

 
 
  1.  
  2. CREATE NICKNAME db2admin.TEMPXX_PERSON2 FOR tempserver.db2admin.TEMPXX_PERSON;   
  3. CREATE NICKNAME db2admin.TEMPXX_PERSONACCOUNT2 FOR tempserver.db2admin.TEMPXX_PERSONACCOUNT;   
  4. create view SYS_PERSON as   
  5. select db2admin.TEMPXX_PERSONACCOUNT2.PERSONUUID, db2admin.TEMPXX_PERSONACCOUNT2.FLAG, db2admin.
  6. TEMPXX_PERSONACCOUNT2.
  7. USERID, db2admin.TEMPXX_PERSONACCOUNT2.ACCOUNTSTAT, db2admin.TEMPXX_PERSONACCOUNT2.LOGINFAILNUM, 
  8. db2admin.TEMPXX_PERSONACCOUNT2.LASTLOGINIP, db2admin.TEMPXX_PERSONACCOUNT2.LASTLOGINDATE, db2admin.
  9. TEMPXX_PERSONACCOUNT2.PASSQUESTION, db2admin.TEMPXX_PERSONACCOUNT2.PASSANSWER, db2admin.TEMPXX_PERSONACCOUNT2.TTLFLAG,
  10.  db2admin.TEMPXX_PERSONACCOUNT2.ACCOUNTTTL, db2admin.TEMPXX_PERSONACCOUNT2.CREATETIME,db2admin.TEMPXX_PERSONACCOUNT2.DELTAG,   
  11. db2admin.TEMPXX_PERSON2.PERSONCODE, db2admin.TEMPXX_PERSON2.CNNAME, db2admin.TEMPXX_PERSON2.ENNAME,
  12.  db2admin.TEMPXX_PERSON2.FIRSTNAME,db2admin.TEMPXX_PERSON2.LASTNAME,db2admin.TEMPXX_PERSON2.IDNUM, 
  13. db2admin.TEMPXX_PERSON2.CARDCODE, db2admin.TEMPXX_PERSON2.SEX, db2admin.TEMPXX_PERSON2.MARRYCODE,
  14.  db2admin.TEMPXX_PERSON2.PCODE, db2admin.TEMPXX_PERSON2.HOMETEL, db2admin.TEMPXX_PERSON2.OFFICETEL, 
  15. db2admin.TEMPXX_PERSON2.HOMEFAX, db2admin.TEMPXX_PERSON2.OFFICEFAX, db2admin.TEMPXX_PERSON2.MOBILE, 
  16. db2admin.TEMPXX_PERSON2.PAGER, db2admin.TEMPXX_PERSON2.EMAIL1, db2admin.TEMPXX_PERSON2.EMAIL2, 
  17. db2admin.TEMPXX_PERSON2.COUNTRY, db2admin.TEMPXX_PERSON2.PROVINCEID, db2admin.TEMPXX_PERSON2.CITYID, 
  18. db2admin.TEMPXX_PERSON2.CONNECTADDR, db2admin.TEMPXX_PERSON2.ZIP, db2admin.TEMPXX_PERSON2.EDUCODE,
  19.  db2admin.TEMPXX_PERSON2.DEGREECODE, db2admin.TEMPXX_PERSON2.OTHERINFO,db2admin.TEMPXX_PERSON2.
  20. SEQUENCENO,db2admin.TEMPXX_PERSON2.JOB ,db2admin.TEMPXX_PERSON2.SIGNATURE   
  21. from db2admin.TEMPXX_PERSON2, db2admin.TEMPXX_PERSONACCOUNT2   
  22.  
  23. where db2admindb2admin.TEMPXX_PERSON2.PERSONUUID = db2admin.TEMPXX_PERSONACCOUNT2.PERSONUUID; 

View of organization Basic Information

 
 
  1. CREATE NICKNAME db2admin.TEMPXX_ORG2 FOR tempserver.db2admin.TEMPXX_ORG;   
  2. create view SYS_ORG as   
  3. select db2admin.TEMPXX_ORG2.ORGUUID, db2admin.TEMPXX_ORG2.CNNAME, db2admin.TEMPXX_ORG2.ENNAME,

    db2admin.TEMPXX_ORG2.ORGCODE,db2admin.TEMPXX_ORG2.CONTACT,db2admin.TEMPXX_ORG2.ORGGRADE,db2admin.

    TEMPXX_ORG2.ORGPROP,db2admin.TEMPXX_ORG2.ORGLEVEL, db2admin.TEMPXX_ORG2.SERIALINDEX, db2admin.TEMPXX_ORG2.MEMO, 

    db2admin.TEMPXX_ORG2.PARENTORGUUID, db2admin.TEMPXX_ORG2.STATUS,ORGLEVELCODE,db2admin.TEMPXX_ORG2.DELTAG,db2admin.TEMPXX_ORG2.SEQUENCENO   
  4. from db2admin.TEMPXX_ORG2;  

Ing between subsystems and organizations

 
 
  1. CREATE NICKNAME db2admin.TEMPXX_SYSORGSHORTCUT2 FOR tempserver.db2admin.TEMPXX_SYSORGSHORTCUT;   
  2. CREATE NICKNAME db2admin.TEMPXX_SYSTEM2 FOR tempserver.db2admin.TEMPXX_SYSTEM;   
  3. create view SYS_ORGSUBSYSREL as   
  4. select db2admin.TEMPXX_SYSORGSHORTCUT2.SYSID, db2admin.TEMPXX_SYSORGSHORTCUT2.  
  5. ORGUUID ,db2admin.TEMPXX_ORG2.CNNAME ,db2admin.  
  6. TEMPXX_SYSTEM2.SYSNAME,db2admin.TEMPXX_SYSTEM2.SYSPROP   
  7. from db2admin.TEMPXX_SYSORGSHORTCUT2,db2admin.TEMPXX_SYSTEM2,db2admin.TEMPXX_ORG2   
  8. where db2admindb2admin.TEMPXX_SYSORGSHORTCUT2.SYSID = db2admin.TEMPXX_SYSTEM2.SYSID and 

    db2admindb2admin.TEMPXX_SYSORGSHORTCUT2.ORGUUID = db2admin.TEMPXX_ORG2.ORGUUID;   

User-organization ing View

 
 
  1. CREATE NICKNAME db2admin.TEMPXX_ORGPERSON2 FOR tempserver.db2admin.TEMPXX_ORGPERSON;   
  2. create view SYS_ORGPERSON as   
  3. select db2admin.TEMPXX_ORGPERSON2.PERSONUUID,db2admin.TEMPXX_ORGPERSON2.ORGUUID,  
  4. db2admin.TEMPXX_ORGPERSON2.ISBELONG from db2admin.TEMPXX_ORGPERSON2;   

User-system role ing View

 
 
  1. CREATE NICKNAME db2admin.TEMPXX_RIGHTSHORTCUT2 FOR tempserver.db2admin.TEMPXX_RIGHTSHORTCUT;   
  2. CREATE NICKNAME db2admin.TEMPXX_ROLE2 FOR tempserver.db2admin.TEMPXX_ROLE;   
  3. CREATE NICKNAME db2admin.TEMPXX_ROLEDISABLE2 FOR tempserver.db2admin.TEMPXX_ROLEDISABLE;   
  4. create view SYS_RIGHTSHORTCUT as   
  5. select db2admin.TEMPXX_RIGHTSHORTCUT2.PERSONUUID, db2admin.TEMPXX_RIGHTSHORTCUT2.ROLEID,   
  6. db2admin.TEMPXX_ROLE2.SYSID ,db2admin.TEMPXX_ROLE2.CNNAMEfrom db2admin.TEMPXX_RIGHTSHORTCUT2,db2admin.
  7. TEMPXX_ROLE2 where db2admindb2admin.TEMPXX_RIGHTSHORTCUT2.ROLEID = db2admin.TEMPXX_ROLE2.ROLEID   
  8. except   
  9. select db2admin.TEMPXX_ROLEDISABLE2.PERSONUUID,db2admin.TEMPXX_ROLEDISABLE2.ROLEID, db2admin.TEMPXX_ROLEDISABLE2.SYSID ,
  10. db2admin.TEMPXX_ROLE2.CNNAME from db2admin.  
  11. TEMPXX_ROLEDISABLE2,db2admin.TEMPXX_ROLE2 where db2admindb2admin.TEMPXX_ROLEDISABLE2.ROLEID = db2admin.TEMPXX_ROLE2.ROLEID;   

User-application role ing View

 
 
  1. create view SYS_APPROLE_PERSON as   
  2. select distinct db2admin.TEMPXX_RIGHTSHORTCUT2.PERSONUUID, db2admin.TEMPXX_PERSON2.
  3. CNNAME as PERSONNAME,db2admin.TEMPXX_ROLE2.CNNAME as ROLENAME,db2admin.TEMPXX_ROLE2.
  4. ROLECODE from db2admin.TEMPXX_RIGHTSHORTCUT2,db2admin.TEMPXX_ROLE2,db2admin.
  5. TEMPXX_PERSON2 where db2admindb2admin.TEMPXX_RIGHTSHORTCUT2.ROLEID = db2admin.TEMPXX_ROLE2.ROLEID and 
  6. db2admindb2admin.TEMPXX_RIGHTSHORTCUT2.PERSONUUID = db2admin.TEMPXX_PERSON2.PERSONUUID and TEMPXX_ROLE2.CREATEBY = '1'   
  7. except   
  8. select distinct db2admin.TEMPXX_ROLEDISABLE2.PERSONUUID, db2admin.TEMPXX_PERSON2.
  9. CNNAME as PERSONNAME,db2admin.TEMPXX_ROLE2.CNNAME as ROLENAME,db2admin.TEMPXX_ROLE2.
  10. ROLECODE from db2admin.TEMPXX_ROLEDISABLE2,db2admin.TEMPXX_ROLE2,db2admin.
  11. TEMPXX_PERSON2 where db2admindb2admin.TEMPXX_ROLEDISABLE2.ROLEID = db2admin.
  12. TEMPXX_ROLE2.ROLEID and db2admindb2admin.TEMPXX_ROLEDISABLE2.PERSONUUID = db2admin.TEMPXX_PERSON2.
  13. PERSONUUID and TEMPXX_ROLE2.CREATEBY = '1';   

The above content is an introduction to creating a cross-database view for DB2. I hope you will find some gains.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.