<script type="text/javascript">
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
'文件:Set Identity.vbs
'版本:1.0
'版权:floodzhu(floodzhu@hotmail.com),2004.12.31
'功能:遍历物理模型中的所有表,把是主键但不是外键的字段设置为 Identity,适用于
' 物理模型为MSSqlServer的类型。
'用法:打开物理模型,运行本 脚本(Ctrl+Shift+X)
'备注:我有两个习惯,一个是把所有表的主键都定义为自增长的int类型,另一个是定义
' 一个Domain叫ID,在概念模型时把所有的PrimaryKey字段的Domain设置为ID
' 类型。
'
' 如果我进行了上面的设置,则在转化为物理模型时需要手工设置 Identity,
' 最笨的方法是一个表一个表进行设置,最简单的方法是在物理模型中直接对Domain
' 进行设置。对Domain进行设置有一个小缺点,就是如果该字段不是主键也不是生
' 成的外键,而是一个一般字段,例如表示树状结构的PID,则它也会被设置为
' Identity,不过由于这种字段比较少,而且在生成时会发生错误可以提醒
' 你进行纠正,所以可以轻松过关而不至于隐藏错误,所以是一种好方法。
'
' 用下面的 代码可以给你第三种选择,而不会发生任何错误。
'*****************************************************************************
dimmodel'currentmodel
setmodel=ActiveModel
If(modelIsNothing)Then
MsgBox"ThereisnocurrentModel"
ElseIfNotmodel.IsKindOf(PdPDM.cls_Model)Then
MsgBox"ThecurrentmodelisnotanPhysicalDatamodel."
Else
ProcessTablesmodel
EndIf
'*****************************************************************************
'函数:ProcessTables
'功能:递归遍历所有的表
'*****************************************************************************
subProcessTables(folder)
'处理模型中的表
dimtable
foreachtableinfolder.tables
ifnottable.IsShortCutthen
ProcessTabletable
endif
next
'对子目录进行递归
dimsubFolder
foreachsubFolderinfolder.Packages
ProcessTablessubFolder
next
endsub
'*****************************************************************************
'函数:ProcessTable
'功能:遍历指定table的所有字段,如果该字段是主键但不是外键,则设置为 Identity
'*****************************************************************************
subProcessTable(table)
dimcol
foreachcolintable.Columns
'对于是主键且不是外键的字段设置为 Identity(自增长类型)
ifcol.Primaryandnotcol.ForeignKeythen
col. Identity=true
endif
next
endsub <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript">
</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
'*****************************************************************************
'文件:Set Identity.vbs
'版本:1.0
'版权:floodzhu(floodzhu@hotmail.com),2004.12.31
'功能:遍历物理模型中的所有表,把是主键但不是外键的字段设置为 Identity,适用于
' 物理模型为MSSqlServer的类型。
'用法:打开物理模型,运行本 脚本(Ctrl+Shift+X)
'备注:我有两个习惯,一个是把所有表的主键都定义为自增长的int类型,另一个是定义
' 一个Domain叫ID,在概念模型时把所有的PrimaryKey字段的Domain设置为ID
' 类型。
'
' 如果我进行了上面的设置,则在转化为物理模型时需要手工设置 Identity,
' 最笨的方法是一个表一个表进行设置,最简单的方法是在物理模型中直接对Domain
' 进行设置。对Domain进行设置有一个小缺点,就是如果该字段不是主键也不是生
' 成的外键,而是一个一般字段,例如表示树状结构的PID,则它也会被设置为
' Identity,不过由于这种字段比较少,而且在生成时会发生错误可以提醒
' 你进行纠正,所以可以轻松过关而不至于隐藏错误,所以是一种好方法。
'
' 用下面的 代码可以给你第三种选择,而不会发生任何错误。
'*****************************************************************************
dimmodel'currentmodel
setmodel=ActiveModel
If(modelIsNothing)Then
MsgBox"ThereisnocurrentModel"
ElseIfNotmodel.IsKindOf(PdPDM.cls_Model)Then
MsgBox"ThecurrentmodelisnotanPhysicalDatamodel."
Else
ProcessTablesmodel
EndIf
'*****************************************************************************
'函数:ProcessTables
'功能:递归遍历所有的表
'*****************************************************************************
subProcessTables(folder)
'处理模型中的表
dimtable
foreachtableinfolder.tables
ifnottable.IsShortCutthen
ProcessTabletable
endif
next
'对子目录进行递归
dimsubFolder
foreachsubFolderinfolder.Packages
ProcessTablessubFolder
next
endsub
'*****************************************************************************
'函数:ProcessTable
'功能:遍历指定table的所有字段,如果该字段是主键但不是外键,则设置为 Identity
'*****************************************************************************
subProcessTable(table)
dimcol
foreachcolintable.Columns
'对于是主键且不是外键的字段设置为 Identity(自增长类型)
ifcol.Primaryandnotcol.ForeignKeythen
col. Identity=true
endif
next
endsub <script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript">
</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>