自动设置Identity属性的代码(PowerDesigner脚本)

<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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值