ER/Studio 数据库建模

打开ER/Studio工具,File —> NEW

选择第二个,连接数据库,设置数据库类型,连接数据库属性值

一直Next,生成数据库模型图

到此,数据库模型图建成,保存。

PS:有的时候需要将模型图EntityName设置为数据库中表的备注信息,所以我们应用工具宏来完成这一操作。

打开数据库模型图,点击Tools —> Basic Macro Editor

打开文件DefinitionToAttribute.BAS,并运行,等待完成,整个过程就OK了。

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

DefinitionToAttribute.BAS(EntityName描述设置为数据库表的备注)

 1 Dim MyDiagram As Diagram
 2 Dim MyModel As Model
 3 Dim MyEntity As Entity
 4 Dim MyAttribute As AttributeObj
 5 
 6 Sub Main
 7 Debug.Clear
 8 Set MyDiagram = DiagramManager.ActiveDiagram
 9 Set MyModel = MyDiagram.ActiveModel
10 
11 For Each MyEntity In MyModel.Entities
12   MyEntity.EntityName = MyEntity.Definition
13   
14     For Each MyAttribute In MyEntity.Attributes
15         MyAttribute.AttributeName = MyAttribute.Definition
16       Next MyAttribute
17 Next MyEntity
18 End Sub

AttributeToDefinition.BAS

 1 Dim EntCount As Integer
 2 Dim ColCount As Integer
 3 Dim MyDiagram As Diagram
 4 Dim MyModel As Model
 5 Dim MyEntity As Entity
 6 Dim MyAttribute As AttributeObj
 7 Dim TableArray() As String
 8 Dim ColArray() As String
 9 Function getColumns(TableName As String )
10 Dim Indx As Integer
11 Dim count As Integer
12 count = 1
13 Indx = 0
14 Set MyEntity = MyModel.Entities.Item(TableName)
15 ColCount = MyEntity.Attributes.Count
16 ReDim ColArray(0 To ColCount) As String
17 For count=1 To ColCount
18   For Each MyAttribute In MyEntity.Attributes
19     If MyAttribute.SequenceNumber = count Then
20       If MyModel.Logical = True Then
21         If MyAttribute.HasLogicalRoleName = True Then
22           ColArray(Indx) = MyAttribute.LogicalRoleName
23       Else
24         ColArray(Indx) = MyAttribute.AttributeName
25       End If
26     Else
27       If MyAttribute.HasRoleName = True Then
28         ColArray(Indx) = MyAttribute.RoleName
29       Else
30         ColArray(Indx) = MyAttribute.ColumnName
31       End If
32     End If
33     MyAttribute.Definition = ColArray(Indx)
34     Indx= Indx +1
35   End If
36   Next MyAttribute
37   Next count
38 End Function
39 
40 Sub Main
41 Debug.Clear
42 Set MyDiagram = DiagramManager.ActiveDiagram
43 Set MyModel = MyDiagram.ActiveModel
44 Dim Indx As Integer
45 Indx = 0
46 EntCount = MyModel.Entities.Count - 1
47 ReDim TableArray(0 To EntCount) As String
48 For Each MyEntity In MyModel.Entities
49   If MyModel.Logical = True Then
50     TableArray(Indx) = MyEntity.EntityName
51   Else
52     TableArray(Indx) = MyEntity.TableName
53   End If
54   MyEntity.Definition = TableArray(Indx)
55   getColumns(TableArray(Indx))
56   Indx = Indx +1
57 Next MyEntity
58 End Sub
原文地址:https://www.cnblogs.com/Gieag/p/2831055.html