powerdesigner-vbsrcipt-Auto-Set Primary key, foreign key name, etc. (SQL Server)

Source: Internet
Author: User
Tags powerdesigner

Original: powerdesigner-vbsrcipt-Auto set Primary key, foreign key name, etc. (SQL Server)

When designing SQL Server datasheets in PowerDesigner, the following functionality is required through VBScript scripting:

Primary key: Pk_tablename

FOREIGN key: Fk_tablename_foreignkeycolumnlist

When the field is a primary key and the type is Smallint,int,bigint, set the identity =true.

When the field is a primary key and the type is uniqueidentifier, set the default value to NEWID () and set the extended property ROWGUIDCOL.

Option ExplicitValidationmode=TrueInteractivemode=Im_batchDimmdl'The current modelSetMDL =ActivemodelIf(MDL is  Nothing) Then   MsgBox "There is no current Model"ElseIf  notmdl. IsKindOf (Pdpdm.cls_model) Then   MsgBox "The current model isn't an physical Data model."ElseProcessFolder MDLEnd IfPrivate SubProcessFolder (folder)'Tables   Dim Tab    for  each Tab inchFolder.tablesDimCol for  eachColinch Tab. Columns'Auto Setup Identity            ifCol.primary =true  and(Col.datatype ="smallint" orCol.datatype ="int"  orCol.datatype ="bigint") Thencol.identity=true                           'Auto Setup rowguidcol            ElseIfcol.primary=true  andCol.datatype="uniqueidentifier"  ThenCol. Defaultvaluedisplayed="newid ()"Col. Setextendedattributetext"Extrowguidcol",true            End if                   Next                 'Auto Setup Key      DimKY for  eachKyinch Tab. KeysifKy.primary =true  ThenKy. Name="Pk_"+Tab. Name Ky. Code=Ky. Name Ky. ConstraintName=Ky. Name Ky. Clustered=true            End if      Next                          Next      'Auto Set external keys   Dimref for  eachRefinchfolder. References Ref.name="Fk_"+ref. Childtable.name +"_"+Ref. Foreignkeycolumnlist Ref. Code=Ref. Name Ref. Foreignkeyconstraintname=Ref.nameNext      'go into the sub-packages   DimF'Running Folder    for  eachFinchfolder. Packagesif  notF.isshortcut ThenProcessFolder FEnd if   NextEnd Sub

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.