让er studio 生成带说明的sql

一直使用er studion 来建数据库的模型图。 用了几年苦于 erstudion 不能生成带说明注释的sql 语句,每次生成实体之后都要自己去加注释。 今天根据外国朋友的资料找到了办法

  需要自己建一段弘代码

Dim EntCount As Integer
Dim ColCount As Integer
Dim MyDiagram As Diagram
Dim MyModel As Model
Dim MyEntity As Entity
//下面这句不知道说明原因报错 去掉也没有关系
Dim MyAttribute As AttributeObjDim 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(0 To 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(0 To 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

然后在tools里面 macro 里面新建一个 运行下 。就自动保存到er studion的macro 里面去了

其实不使用这外力的的情况下也是可以生成的 但是麻烦些 在新建字段名的时候选择

definition 标签选项 然后在里面写入注释 生成sql的时候也会生成带说明的sql语句 

记得在生成物理模型的时候要勾选

sql 语句的时候EXECUTE sp_addextendedproperty N'MS_Description', '描述内容', N'user', N'dbo', N'table', N'表名', NULL, NULL

原文地址:https://www.cnblogs.com/sxmny/p/4966626.html