PowerDesigner的基本使用


数据库模型

  通过PowerDesigner建立数据库模型,生成sql语句以后,去数据库执行即可建表。

1、New Model

以下两种都可以
在这里插入图片描述

2、创建数据库模型

  New Model以后出现以下窗口,按照1-2-3操作即可
在这里插入图片描述

3、创建表

  • 建表
      点击图示后,鼠标变为表格图示,空白处点击后创建一张表,相当于数据库的表。
    在这里插入图片描述
  • 编辑表
      点击后创建的表如下图示,在palette选择鼠标箭头,双击该表就能编辑。
    在这里插入图片描述
  • 设置名称
    在这里插入图片描述
  • 编辑列
    在这里插入图片描述
    在这里插入图片描述
  • 主键自增
    在这里插入图片描述
  • 关联主外键
    点击palette,选择如图所示标志,然后关联起来,直接拉就可以
    在这里插入图片描述
    双击这个箭头,可以看到父表子表关联完成,然后指定他们的关联字段。
    在这里插入图片描述
    可以看到关联的字段已经设定好
    在这里插入图片描述

4、导出为sql语句

导出全部表

在这里插入图片描述
选择好直接确定,就是导出所有表

导出指定表

在上步的基础上,选择selection,找到大的模块,然后选择tables,然后选中要导出的某张表
在这里插入图片描述

5、运行测试

打开数据库,运行生成的sql文件,成功
在这里插入图片描述

导出为EXCEL

导出所有表

  1. tools-execute commands-edit/run script
    在这里插入图片描述
    然后在窗口中粘贴代码点RUN执行
    在这里插入图片描述
    执行完毕所有表将会生成在同一个EXCEL表格
  2. 粘贴代码
'******************************************************************************
Option Explicit
   Dim rowsNum
   rowsNum = 0
'-----------------------------------------------------------------------------
' Main function
'-----------------------------------------------------------------------------
' Get the current active model
    Dim Model
    Set Model = ActiveModel
    If (Model Is Nothing) Or (Not Model.IsKindOf(PdPDM.cls_Model)) Then
       MsgBox "The current model is not an PDM model."
    Else
      ' Get the tables collection
      '创建EXCEL APP
      dim beginrow
      DIM EXCEL, SHEET, SHEETLIST
      set EXCEL = CREATEOBJECT("Excel.Application")
      EXCEL.workbooks.add(-4167)'添加工作表
      EXCEL.workbooks(1).sheets(1).name ="表结构"
      set SHEET = EXCEL.workbooks(1).sheets("表结构")
      
      EXCEL.workbooks(1).sheets.add
      EXCEL.workbooks(1).sheets(1).name ="目录"
      set SHEETLIST = EXCEL.workbooks(1).sheets("目录")
      ShowTableList Model,SHEETLIST

      ShowProperties Model, SHEET,SHEETLIST
      
      
      EXCEL.workbooks(1).Sheets(2).Select
      EXCEL.visible = true
      '设置列宽和自动换行
      sheet.Columns(1).ColumnWidth = 20 
      sheet.Columns(2).ColumnWidth = 20 
      sheet.Columns(3).ColumnWidth = 20 
      sheet.Columns(4).ColumnWidth = 40 
      sheet.Columns(5).ColumnWidth = 10 
      sheet.Columns(6).ColumnWidth = 10 
      sheet.Columns(1).WrapText =true
      sheet.Columns(2).WrapText =true
      sheet.Columns(4).WrapText =true
      '不显示网格线
      EXCEL.ActiveWindow.DisplayGridlines = False
      
      
 End If
'-----------------------------------------------------------------------------
' Show properties of tables
'-----------------------------------------------------------------------------
Sub ShowProperties(mdl, sheet,SheetList)
   ' Show tables of the current model/package
   rowsNum=0
   beginrow = rowsNum+1
   Dim rowIndex 
   rowIndex=3
   ' For each table
   output "begin"
   Dim tab
   For Each tab In mdl.tables
      ShowTable tab,sheet,rowIndex,sheetList
      rowIndex = rowIndex +1
   Next
   if mdl.tables.count > 0 then
        sheet.Range("A" & beginrow + 1 & ":A" & rowsNum).Rows.Group
   end if
   output "end"
End Sub
'-----------------------------------------------------------------------------
' Show table properties
'-----------------------------------------------------------------------------
Sub ShowTable(tab, sheet,rowIndex,sheetList)
   If IsObject(tab) Then
     Dim rangFlag
     rowsNum = rowsNum + 1
      ' Show properties
      Output "================================"
      sheet.cells(rowsNum, 1) =tab.name
      sheet.cells(rowsNum, 1).HorizontalAlignment=3
      sheet.cells(rowsNum, 2) = tab.code
      'sheet.cells(rowsNum, 5).HorizontalAlignment=3
      'sheet.cells(rowsNum, 6) = ""
      'sheet.cells(rowsNum, 7) = "表说明"
      sheet.cells(rowsNum, 3) = tab.comment
      'sheet.cells(rowsNum, 8).HorizontalAlignment=3
      sheet.Range(sheet.cells(rowsNum, 3),sheet.cells(rowsNum, 7)).Merge
      '设置超链接,从目录点击表名去查看表结构
      '字段中文名    字段英文名    字段类型    注释    是否主键    是否非空    默认值
      sheetList.Hyperlinks.Add sheetList.cells(rowIndex,2), "","表结构"&"!B"&rowsNum
      rowsNum = rowsNum + 1
      sheet.cells(rowsNum, 1) = "字段中文名"
      sheet.cells(rowsNum, 2) = "字段英文名"
      sheet.cells(rowsNum, 3) = "字段类型"
      sheet.cells(rowsNum, 4) = "注释"
      sheet.cells(rowsNum, 5) = "是否主键"
      sheet.cells(rowsNum, 6) = "是否非空"
      sheet.cells(rowsNum, 7) = "默认值"
      '设置边框
      sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 7)).Borders.LineStyle = "1"
      'sheet.Range(sheet.cells(rowsNum-1, 4),sheet.cells(rowsNum, 9)).Borders.LineStyle = "1"
      '字体为10sheet.Range(sheet.cells(rowsNum-1, 1),sheet.cells(rowsNum, 7)).Font.Size=10
            Dim col ' running column
            Dim colsNum
            colsNum = 0
      for each col in tab.columns
        rowsNum = rowsNum + 1
        colsNum = colsNum + 1
          sheet.cells(rowsNum, 1) = col.name
        'sheet.cells(rowsNum, 3) = ""
          'sheet.cells(rowsNum, 4) = col.name
          sheet.cells(rowsNum, 2) = col.code
          sheet.cells(rowsNum, 3) = col.datatype
        sheet.cells(rowsNum, 4) = col.comment
          If col.Primary = true Then
        sheet.cells(rowsNum, 5) = "Y" 
        Else
        sheet.cells(rowsNum, 5) = " " 
        End If
        If col.Mandatory = true Then
        sheet.cells(rowsNum, 6) = "Y" 
        Else
        sheet.cells(rowsNum, 6) = " " 
        End If
        sheet.cells(rowsNum, 7) =  col.defaultvalue
      next
      sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,7)).Borders.LineStyle = "3"       
      'sheet.Range(sheet.cells(rowsNum-colsNum+1,4),sheet.cells(rowsNum,9)).Borders.LineStyle = "3"
      sheet.Range(sheet.cells(rowsNum-colsNum+1,1),sheet.cells(rowsNum,7)).Font.Size = 10
      rowsNum = rowsNum + 2
      
      Output "FullDescription: "       + tab.Name
   End If
   
End Sub
'-----------------------------------------------------------------------------
' Show List Of Table
'-----------------------------------------------------------------------------
Sub ShowTableList(mdl, SheetList)
   ' Show tables of the current model/package
   Dim rowsNo
   rowsNo=1
   ' For each table
   output "begin"
   SheetList.cells(rowsNo, 1) = "主题"
   SheetList.cells(rowsNo, 2) = "表中文名"
   SheetList.cells(rowsNo, 3) = "表英文名"
   SheetList.cells(rowsNo, 4) = "表说明"
   rowsNo = rowsNo + 1
   SheetList.cells(rowsNo, 1) = mdl.name
   Dim tab
   For Each tab In mdl.tables
     If IsObject(tab) Then
         rowsNo = rowsNo + 1
      SheetList.cells(rowsNo, 1) = ""
      SheetList.cells(rowsNo, 2) = tab.name
      SheetList.cells(rowsNo, 3) = tab.code
      SheetList.cells(rowsNo, 4) = tab.comment
     End If
   Next
    SheetList.Columns(1).ColumnWidth = 20 
      SheetList.Columns(2).ColumnWidth = 20 
      SheetList.Columns(3).ColumnWidth = 30 
     SheetList.Columns(4).ColumnWidth = 60 
   output "end"
End Sub

导出单张表

在这里插入图片描述

将name自动填充到注释(comment)

'把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

comment赋值到name

'代码二:将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

设置导出SQL的编码

在这里插入图片描述

检查设计的表有没有问题

在这里插入图片描述
在这里插入图片描述

导入sql生成模型

在这里插入图片描述
2.
选好数据库类型点击确定
在这里插入图片描述
3.
选择要导入的sql,可多选,选好点确定就生成了
在这里插入图片描述

改变name时code跟着改变

菜单栏ToolsGeneral Options
选中Name to Code mirroring是name跟着code改变,不选中是不跟着改变
在这里插入图片描述
在这里插入图片描述

导入excel为model

x1.Workbooks.Open “C:\Users\w4523\Desktop\数据管控\工作表.xlsx”
x1.Workbooks(1).Worksheets(“Sheet1”).Activate
这里设置excel路径和sheet位置

Option Explicit   
Dim mdl ' the current model 
Set mdl = ActiveModel 
If (mdl Is Nothing) Then   
  MsgBox "There is no Active Model" 
End If 
  
Dim HaveExcel 
Dim RQ  
RQ = vbYes 'MsgBox("Is Excel Installed on your machine ?", vbYesNo + vbInformation, "Confirmation") 
If RQ = vbYes Then  
   HaveExcel = True  
' Open & Create Excel Document 
 Dim x1 '  
  Set x1 = CreateObject("Excel.Application")
  x1.Workbooks.Open "C:\Users\w4523\Desktop\数据管控\工作表.xlsx" 
  x1.Workbooks(1).Worksheets("Sheet1").Activate 
Else
   HaveExcel = False 
End If 
  
a x1, mdl 
  
sub a(x1,mdl) 
dim rwIndex 
dim tableName 
dim colname 
dim table 
dim col 
dim count 
  
'on error Resume Next 
For rwIndex = 1 To 1000 step 1   
    With x1.Workbooks(1).Worksheets("Sheet1")
  'MsgBox "生成数据表结构共计1 ="+CStr(.Cells(2,2).Value ), vbOK + vbInformation, "表" 
   If .Cells(rwIndex, 1).Value = "" Then 
       Exit For 
   End If  
  If .Cells(rwIndex, 3).Value = "" Then 
    set table = mdl.Tables.CreateNew 
        table.Name = .Cells(rwIndex , 1).Value 
        table.Code = .Cells(rwIndex , 2).Value 
        count = count + 1  
   Else   
    colName = .Cells(rwIndex, 1).Value 
    set col = table.Columns.CreateNew  
   'MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列" 
    col.Name = .Cells(rwIndex, 1).Value 
    'MsgBox col.Name, vbOK + vbInformation, "列"
     col.Code = .Cells(rwIndex, 2).Value 
    col.Comment = .Cells(rwIndex,3).Value  
    col.DataType = .Cells(rwIndex, 4).Value 
   End If 
  End With 
Next 
  
MsgBox "生成数据表结构共计" + CStr(count), vbOK + vbInformation, "表" 
 
Exit Sub 
End sub

excel格式如下在这里插入图片描述

查找

查找的时候默认是全匹配,就是得一模一样,可以用*模糊查询在这里插入图片描述

PowerDesigner是一种建模工具,用于设计和管理软件系统。它有一个整体的框架,可以帮助开发人员更好地理解和使用该工具。 首先,PowerDesigner是一个功能强大的工具,可以帮助开发人员进行数据建模、业务流程建模、应用程序设计等任务。它提供了丰富的功能和工具,可以帮助用户快速创建和管理各种模型。 在使用PowerDesigner之前,我们需要了解它的整体框架和基本概念。PowerDesigner中的主要概念包括模型、图表、对象和库。模型是一个概念上的容器,可以包含多个图表和对象。图表是用来展示模型中的对象和它们之间的关系的图形表示。对象是模型中的具体元素,如表、类、过程等。库是PowerDesigner中用来存储和管理对象的地方,可以将项目中的所有对象存储到PowerDesigner库中,以便后续使用和管理。 了解PowerDesigner的整体框架后,我们可以开始学习如何使用该工具。有很多资源可以帮助我们学习PowerDesigner使用方法。例如,可以参考引用中提到的通过图例了解PowerDesigner使用方法的文档。这份文档详细介绍了PowerDesigner使用方法,并通过示例代码提供了实际操作的指导和参考。 在使用PowerDesigner时,我们可以按照以下步骤进行: 1. 创建项目:在PowerDesigner中创建一个项目,并为该项目选择合适的模型类型和选项。 2. 创建模型:在项目中创建一个新的模型,并选择适当的模型类型,如数据模型、业务流程模型等。 3. 添加对象:在模型中添加需要的对象,如表、类、过程等。可以使用PowerDesigner提供的工具和功能来创建和编辑这些对象。 4. 建立关系:在对象之间建立关联关系,如表之间的关联、类之间的继承关系等。PowerDesigner提供了丰富的工具和功能来帮助用户建立和管理这些关系。 5. 生成文档:可以使用PowerDesigner生成各种文档,如数据字典、类图等,以便与团队成员共享和交流。 总之,PowerDesigner是一个功能强大的建模工具,通过了解其整体框架和使用方法,我们可以更好地利用该工具进行软件系统设计和管理。可以参考引用中的文档来深入学习和掌握PowerDesigner使用方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [PowerDesigner使用](https://blog.csdn.net/qq_31653405/article/details/123894670)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [通过图例了解PowerDesigner使用方法](https://download.csdn.net/download/weixin_38613681/12742615)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值