在默认的情况下,powerdesigner生成的表的sql语句是不带注释的。如果我们不懂表中的字段,那么我们可以在powerdesigner中查找。但是,这样是很麻烦的。你不想多次打开一个早就不需要使用的软件了吧。如果你电脑配置低,好呀,更麻烦了。怎么解决这一个问题?那就是给生成的sql加上注解。这样在查看数据库的时候,就可以查找字段的意思了。这样岂不是方便了很多。怎么操作?
tools->Excecute commands ->Edit/run script 执行如下代码即可:
'******************************************************************************
'* File: name2comment.vbs
'* Purpose: Database generation cannot use object names anymore
' in version 7 and above.
' It always uses the object codes.
'
' In case the object codes are not aligned with your
' object names in your model, this script will copy
' the object Name onto the object Comment for
' the Tables and Columns.
'
'* Title:
'* Version: 1.0
'* Company: Sybase Inc.
'******************************************************************************
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
'把列name和comment合并为comment
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
解决了问题么?我不知道。因为我做了另外一种方式:database->general->script->Objects->Column->ColumnComment 修改了值。但是也爆出一个问题。
什么问题呢?创建的表的字段的主键值不能自增(我用的字段类型为Serial)。那么,我得看下是什么问题了。后来发现在生成的sql文件中。使用修改值的方式来解决注释的sql文件,注解是修改字段然后带上注释的。取消了主键的自动递增。我不会修改那个语句。所以抛弃了这种方法。
后来我经过查找发现这种方式能解决,在创建表的时候就给字段添加了注释,不会造成主键不能递增。具体看一下他的文档:https://blog.csdn.net/qq_28986619/article/details/79770411