- 从数据库工具(比如:navicat)中导出表结构sql。
- 将sql导入到powerDesigner里。
- File → Reverse Engineer → Database
选中导出的表结构sql点确定,生成pdm
- File → Reverse Engineer → Database
- 将comment的值写到name上
Tools → Execute Commonds → Edit/Run Script
- 写入代码点run,然后close弹窗:
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 code 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 len(tab.comment) <> 0 then
tab.name = tab.comment
end if
On Error Resume Next
Dim col 'running column
for each col in tab.columns
if len(col.comment) <>0 then
col.name =col.comment
end if
On Error Resume Next
next
end if
next
end sub
- 把code驼峰转为下划线
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)
Dim Tab
for each Tab in folder.tables
Dim col
for each col in tab.columns
Dim ch
Dim exaStr
exaStr = ""
Dim intCounter
Dim intLen
Dim arrChars
intLen = Len(col.code)-1
redim arrChars(intLen)
For intCounter = 0 to intLen
arrChars(intCounter) = Mid(col.code, intCounter + 1,1)
Next
for each ch in arrChars
Dim tmpCh
tmpCh = LCase(ch)
If StrComp(ch, tmpCh)=0 Then
exaStr = exaStr + ch
Else
exaStr = exaStr + "_" + tmpCh
End If
next
col.code = exaStr
next
next
end sub
搞定