【转载】PowerDesigner逆向工程

原文链接:

http://www.cnblogs.com/xiuyusoft/archive/2011/06/07/2074127.html

http://www.cnblogs.com/jwb_bino/archive/2009/11/12/1601869.html

http://www.cnblogs.com/luluping/archive/2010/09/19/1831075.html

Power Designer 15 数据库逆向工程

1. 破解及安装

下载地址

地址一:http://www.99d.com/down/173/486854.html

地址二:http://club.topsage.com/thread-2073507-1-1.html

1.安装Sysbase PowerDesigner 15.1。

2.拷贝pdflm15.dll到安装目录下。

3.重新启动计算机。

汉化(可选)

1.备份根目录下要汉化的文件。

2.拷贝汉化文件到安装目录下。

对于已有PD数据库文件,直接看第3步。

2. 对数据库进行反向工程

新建PDM(Physical Data Model).

1. 选择New Model(新模型),即打开创建模型选项窗口,如下图:

clip_image002

2. 选择Model types,在Model types的列表中选择Physical Data Model,最后选择Physical Diagram。在Model Name名称输入PDM的名称,DBMS选择数据库类型,选择”Share the DBMS definition。”

3. 单击”OK”,即完成PDM创建过程。

建立数据库连接

菜单”Database”à”Connect…”,弹出如下界面

clip_image004

没有ODBC数据源,则配置数据源。

(SQL2005时注意)在配置ODBC的时候,连点两个“下一步”按钮后,在第3个页面中将“更改默认的数据库为”复选框选中,并从数据库列表中选中你要Reverse的数据库,就会出现这个问题。如果取消“更改默认的数据库为”复选框的选中状态,问题解决!!!

而MSSQL2000时需要选中,而且要指定默认的数据库。

选择”ODBC machine data source”,点击”Configure”(配置过程省略)

clip_image006

对数据库进行反向工程

数据库连接建立完成后选择”Database”à”Update Model from Database…”

clip_image008

点击确定。

clip_image010

在MSSQL2005中,由于没有默认数据库,需要选择数据库。

在此对话框选择注意选择需要的视图、触发器和存储过程。

点击”OK”则对数据库进行反向工程。


个人补充:

1. PDM和CDM转换:

在【file】菜单中,从数据库或者sql脚本文件生成PDM

选择【tools】

-》选择【generate conceptual data model...】-转换为CDM

在CDM工作区时,选择菜单【tools】-》【generate physical model...】生成PDM

在PDM工作区时,选择菜单【database】-》【geerate database】生成数据库或SQL脚本文件

2. 遇到一个问题,如下:

Unable to list the users.

解决方案:

      步骤:选择菜单栏中的Database -> Change Current DBMS ,给DBMS选择Oracle Version 9i2。确定就搞定了;


3. 修改数据库信息

数据库

双击左侧的PDM,弹出如下对话框,修改数据库信息。

clip_image012

数据表

clip_image014

字段

clip_image016

设置主键(Primary)在自定义列性息中,选择Primary。

设置索引(Index)

设置关键字(Key)

clip_image018

修改字段默认值

在上图中,选择需要修改默认值的列,点击第一个小图标(Properties),在Standard Checks页中的Default输入默认值。

clip_image020

自定义列信息

在上图中,点击倒数第二个小图标(customize Column and Filter).

clip_image022

4. Report的生成环境

有2中方法生成报表,我们使用第二种方法输出报表。

新建一个报表

菜单Report--àReport…

clip_image024

点击第二个图标New Report.

clip_image026

输入报表名称,语言栏选择Simplified Chinese,点击OK,开始设计新报表。

4.如下图:我们左右2个区,Aavailable区域中选择你想要在WORD文档中展示的东东,这里我们选择List of Tables,和List of Table Columns[数据表格信息],当然你也可以加别的一些元素。

clip_image028

完成报表设计之后,保存。

在主窗口菜单选择,Report--àGenerate Report…

clip_image030

设置好相应设置,点击OK。

就生成了中文的RTF数据库设计文档了。

从报表模板中创建报表

将报表模板MyReportTemp.rtp,拷贝到安装路径下的\Resource Files\Report Templates目录下。菜单Report--àGenerate Report--àReport Template,选择报表模板,做好相应设置,点击OK。

5. 从PDM中创建和修改数据库

创建数据库

菜单Database--àGenerater Database。

clip_image032

注意问题,在Option页中,去掉User的选择框。(因为用的默认用户dbo已存在,而且不能删除)

clip_image034

修改数据库

菜单Database--àUpdate Model Change to Database…

clip_image036

选号设置,生成修改数据库脚本,执行脚本修改数据库。

6. 问题

中文报表模板输出RTF有乱码

选择中文模板,右键选择属性(Properties),在RTF Format页中的Template选择None.

PD不支持SQL Server 2005,怎么办

前两天试用PD12的时候遇到一个奇怪的事情,不知道算不算是PD12的BUG。事情的经过是这样的:

后台数据库从SQL2000升级到SQL Server 2005(简体中文版),由于PD11不支持SQL2005,所以从Sybase下载了PD12的试用版,结果发现PD12不能Reverse数据库!

PD能够作反向工程的,有两个地方,(1)File - Reverse Engineer - Database,这个功能主要用于将数据库结构反向工程为PDM设计文档,一般只用一次,以后的设计变更就直接在PDM上做了。(2)打开一个PDM之后,点击菜单Database - Reverse Engineer Database,这个功能主要是用来比较PDM文档与实际数据库之间的结构上的差异,便于两者同步。

现在数据库换成SQL2005、PD换成V12以后(Sybase网站上有两个版本,12.0和12.1,我都试了,都有相同的毛病),Reverse的时候都提示“Unable to list Tables”,不能列出SQL2005中有哪些用户表!直接后果就是无法比较PDM设计文档和SQL2005数据库的结构差异!

胖子刘

2006.10.16

====================================================================

在一个非常机缘巧合的情况下,我找到了问题的解决办法。

上面的问题是怎么产生的呢?

在配置ODBC的时候,连点两个“下一步”按钮后,在第3个页面中将“更改默认的数据库为”复选框选中,并从数据库列表中选中你要Reverse的数据库,就会出现这个问题。

如果取消“更改默认的数据库为”复选框的选中状态,问题解决!!!

同样的操作用在PD11和SQL2000环境下就没问题,所以当这对搭档升级为PD12和SQL2005之后,如果还沿用以前的习惯就会出错。不知道算不算是BUG!!!

前车之鉴,与大家共享。

胖子刘
2006.10.16

7. 其他技巧

取消name和code联动

在修改name的时候,code的值将跟着变动,很不方便。修改方法:PowerDesign中的选项菜单里修改,在[Tool]-->[General Options]->[Dialog]->[Operating modes]->[Name to Code mirroring],这里默认是让名称和代码同步,将前面的复选框去掉就行了。如图:
clip_image037

Name和Comment关联

在使用PowerDesigner对数据库进行概念模型和物理模型设计时,一般在NAME或Comment中写中文,在Code中写英文。Name用来显 示,Code在代码中使用,但Comment中的文字会保存到数据库Table或Column的Comment中,当Name已经存在的时候,再写一次 Comment很麻烦,可以使用以下代码来解决这个问题:

· 代码一:将Name中的字符COPY至Comment中

· '******************************************************************************
'*   File:           name2comment.vbs
'*   Purpose:     Database   generation   cannot   use   object   names   anymore  
'                         in   version   7   and   above.
'                         It   always   uses   the   object   codes.
'
'                         In   case   the   object   codes   are   not   aligned   with   your  
'                         object   names   in   your   model,   this   script   will   copy  
'                         the   object   Name   onto   the   object   Comment   for  
'                         the   Tables   and   Columns.
'
'*   Title:        
'*   Version:     1.0
'*   Company:     Sybase   Inc.  
'******************************************************************************

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   comment   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

--------------------------------------------


另外在使用REVERSE ENGINEER从数据库反向生成PDM的时候,PDM中的表的NAME和CODE事实上都是CODE,为了把NAME替换为数据库中Table或Column的中文Comment,可以使用以下脚本:

· 代码二:将Comment中的字符COPY至Name中

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

Private   sub   ProcessFolder(folder)
On Error Resume Next
      Dim   Tab   'running     table
      for   each   Tab   in   folder.tables
            if   not   tab.isShortcut   then
                  tab.name   =   tab.comment
                  Dim   col   '   running   column
                  for   each   col   in   tab.columns
                  if col.comment="" then
                  else
                        col.name=   col.comment
                  end if
                  next
            end   if
      next

      Dim   view   'running   view
      for   each   view   in   folder.Views
            if   not   view.isShortcut   then
                  view.name   =   view.comment
            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

-----------------------------------------------------------------------

以上两段代码都是VB脚本,在PowerDesigner中使用方法为:

    PowerDesigner->Tools->Execute Commands->Edit/Run Scripts

将代码Copy进去执行就可以了,是对整个CDM或PDM进行操作

8. 缺点

1.由于只是建模工具,不能生成默认数据。

posted on 2011-06-07 10:55 Tony Liu 阅读(1134) 评论(0) 编辑 收藏

转载于:https://www.cnblogs.com/yhlx125/articles/2657466.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值