本文主要介绍的是有关DB2创建跨库视图的实际操作方法,以下就是对DB2数据库创建跨库视图的实际操作流程的具体方案的描述,希望在你今后的学习中会有所帮助。
第一步:连接业务库后执行该语句
- connect to sjsda user db2admin using pass1009;
- --update dbm cfg using federated yes;
然后重新启动 db2 服务
- --db2stop force;
- --db2start;
第二步:执行以下语句,如以别的账号,把下面的模式“db2admin.”都换掉
删除原有各对象
- drop wrapper drda;
- -- 创建WRAPPER 的 DDL 语句
- CREATE WRAPPER "DRDA"
- LIBRARY 'db2drda.dll'
- OPTIONS (DB2_FENCED 'N'
- );
- -- 创建SERVER 的 DDL 语句
- -- 需替换AUTHORIZATION,PASSWORD,DBNAME,指平台的数据库
- CREATE SERVER tempserver
- TYPE DB2/UDB
- VERSION 8.1
- WRAPPER DRDA
- AUTHORIZATION "用户名"
- PASSWORD "密码"
- OPTIONS
- (DBNAME 'TESTPP'
- );
创建USER MAPPING 的 DDL 语句
需替换REMOTE_AUTHID,REMOTE_PASSWORD,指平台的数据库
"FOR db2admin "中的db2admin 在后面都会用到,最好是业务数据库管理账号,如以别的账号,最好把下面的模式“db2admin.”也都换掉
- CREATE USER MAPPING FOR db2admin
- SERVER tempserver
- OPTIONS
- (REMOTE_AUTHID '用户名'
- ,REMOTE_PASSWORD '密码'
- );
创建DB2跨库视图的 DDL 语句
用户基本信息的视图
- CREATE NICKNAME db2admin.TEMPXX_PERSON2 FOR tempserver.db2admin.TEMPXX_PERSON;
- CREATE NICKNAME db2admin.TEMPXX_PERSONACCOUNT2 FOR tempserver.db2admin.TEMPXX_PERSONACCOUNT;
- create view SYS_PERSON as
- select db2admin.TEMPXX_PERSONACCOUNT2.PERSONUUID, db2admin.TEMPXX_PERSONACCOUNT2.FLAG, db2admin.
- TEMPXX_PERSONACCOUNT2.
- USERID, db2admin.TEMPXX_PERSONACCOUNT2.ACCOUNTSTAT, db2admin.TEMPXX_PERSONACCOUNT2.LOGINFAILNUM,
- db2admin.TEMPXX_PERSONACCOUNT2.LASTLOGINIP, db2admin.TEMPXX_PERSONACCOUNT2.LASTLOGINDATE, db2admin.
- TEMPXX_PERSONACCOUNT2.PASSQUESTION, db2admin.TEMPXX_PERSONACCOUNT2.PASSANSWER, db2admin.TEMPXX_PERSONACCOUNT2.TTLFLAG,
- db2admin.TEMPXX_PERSONACCOUNT2.ACCOUNTTTL, db2admin.TEMPXX_PERSONACCOUNT2.CREATETIME,db2admin.TEMPXX_PERSONACCOUNT2.DELTAG,
- db2admin.TEMPXX_PERSON2.PERSONCODE, db2admin.TEMPXX_PERSON2.CNNAME, db2admin.TEMPXX_PERSON2.ENNAME,
- db2admin.TEMPXX_PERSON2.FIRSTNAME,db2admin.TEMPXX_PERSON2.LASTNAME,db2admin.TEMPXX_PERSON2.IDNUM,
- db2admin.TEMPXX_PERSON2.CARDCODE, db2admin.TEMPXX_PERSON2.SEX, db2admin.TEMPXX_PERSON2.MARRYCODE,
- db2admin.TEMPXX_PERSON2.PCODE, db2admin.TEMPXX_PERSON2.HOMETEL, db2admin.TEMPXX_PERSON2.OFFICETEL,
- db2admin.TEMPXX_PERSON2.HOMEFAX, db2admin.TEMPXX_PERSON2.OFFICEFAX, db2admin.TEMPXX_PERSON2.MOBILE,
- db2admin.TEMPXX_PERSON2.PAGER, db2admin.TEMPXX_PERSON2.EMAIL1, db2admin.TEMPXX_PERSON2.EMAIL2,
- db2admin.TEMPXX_PERSON2.COUNTRY, db2admin.TEMPXX_PERSON2.PROVINCEID, db2admin.TEMPXX_PERSON2.CITYID,
- db2admin.TEMPXX_PERSON2.CONNECTADDR, db2admin.TEMPXX_PERSON2.ZIP, db2admin.TEMPXX_PERSON2.EDUCODE,
- db2admin.TEMPXX_PERSON2.DEGREECODE, db2admin.TEMPXX_PERSON2.OTHERINFO,db2admin.TEMPXX_PERSON2.
- SEQUENCENO,db2admin.TEMPXX_PERSON2.JOB ,db2admin.TEMPXX_PERSON2.SIGNATURE
- from db2admin.TEMPXX_PERSON2, db2admin.TEMPXX_PERSONACCOUNT2
- where db2admindb2admin.TEMPXX_PERSON2.PERSONUUID = db2admin.TEMPXX_PERSONACCOUNT2.PERSONUUID;
组织基本信息的视图
- CREATE NICKNAME db2admin.TEMPXX_ORG2 FOR tempserver.db2admin.TEMPXX_ORG;
- create view SYS_ORG as
- 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
- from db2admin.TEMPXX_ORG2;
子系统和组织的映射关系视图
- CREATE NICKNAME db2admin.TEMPXX_SYSORGSHORTCUT2 FOR tempserver.db2admin.TEMPXX_SYSORGSHORTCUT;
- CREATE NICKNAME db2admin.TEMPXX_SYSTEM2 FOR tempserver.db2admin.TEMPXX_SYSTEM;
- create view SYS_ORGSUBSYSREL as
- select db2admin.TEMPXX_SYSORGSHORTCUT2.SYSID, db2admin.TEMPXX_SYSORGSHORTCUT2.
- ORGUUID ,db2admin.TEMPXX_ORG2.CNNAME ,db2admin.
- TEMPXX_SYSTEM2.SYSNAME,db2admin.TEMPXX_SYSTEM2.SYSPROP
- from db2admin.TEMPXX_SYSORGSHORTCUT2,db2admin.TEMPXX_SYSTEM2,db2admin.TEMPXX_ORG2
- where db2admindb2admin.TEMPXX_SYSORGSHORTCUT2.SYSID = db2admin.TEMPXX_SYSTEM2.SYSID and
db2admindb2admin.TEMPXX_SYSORGSHORTCUT2.ORGUUID = db2admin.TEMPXX_ORG2.ORGUUID;
用户和组织的映射关系视图
- CREATE NICKNAME db2admin.TEMPXX_ORGPERSON2 FOR tempserver.db2admin.TEMPXX_ORGPERSON;
- create view SYS_ORGPERSON as
- select db2admin.TEMPXX_ORGPERSON2.PERSONUUID,db2admin.TEMPXX_ORGPERSON2.ORGUUID,
- db2admin.TEMPXX_ORGPERSON2.ISBELONG from db2admin.TEMPXX_ORGPERSON2;
用户和系统角色的映射关系视图
- CREATE NICKNAME db2admin.TEMPXX_RIGHTSHORTCUT2 FOR tempserver.db2admin.TEMPXX_RIGHTSHORTCUT;
- CREATE NICKNAME db2admin.TEMPXX_ROLE2 FOR tempserver.db2admin.TEMPXX_ROLE;
- CREATE NICKNAME db2admin.TEMPXX_ROLEDISABLE2 FOR tempserver.db2admin.TEMPXX_ROLEDISABLE;
- create view SYS_RIGHTSHORTCUT as
- select db2admin.TEMPXX_RIGHTSHORTCUT2.PERSONUUID, db2admin.TEMPXX_RIGHTSHORTCUT2.ROLEID,
- db2admin.TEMPXX_ROLE2.SYSID ,db2admin.TEMPXX_ROLE2.CNNAMEfrom db2admin.TEMPXX_RIGHTSHORTCUT2,db2admin.
- TEMPXX_ROLE2 where db2admindb2admin.TEMPXX_RIGHTSHORTCUT2.ROLEID = db2admin.TEMPXX_ROLE2.ROLEID
- except
- select db2admin.TEMPXX_ROLEDISABLE2.PERSONUUID,db2admin.TEMPXX_ROLEDISABLE2.ROLEID, db2admin.TEMPXX_ROLEDISABLE2.SYSID ,
- db2admin.TEMPXX_ROLE2.CNNAME from db2admin.
- TEMPXX_ROLEDISABLE2,db2admin.TEMPXX_ROLE2 where db2admindb2admin.TEMPXX_ROLEDISABLE2.ROLEID = db2admin.TEMPXX_ROLE2.ROLEID;
用户和应用角色的映射关系视图
- create view SYS_APPROLE_PERSON as
- select distinct db2admin.TEMPXX_RIGHTSHORTCUT2.PERSONUUID, db2admin.TEMPXX_PERSON2.
- CNNAME as PERSONNAME,db2admin.TEMPXX_ROLE2.CNNAME as ROLENAME,db2admin.TEMPXX_ROLE2.
- ROLECODE from db2admin.TEMPXX_RIGHTSHORTCUT2,db2admin.TEMPXX_ROLE2,db2admin.
- TEMPXX_PERSON2 where db2admindb2admin.TEMPXX_RIGHTSHORTCUT2.ROLEID = db2admin.TEMPXX_ROLE2.ROLEID and
- db2admindb2admin.TEMPXX_RIGHTSHORTCUT2.PERSONUUID = db2admin.TEMPXX_PERSON2.PERSONUUID and TEMPXX_ROLE2.CREATEBY = '1'
- except
- select distinct db2admin.TEMPXX_ROLEDISABLE2.PERSONUUID, db2admin.TEMPXX_PERSON2.
- CNNAME as PERSONNAME,db2admin.TEMPXX_ROLE2.CNNAME as ROLENAME,db2admin.TEMPXX_ROLE2.
- ROLECODE from db2admin.TEMPXX_ROLEDISABLE2,db2admin.TEMPXX_ROLE2,db2admin.
- TEMPXX_PERSON2 where db2admindb2admin.TEMPXX_ROLEDISABLE2.ROLEID = db2admin.
- TEMPXX_ROLE2.ROLEID and db2admindb2admin.TEMPXX_ROLEDISABLE2.PERSONUUID = db2admin.TEMPXX_PERSON2.
- PERSONUUID and TEMPXX_ROLE2.CREATEBY = '1';
以上的相关内容就是对DB2创建跨库视图的介绍,望你能有所收获。
【编辑推荐】