When powerdesigner is used to design conceptual and physical models for databases, it generally writes Chinese in name or comment and English in code. Name is used to display
Code is used in the code, but the text in the comment is saved to the database table or column comment. If the name already exists, write it again.
Comment is very troublesome. You can use the following code to solve this problem:
- Code 1:Copy the characters in name to comment.
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. isw.cut 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. isw.cut 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. isw.cut then
ProcessFolder f
End if
Next
End sub
--------------------------------------------
In addition, when the reverse engineer is used to reverse generate PDM from the database, the name and code of the table in PDM are actually code. To replace the name with the Chinese comment of table or column in the database, you can use the following script:
- Code 2:COPY the characters in 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. isw.cut 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. isw.cut 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. isw.cut then
ProcessFolder f
End if
Next
End sub
-----------------------------------------------------------------------
The above two sections of code are all VB scripts. The usage in powerdesigner is as follows:
Powerdesigner-> Tools-> execute commands-> edit/run scripts
Copy the code and execute it. The operation is performed on the entire CDM or PDM.