参考
运行如下的脚本可以为PDM模型中的每张表增加二个字段(创建时间和更新时间)
Option Explicit
Dim mdl ' the current model
Set mdl = ActiveModel
Dim Tab 'running table
Dim col_CreatedTime, col_ModTime
' 定义属性变量
for each Tab in ActiveModel.Tables
If(Tab.Code <> "tab1")and (Tab.Code <> "tab2") Then
Set col_CreatedTime = Tab.Columns.CreateNew
set col_ModTime = Tab.Columns.CreateNew
col_CreatedTime.name = "创建时间"
col_CreatedTime.comment = "创建时间"
col_CreatedTime.code = "created_at"
col_CreatedTime.DataType = "timestamp"
col_ModTime.name = "更新时间"
col_ModTime.comment = "更新时间"
col_ModTime.code = "updated_at"
col_ModTime.DataType = "timestamp"
end if
next
修改建表脚本生成规则。
如果每个表格都有相同的字段,可以如下修改:
Database -> Edit Current DBMS 展开 Script -> Object -> Table -> Create 见右下的Value值,可以直接修改如下:
/* tablename: %TNAME% */
create table [%QUALIFIER%]%TABLE% (
%TABLDEFN%
created_at timestamp default CURRENT_TIMESTAMP comment '创建时间',
updated_at timestamp default CURRENT_TIMESTAMP comment '更新时间',
)
[%OPTIONS%]