在Powerdesigner或者ER/Studio中使用宏把Attribute复制到Definition

在处理ER/Studio生成SQL脚本时发现,如果在Definition处没有定义,那么在生成SQL脚本后就没有表和字段的注释。

解决办法:添加一个宏,Tools-->Basic Macro Editor,录入代码:  

保存为Attribute2Definition.BAS文件,路径不要改。

使用时:右键-->Add/Remove Macro shortcuts ,选择Attribute2Definition,添加到右边列表中。再右键-->Macros-->Attribute2Definition执行即可。

 

Dim EntCount As Integer
Dim ColCount As Integer
Dim MyDiagram As Diagram
Dim MyModel As Model
Dim MyEntity As Entity
Dim MyAttribute As AttributeObj
Dim TableArray() As String
Dim ColArray() As String
Function getColumns(TableName As String )
Dim Indx As Integer
Dim count As Integer
count =1
Indx =0
Set MyEntity = MyModel.Entities.Item(TableName)
ColCount = MyEntity.Attributes.Count
ReDim ColArray(0To ColCount) As String
For count=1 To ColCount
  For Each MyAttribute In MyEntity.Attributes
    If MyAttribute.SequenceNumber = count Then
      If MyModel.Logical = True Then
        If MyAttribute.HasLogicalRoleName = True Then
          ColArray(Indx) = MyAttribute.LogicalRoleName
      Else
        ColArray(Indx) = MyAttribute.AttributeName
      End If
    Else
      If MyAttribute.HasRoleName = True Then
        ColArray(Indx) = MyAttribute.RoleName
      Else
        ColArray(Indx) = MyAttribute.ColumnName
      End If
    End If
    MyAttribute.Definition = ColArray(Indx)
    Indx= Indx +1
  End If
  Next MyAttribute
  Next count
End Function

Sub Main
Debug.Clear
Set MyDiagram = DiagramManager.ActiveDiagram
Set MyModel = MyDiagram.ActiveModel
Dim Indx As Integer
Indx =0
EntCount = MyModel.Entities.Count -1
ReDim TableArray(0To EntCount) As String
For Each MyEntity In MyModel.Entities
  If MyModel.Logical = True Then
    TableArray(Indx) = MyEntity.EntityName
  Else
    TableArray(Indx) = MyEntity.TableName
  End If
  MyEntity.Definition = TableArray(Indx)
  getColumns(TableArray(Indx))
  Indx = Indx +1
Next MyEntity
End Sub

 

 

 

 

 

 

 erstudio Definition2Attribute,反向工程

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
                  if tab.comment="" then 
                  else
      tab.name = tab.comment
                  end if
      Dim col ' running column
      for each col in tab.columns
      if col.comment="" then
      else
        col.name= left(col.comment,8)
      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

  

Powerdesinger name to commnet

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

 

 

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

 

Powerdesigner 自动命名主键、外键名称 

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl ' the current 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)
    'Tables
   Dim tab
   for each tab in folder.tables
       
       
      '自動設置主鍵
      dim ky
      for each ky in tab.Keys
            if ky.primary =true then
               ky.Name="PK_"+tab.Code
               ky.Code=ky.Name
               ky.ConstraintName=ky.Name
               'ky.Clustered=true
            end if
      next
                       
   next
   
   '自動設置外鍵
   dim ref
   for each ref in folder.References
      ref.name="FK_"+ref.ChildTable.Code +"_"+ref.ForeignKeyColumnList
      ref.Code=ref.Name
      ref.ForeignKeyConstraintName=ref.name
   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

 

 

转载于:https://www.cnblogs.com/zhahost/archive/2010/09/09/1822716.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: PowerDesigner是一款功能强大的数据建模工具,其ER图功能可帮助用户建立实体关系模型。使用步骤如下: 1. 打开PowerDesigner软件,新建一个ER图工作空间。 2. 在ER添加实体,可以通过工具栏上的“实体”按钮或菜单栏的“插入”选项添加。 3. 为实体添加属性,可以在实体上双击或右键点击“属性”选项添加。 4. 在实体之间建立关系,可以通过工具栏上的“关系”按钮或菜单栏的“插入”选项建立。 5. 可以通过“格式”选项调整ER图的布局,以获得更好的可读性。 6.最后进行保存。 注意:使用过程如有疑问可以查看帮助文档或者网上的教程,详细的使用方式与版本有关。 ### 回答2: PowerDesigner是一款功能强大的数据库设计和建模工具,在其使用ER图是非常重要的一个步骤。如果你想学会如何使用PowerDesignerER图,那么请看下文。 首先,我们需要了解ER图的概念。ER图是指“实体关系图”,它是用来描述一个数据库各种实体和实体之间关系的一种图形展示方式。在ER,每个实体可以被视为一个独立的“对象”,这些对象之间的关系可以用箭头线条来表示。同时,ER还包含了很多用于描述实体特征的语义元素,例如属性和主键等。 要在PowerDesigner使用ER图,首先需要打开PowerDesigner软件,然后选择“数据库”模型。接着,在模型新建一个ER图,从可以看到一个空白的白板。 接下来,我们需要在ER定义实体。在PowerDesigner,可以通过“实体”选项来创建一个新的实体,同时也可以添加实体的属性等信息。如需添加主键和外键,可以通过右键菜单的“主键”选项来进行操作。 在ER,实体之间的关系可以通过箭头线条来表示。例如,如果两个实体之间是“一对多”的关系,那么可以使用“箭头-普通线条”选项来创建一个连接。如果两个实体之间是“多对多”的关系,那么可以使用“箭头-菱形线条-箭头”选项来创建一个连接。注意,在建立连接时需要将鼠标指向相应的实体上。 在PowerDesignerER,还可以使用“模板”来快速建立一个符合标准的ER图模型。模板提供了一些通用的图形组件和样式元素,使得用户可以在更短的时间内创建一个建模图形。当然,如果需要更精细的设计,也可以自己手动进行设计。 最后,需要注意PowerDesignerER图设计是进化的过程,多使用是最好的方法。熟练掌握ER图的创建和管理技能可以极大的提升对数据库建模的效率和准确性。如果需要更多的帮助和指导,可以查看PowerDesigner官方文档或者查询网络上的相关资源。 ### 回答3: PowerDesigner是一个全面的数据建模工具,可以用于设计和维护企业解决方案。 它可以帮助用户创建ER图,属性、对象、参考完整性等其他可视化模型,并定义元数据,以便能够执行数据映射和数据转换操作。 创建ER图实际上是为了帮助您设计系统的数据库,并通过向您展示数据库架构,表之间的关系以及应用程序访问这些表时的过程来实现这一目的。 在PowerDesigner,创建ER图像如下: 第一步: 在开始使用PowerDesigner进行ER图设计之前,您需要打开该软件并创建一个新的模型。 为此,请点击“文件”->“新建”->“模型”选项。 现在,您需要在左侧显示器选择“数据库”选项,在右侧显示器选择与所需数据库兼容的命令并设置模型属性,例如模型名称,描述等。 第二步: 现在,打开ER图绘图窗口,单击“工具”-“ER图”选项卡,然后选择“新建ER图”打开一个新建的ER图。在ER窗口单击“模式”选项卡,然后从下拉列表选择ER模式,任何新的哪些对象将被添加到ER。 第三步: 在ER图上单击鼠标右键,然后选择“新建实体”选项。 现在,在ER窗口单击“对象”选项卡,添加实体(新建实体),然后配置实体属性,例如给实体命名,添加属性等。 第四步: 为实体建立一个主键或唯一标识符,通过单击鼠标右键并选择“新建属性”选项,然后在ER窗口配置该属性。 添加所有必需的属性,保存所有更改并退出ER图。 第五步: 如果必须将您的ER图与其他应用程序一同使用,则需导出ER的元数据以供使用。 要执行此操作,请单击“菜单”选项卡,并选择“文件”->“导出”选项。 现在,您可以指定导出文件格式并选择要导出到的文件夹。 总之,PowerDesigner提供了许多功能和选项,可以帮助您创建专业的ER图,并提供了各种方法来优化图形以更好地满足您的需求。对于初学者,使用PowerDesigner创建ER图可能需要一些时间和练习,但一旦您熟悉了软件的各种选项和设置,就可以灵活地使用ER图来设计您的系统数据库和架构。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值