使用Powerdesigner的逆向工程生成PDM
来源: 51CMM.COM 作者: 徐异婕
在数据建模过程中,我们建立概念数据模型,通过正向工程生成物理数据模型,生成数据库建库脚本,最后将物理数据模型生成关系数据库。系统数据库设计人员希望能够将数据库设计和关系数据库生成无缝地集成起来,如何保证物理数据模型与其对应数据库之间的双向同步成为数据建模非常关键的一点。
Powerdesigner作为强大的Case工具,为我们提供了方便的逆向工程特性。可以将目前所有流行的后端数据库(包括Sybase、 DB2、Oracle等)的结构信息通过逆向工程加入到PowerDesigner的物理数据模型和概念数据模型中,包括表、索引、触发器、视图等。
本文介绍的内容仅涉及PDM(物理数据模型)的逆向工程。
PDM中的逆向工程是指从现有DBMS的用户数据库或现有数据库SQL脚本中生成PDM的过程。逆向工程有两种对象:1)通过ODBC数据源连接数据库 2) 现有数据库sql脚本。
本文示例的系统环境如下:
1、 数据库已创建完毕,访问用户和密码设置完成。数据库为Oracle9i。
2、 ODBC数据源已由oracle 的Net Configuration Assistant 创建,本地网络命名服务“Database”。
3、 sql脚本示例crebas.sql。
4、 Powerdesigner9.5已安装完成。 一、 通过数据源连接数据库逆向工程生成PDM
1、 配置用户数据库连接参数
选择Database->configure connections,转到system dsn标签,
点击Add按钮,选数据库类型Oracle,点击完成。显示如下:输入DataSource Name“PDMTest”;输入ServerName“Database”, 配置完成。
点击“Test Connect”输入ServerName“Database”,用户名和密码,若连接成功,显示如下:
以后每次连接,选择Database?connect,选择odbc数据源,输入ServerName“Database”,用户名和密码。若无提示,则说明连接成功。同时,可以通过Database?Connection Information 查看连接信息。
2、 设置逆向工程选项,生成pdm
创建一个PDM文件,选择与之匹配的数据库类型“oracle9i”。
选择Database?Reverse Engineer Database,弹出Database Reverse Engineering对话框,选Using an ODBC data source选ODBC数据源“PDMTest”
点击确定后,显示此数据库中所有表、视图、用户。根据需要选择后,转换成pdm。
3、 查看数据
对于生成好的PDM,选择一个表图形符号,点击右键,选择View Data,就可以访问表中的数据了。
二、 通过SQL脚本逆向工程生成PDM
1、 数据库SQL脚本文件crebas.sql。下为脚本实例:
/*==============================================================*/
/* Database name: PhysicalDataModel_1 */
/* DBMS name: ORACLE Version 9i */
/* Created on: 2003-07-13 10:49:08 */
/*==============================================================*/
/*==============================================================*/
/* Table: "class" */
/*==============================================================*/
create table "class" (
"classID" NUMBER(2) not null,
"className" VARCHAR2(24),
constraint PK_CLASS primary key ("classID")
)
/
/*==============================================================*/
/* Table: "student" */
/*==============================================================*/
create table "student" (
"studentID" NUMBER(10) not null,
"studentName" VARCHAR2(4),
"classID" NUMBER(2),
constraint PK_STUDENT primary key ("studentID")
)
/
alter table "student"
add constraint FK_STUDENT_REFERENCE_CLASS foreign key ("classID")
references "class" ("classID")
/
2、 创建一个pdm,选择Database?Reverse Engineer Database,选择Using script files。
3、 看到由脚本自动生成相关的PDM如下所示:
下面是表名的中文及字段的name和comment的替换问题
PowerDesigner中name和comment互換
1 PowerDesigner中批量根据对象的name生成comment的脚本
执行方法:Open PDM -- Tools -- Execute Commands -- Run Script
Vb script代码
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl 'the current model
'get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model."
Else
ProcessFolder mdl
End If
'This routine copy name into code for each table, each column and each view
'of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
tab.comment = tab.name
Dim col 'running column
for each col in tab.columns
col.comment= col.name
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.comment = view.name
end if
next
'go into the sub-packages
Dim f 'running folder
For Each f In folder.Packages
if not f.IsShortcut then
ProcessFolder f
end if
Next
end sub
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl 'the current model
'get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model."
Else
ProcessFolder mdl
End If
'This routine copy name into code for each table, each column and each view
'of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
tab.comment = tab.name
Dim col 'running column
for each col in tab.columns
col.comment= col.name
next
end if
next
Dim view 'running view
for each view in folder.Views
if not view.isShortcut then
view.comment = view.name
end if
next
'go into the sub-packages
Dim f 'running folder
For Each f In folder.Packages
if not f.IsShortcut then
ProcessFolder f
end if
Next
end sub
2 PowerDesigner中逆向工程将数据库中comment脚本赋值到PDM的name
执行方法:Open PDM -- Tools -- Execute Commands -- Run Script
Vb script代码
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl 'the current model
'get the current active model
Set mdl = ActiveModel
If (mdl Is Nothing) Then
MsgBox "There is no current Model"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model."
Else
ProcessFolder mdl
End If
'This routine copy name into code for each table, each column and each view
'of the current folder
Private sub ProcessFolder(folder)
Dim Tab 'running table
for each Tab in folder.tables
if not tab.isShortcut then
if len(tab.comment) <> 0 then
tab.name = tab.comment
end if
On Error Resume Next
Dim col 'running column
for each col in tab.columns
if len(col.comment) <>0 then
col.name =col.comment
end if
On Error Resume Next
next
end if
next
end sub
分享到:
相关推荐
Powerdesigner逆向工程生成PDM 中文列名表名替换为注释
PowerDesigner逆向工程生成PDM模型及数据库
powerdesigner逆向工程导入mysql脚本生成PDM带全注释
PowerDesigner逆向工程导入MYSQL数据库总结 PowerDesigner逆向工程导入MYSQL数据库总结
使用Powerdesigner的逆向工程生成PDM.pdf
PowerDesigner逆向工程-Mysql,并解决没有注释的问题!
使用PowerDeSigner逆向生成Mysql数据库PDM图(带中文注释)-附件资源
POWERDESIGNER逆向工程从现有数据库生成PDM
Powerdesigner逆向工程Mysql导出表pdm Powerdesigner逆向工程Mysql导出表pdm Powerdesigner逆向工程Mysql导出表pdm
PowerDesigner16.5逆向工程显示字段备注,生成的更贴合。使用的是命令运行的方式,本人亲试,非常方便。
PowerDesigner逆向工程 PowerDesigner逆向工程 PowerDesigner逆向工程
在数据库设计中,经常使用数据库逆向工程,将数据库中库表结构转为PDM,为了阅读方便,需要将将表字段的comment转换为PDM的name。该文件解决此问题
Powerdesigner逆向工程从现有数据库生成PDM.doc
在数据建模过程中,我们建立概念数据模型,通过正向工程生成物理数据模型,生成数据库建库脚本,最后将物理数据模型生成关系数据库,现在反过来,通过逆向工程将关系数据库,生成物理数据模型。
通常数据表字段使用英文,备注comment完成字段的说明。使用该脚本能够在PowerDesigner批量生成SQL脚本时将name生成数据库中字段的comment
1 PowerDesigner逆向工程 传说中,程序员们喜欢用powerDesign进行数据库建模。通常都是先设计出物理模型图,在转换出数据库需要的SQL语句,从而生成数据库。 但,江湖中流传着“powerDesign逆向工程”的传说。好,...
在PowerDesigner里执行脚本命令,从Excel里读取表结构生成pdm文件。
如何用PowerDesigner逆向工程导出ORACLE数据库表
安装完成后需要先设置一下,解决生成的表中没有字段注释和表注释的问题: 1:点击工具栏中的数据库,选择第二个选项: 2:如图,将值替换为: {OWNER, TABLE, TNAME} select t.table_schema, t.table_name, t.table_...
当PowerDesigner连接好数据库,并生成模型后,在PowerDesigner用Ctrl+Shift+x快捷键打开,然后将脚本内容粘贴运行,就可以开始生成数据库中存在的注释了