编写Powerdesigner脚本,快速生成数据库表
2005-08-12 08:52
435 查看
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,然后再一个一个改吧。
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,然后再一个一个改吧。
相关文章推荐
- 编写Powerdesigner脚本,快速生成数据库表
- 使用PD(PowerDesigner)图如何快速生成创建数据库表的SQL脚本
- powerdesigner 生成数据库脚本
- (喷血分享)利用.NET生成数据库表的创建脚本,类似SqlServer编写表的CREATE语句
- PowerDesigner 物理数据模型生成数据库脚本并执行
- PowerDesigner 导入数据库建表SQL脚本生成物理模型
- powerdesigner如何给生成的mysql 4.0 脚本数据库中增加注释
- PowerDesigner生成数据库建表SQL脚本时去双引号
- PowerDesigner 如何生成数据库更新脚本
- sql2012包含数据库,快速生成用户tsql脚本
- PowerDesigner生成数据库脚本的方法
- powerdesigner中生成数据库脚本时出现长度限制问题的解决方法
- 使用PowerDesigner生成数据库建表SQL脚本时去双引号
- PowerDesigner 生成对应数据库的sql脚本
- (喷血分享)利用.NET生成数据库表的创建脚本,类似SqlServer编写表的CREATE语句
- 利用.NET生成数据库表的创建脚本,类似SqlServer编写表的CREATE语句
- PowerDesigner中在生成的数据库脚本中用name列替换comment列作为字段描述的方法
- PowerDesigner生成数据库建表sql脚本
- 利用.NET生成数据库表的创建脚本,类似SqlServer编写表的CREATE语句
- (喷血分享)利用.NET生成数据库表的创建脚本,类似SqlServer编写表的CREATE语句