zoukankan      html  css  js  c++  java
  • 编写Powerdesigner脚本,快速生成数据库表

     

    PowerDesigner支持VBScript脚本,帮助生成数据库模型中的对象。具体功能入口在菜单Tools-->Execute Commands-->Edit/Run Script,下面是我写的一个快速生成数据库表的脚本,在我的项目实践中,因为有太多的表要从需求调研报告中提取出来,在PD中一个字段一个字段的输入实在太费劲了,就想了这个办法偷赖。代码如下:

    Option Explicit

    '-----------------------------------------------------------------------------
    ' Initialization
    '-----------------------------------------------------------------------------
    Dim system, file
    Set system = CreateObject("Scripting.FileSystemObject")

    ' Open mode constants...
    Dim ForReading, ForWriting, ForAppending
    ForReading   = 1 ' Open a file for reading only. You can't write to this file.
    ForWriting   = 2 ' Open a file for writing.
    ForAppending = 8 ' Open a file and write to the end of the file.

    '-----------------------------------------------------------------------------
    ' Main function
    '-----------------------------------------------------------------------------

    Set file = system.OpenTextFile("D:\table.txt", ForReading)
    Dim noLine
    Dim Tab  'table
    ValidationMode = True
    Dim mdl ' the current model
    Dim Col
    dim dm, dmstr
    Dim SSS
    Dim isNewTable
    ' get the current active model
    Set mdl = ActiveModel

       For each dm in mdl.domains
          If Not dm.isShortcut Then
             If dm.code = "dm_pk" Then
                Exit For
             End If
          End If
       Next  
       For each dmstr in mdl.domains
          If Not dmstr.isShortcut Then
             If dmstr.code = "dm_string" Then
                Exit For
             End If
          End If
       Next  


    set Tab = mdl.Tables.CreateNew
    set Col=tab.Columns.CreateNew
    Col.name = "ID"
    Col.Code = "ID"
    col.domain=dm
    Col.Primary = True
    isNewTable = True
    Do While file.AtEndOfStream <> True
       SSS = file.ReadLine
       if isNewTable = True then
         if SSS <> "" then
           isNewTable = False
           tab.name = SSS
         end if
       elseif SSS = "" then
         set Tab = mdl.Tables.CreateNew
         set Col=tab.Columns.CreateNew
         Col.name = "ID"
         Col.Code = "ID"
         col.domain=dm
         Col.Primary = True
         isNewTable = True
       else 
         set Col=tab.Columns.CreateNew
         Col.name = SSS
         col.domain=dmstr
       end if 
    Loop
    file.Close

    这样我只要将所需的实段名和表名放在文本文件中,不同的表以空行分开,就可以自动增加表了。

    不过生成的字段名都是Column1...ColumnN,然后再一个一个改吧。

    antony
    :antony1029@163.com
    :http://antony1029.cnblogs.com
  • 相关阅读:
    小小知识点(二)——如何修改win10 的C盘中用户下的文件夹名称
    Day15 Python基础之logging模块(十三)
    Day14 Python基础之os/sys/hashlib模块(十二)
    Day13 Python基础之time/datetime/random模块一(十一)
    Day12 Python基础之生成器、迭代器(高级函数)(十)
    Day11 Python基础之装饰器(高级函数)(九)
    火狐HACK
    javascript操作cookie
    <!DOCTYPE>标签的定义与用法
    前端性能优化
  • 原文地址:https://www.cnblogs.com/antony1029/p/331303.html
Copyright © 2011-2022 走看看