Option Explicit
ValidationMode =True
InteractiveMode = im_Batch
Dim mdl
Set mdl = ActiveModel
If(mdl IsNothing)Then
MsgBox "There is no Active Model"Else
ListObjects(mdl)EndIfPrivateSub ListObjects(fldr)output"Scanning "& fldr.code
Dim obj
For Each obj In fldr.children
TableSetComment obj
NextDim f
For Each f In fldr.Packages
ListObjects f
NextEndSubPrivateSub TableSetComment(CurrentObject)ifnot CurrentObject.Iskindof(cls_Table)thenexitsub// 添加你需要排除的表
if instr(",standard_data_field,",","+CurrentObject.Code+",")>0thenexitsubifnot CurrentObject.isShortcut thenDim col
Dim num
//定义你需要添加的字段;
dim create_user_id_
dim create_time_
dim modify_user_id_
dim modify_time_
dim is_delete_
dim is_final_
dim tenant_id_
dim team_id_
//给字段定义一个初始值;
create_user_id_=1
modify_user_id_=1
create_time_=1
modify_time_=1
is_delete_=1
is_final_ =1
tenant_id_ =1
team_id_ =1//循环获取到最大列号;
for each col in CurrentObject.columns
num= num +1//如果列中有此字段,赋个其他值;(可能是,实际操作如果表中有此字段,会报错)
if col.Code="create_user_id_"then
create_user_id_=100endifif col.Code="create_time_"then
create_time_=100endifif col.Code="modify_user_id_"then
modify_user_id_=100endifif col.Code="modify_time_"then
modify_time_=100endifif col.Code="is_delete_"then
is_delete_=100endifnext//下面的操作是进行赋默认值,根据需要进行设计即可。
if create_user_id_=1then
CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns
if col.DataType=""then
col.Name="创建人"
col.Code="create_user_id_"
col.Comment="创建人"
col.DataType="bigint(20)"
col.Mandatory=1endifnext
num=num+1endifif create_time_=1then
CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns
if col.DataType=""then
col.Name="创建时间"
col.Code="create_time_"
col.Comment="创建时间"
col.DataType="datetime"
col.DefaultValue="CURRENT_TIMESTAMP"endifnext
num=num+1endifif modify_user_id_=1then
CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns
if col.DataType=""then
col.Name="修改人"
col.Code="modify_user_id"
col.Comment="修改人"
col.DataType="bigint(20)"endifnext
num=num+1endifif modify_time_=1then
CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns
if col.DataType=""then
col.Name="修改时间"
col.Code="modify_time_"
col.Comment="修改时间"
col.DataType="datetime"
col.DefaultValue="CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"endifnext
num=num+1endifif is_delete_=1then
CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns
if col.DataType=""then
col.Name="删除标志"
col.Code="is_delete_"
col.Comment="删除标识(1:已删除;0:正常)"
col.DataType="tinyint(1)"
col.DefaultValue="0"endifnext
num=num+1endifif is_final_=1then
CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns
if col.DataType=""then
col.Name="修改标志"
col.Code="is_final_"
col.Comment="是否不可修改(1:不可修改;0:可修改)"
col.DataType="tinyint(1)"
col.DefaultValue="0"endifnext
num=num+1endifif tenant_id_=1then
CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns
if col.DataType=""then
col.Name="租户id"
col.Code="tenant_id_"
col.Comment="租户id"
col.DataType="bigint(20)"
col.DefaultValue="-1"endifnext
num=num+1endifif team_id_=1then
CurrentObject.columns.CreateNewAt(num)for each col in CurrentObject.columns
if col.DataType=""then
col.Name="团队id"
col.Code="team_id_"
col.Comment="团队id"
col.DataType="bigint(20)"endifnext
num=num+1endifendifEndSub
添加注释
Option Explicit
ValidationMode =True
InteractiveMode = im_Batch
Dim blankStr
blankStr = Space(1)Dim mdl ' the current model ' get the current active model Set mdl = ActiveModel
If(mdl IsNothing)Then
MsgBox "There is no current Model "ElseIfNot mdl.IsKindOf(PdPDM.cls_Model)Then
MsgBox "The current model is not an Physical Data model. "Else
ProcessFolder mdl
EndIfPrivatesub ProcessFolder(folder)On ErrorResumeNextDimTab'running table for each Tabin folder.tables
ifnottab.isShortcut thentab.name=tab.comment
Dim col ' running column for each col intab.columns
if col.comment =""or replace(col.comment," ","")=""Then
col.name= blankStr
blankStr = blankStr & Space(1)else
col.name= col.comment
endifnextendifnextDim view 'running view for each view in folder.Views
ifnot view.isShortcut then
view.name= view.comment
endifnext' go into the sub-packages Dim f ' running folder For Each f In folder.Packages
ifnot f.IsShortcut then
ProcessFolder f
endifNextendsub