在PowerDesigner中的設計SQL Server 數據表時,要求通過vbScript腳本實現下面的功能:
主鍵:pk_TableName
外鍵:fk_TableName_ForeignKeyColumnList
當字段作為主鍵,而且類型為smallint,int,bigint,那么要設置Identity =true.
當字段作為主鍵,而且類型為uniqueidentifier,那么要設置默認值為newid(),而且設置擴展屬性rowguidcol.
Option ExplicitValidationMode = TrueInteractiveMode = im_BatchDim mdl ' the current modelSet mdl = ActiveModelIf (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 mdlEnd IfPrivate sub ProcessFolder(folder) 'Tables Dim tab for each tab in folder.tables dim col for each col in tab.columns '自動設置Identity if col.primary =true and (col.datatype ="smallint" or col.datatype = "int" or col.datatype = "bigint") then col.identity=true '自動設置ROWGUIDCOL elseif col.primary=true and col.datatype="uniqueidentifier" then col.DefaultValueDisplayed="newid()" col.SetExtendedAttributeText "ExtRowGUIDCol",true end if next '自動設置主鍵 dim ky for each ky in tab.Keys if ky.primary =true then ky.Name="pk_"+tab.Name ky.Code=ky.Name ky.ConstraintName=ky.Name ky.Clustered=true end if next next '自動設置外鍵 dim ref for each ref in folder.References ref.name="fk_"+ref.ChildTable.Name +"_"+ref.ForeignKeyColumnList ref.Code=ref.Name ref.ForeignKeyConstraintName=ref.name 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 Nextend sub
新聞熱點
疑難解答