从数据库生成PD 并且设置数据库字段说明对应PD的NAME属性

本文介绍如何在PowerDesigner中实现数据模型中元素的NAME字段与COMMENT字段之间的相互转换,包括具体的步骤与VBS脚本示例。

1:file->reverser engineer-->database




这里说明下

Share:   Use   the   shared   DBMS   definiation
Copy   :   create   a   copy   of   dbms   definition   in   model

pd对于每个它所支持的DBMS都有一个定义文件(xml),这里包含了,诸如,关键字,数据类型,如何读取
元数据的sql等.并作为资源文件存放
C:\Program   Files\Sybase\PowerDesigner   Trial   11\Resource   Files\DBMS
根据你的项目需要,需要修改这个定义文件时你应该copy一个,作为你这个项目专用的.
否则,你在share模式下所做的修改将会影响以后项目所使用的定义文件.


2:点击确定

3:点击按钮 

4:出现界面 这个选


5:点击按钮 出现新页面 点击 添加数据库





剩下的就是 确定 一路点下去了


PowerDesigner中NAME和COMMENT的互相转换,需要执行语句

使用说明: 在【Tools】-【Execute Commands】-【Edit/Run Script】 下。输入下面你要选择的语句即可,也可以保存起来,以便下次使用,后缀为.vbs。

 需要注意的问题是:运行语句时必须在Module模式下,如果是导出报表时执行会出现错误提示。

1.Name转到Comment注释字段。一般情况下只填写NAME,COMMENT可以运行语句自动生成。

将该语句保存为name2comment.vbs

代码

代码

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->'把pd中那么name想自动添加到comment里面
'如果comment为空,则填入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

'   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
          if  trim(tab.comment)="" then'如果有表的注释,则不改变它.如果没有表注释.则把name添加到注释里面.   
                    tab.comment   =   tab.name   
          end if  
                  Dim   col   '   running   column    
                  for   each   col   in   tab.columns   
                        if trim(col.comment)="" then '如果col的comment为空,则填入name,如果已有注释,则不添加;这样可以避免已有注释丢失.
                           col.comment=   col.name   
                        end if
                  next    
            end   if    
      next    
 
      Dim   view   'running   view    
      for   each   view   in   folder.Views    
            if   not   view.isShortcut and trim(view.comment)=""  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.将Comment内容保存到NAME中,comment2name.vbs 实习互换。语句为:

 

代码

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->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

 


### 使用 PowerDesigner 自动生成 MySQL 数据库模型的设计工具教程 #### 1. 创建新的物理数据模型 (PDM) 在 PowerDesigner 中创建一个新的物理数据模型 (PDM),这是生成 MySQL 数据库的基础步骤。具体操作为: 打开 PowerDesigner 软件,点击菜单栏中的 **File -> New Model**,随后选择 **Model Types -> Physical Data Model** 并命名该模型文件[^2]。 #### 2. 设置目标数据库类型 为了确保 PDM 的设计能够适配 MySQL 数据库,在新建模型时需指定目标 RDBMS 类型。这一步骤可以通过以下方式完成: - 右键单击空白区域并选择 **Properties**。 - 在弹出窗口中找到 **Default Column Properties** 和 **RDBMS Type** 部分,将其设置为 **MySQL**[^3]。 #### 3. 设计实体关系图 (ERD) 利用 PowerDesigner 提供的功能绘制 ER 图形化界面,定义各个表及其字段属性、主外键约束等内容。此过程可以手动输入或者借助已有文档快速构建[^4]。 #### 4. 导出 SQL 脚本至 MySQL 当完成了整个数据库设计方案后,可通过内置功能直接导出对应的 DDL (Data Definition Language)脚本来实现自动化部署工作流: ```sql -- Example of Generated SQL Script from PowerDesigner to MySQL CREATE TABLE `example_table` ( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(50), PRIMARY KEY (`id`) ); ``` 上述代码片段展示了由 PowerDesigner 自动生成的一个简单表格定义样例。 #### 5. 利用逆向工程技术优化现有数据库结构 如果已经存在一个实际运行中的 MySQL 实例,则可采用 Reverse Engineering 技术加载其元信息回 PowerDesigner 进行进一步调整和完善。按照官方指南执行相应命令即可轻松达成目的[^1]。 ---
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值