powerdesigner vba 创建表和列

手工建立powerdesigner的表和列非常麻烦,于是思考用vba实现,借鉴http://www.pudn.com/downloads447/sourcecode/database/detail1884121.html,具体如下:

创建表:

Set mdl = ActiveModel

set table = mdl.Tables.CreateNew

table.Name = "tablename"

table.Code = "table"

创建列:

for each Tab in folder.tables

dim col

set col =tab.columns.createnew

col.name="columnname"

col.code="columnname"

col.comment="columncomment"

col.datatype="nvarchar2(255)"

next

参照的源码如下:

Option Explicit

Dim mdl ‘ the current model

Set mdl = ActiveModel

If (mdl Is Nothing) Then

MsgBox "There is no Active Model"

End If

Dim HaveExcel

Dim RQ

RQ = vbYes ‘MsgBox("Is Excel Installed on your machine ?", vbYesNo + vbInformation, "Confirmation")

If RQ = vbYes Then

HaveExcel = True

‘ Open & Create Excel Document

Dim x1  ‘

Set x1 = CreateObject("Excel.Application")

x1.Workbooks.Open "test.xls"

x1.Workbooks(1).Worksheets("sheet1").Activate

Else

HaveExcel = False

End If

a x1, mdl

sub a(x1, mdl)

dim rwIndex

dim tableName

dim colname

dim table

dim col

dim count

on error Resume Next

For rwIndex = 2 To 20000

With x1.Workbooks(1).Worksheets("sheet1")

If trim(.Cells(rwIndex, 2).Value) = "" Then

Exit For

End If

If trim(.Cells(rwIndex, 2).Value) <>trim(.cells(rwindex-1,2).value) Then

set table = mdl.Tables.CreateNew

table.Name = trim(.Cells(rwIndex, 1).Value)

table.Code = trim(.Cells(rwIndex, 2).Value)

count = count + 1

‘建表循环

‘--------------------第一列循环

‘colName = .Cells(rwIndex, 3).Value

set col = table.Columns.CreateNew

‘MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列"

col.Name = trim(.Cells(rwIndex, 3).Value)

‘MsgBox col.Name, vbOK + vbInformation, "列"

col.Code = trim(.Cells(rwIndex, 4).Value)

if trim(.Cells(rwIndex, 10).Value) <> "" Then

col.Comment = "单位:" + .Cells(rwIndex, 10).Value + " 。  " + .Cells(rwIndex, 18).Value

else

col.Comment = .Cells(rwIndex, 8).Value

end if

if trim(.Cells(rwIndex, 6).Value) <> "" Then

col.Primary = true

end if

col.datatype=trim(.Cells(rwIndex, 5).Value)

‘---------------第一列循环

Else

‘----------------列循环

‘colName = .Cells(rwIndex, 4).Value

set col = table.Columns.CreateNew

‘MsgBox .Cells(rwIndex, 1).Value, vbOK + vbInformation, "列"

col.Name = trim(.Cells(rwIndex, 3).Value)

‘MsgBox col.Name, vbOK + vbInformation, "列"

col.Code = trim(.Cells(rwIndex, 4).Value)

if trim(.Cells(rwIndex, 10).Value) <> "" Then

col.Comment = "单位:" + .Cells(rwIndex, 10).Value + " 。  " + .Cells(rwIndex, 18).Value

else

col.Comment = .Cells(rwIndex, 8).Value

end if

if trim(.Cells(rwIndex, 6).Value) <> "" Then

col.Primary = true

end if

col.datatype=trim(.Cells(rwIndex, 5).Value)

End If

End With

Next

MsgBox "生成数据表结构共计 " + CStr(count), vbOK + vbInformation, "表"

Exit Sub

End sub

时间: 2024-07-31 13:31:31

powerdesigner vba 创建表和列的相关文章

oracle创建表案列

下面是以商品交易为案列 做的关于用户.库存.商品.交易的表格

information_schema系列四(跟踪,列约束,表和列)

这个系列的文章主要是为了能够让自己了解MySQL5.7的一些系统表,统一做一下备注和使用,也希望分享出来让大家能够有一点点的受益. 1:KEY_COLUMN_USAGE 按照官方的解释,这个表描述的是关于有约束的列.也就是没有约束的列都不会显示出来,按照整库查了一下,我里面有五张表,结果这个库记录的只有一条信息.因为只有这个列有约束,其他几张表都是测试玩的,并没有什么约束. 我现在创建两张表主键外键关联关系,然后查一下记录: 看一下就很是明朗了有没有,test1的ID只是主键,后面的关联就会显示

4.SQL Server 创建表 修改表

系统中,表分为四种:1.系统表   2.分区表   3.临时表  4.用户自定义数据表 1.Sql创建表  默认列允许为null CREATE TABLE 表名称 ( 列名称1 数据类型, 列名称2 数据类型, 列名称3 数据类型, .... ) Create table NewTable ( id int , lastname nvarchar(255), startTime Datetime, endtime image not null ) 2.创建临时表 不在数据库实例中保存,只是保存在

PowerDesigner中创建Oracle表全过程记录

本文记录如何在PowerDesigner中创建一个Oracle结构的表. 在进行本文阅读之前,需要在PowerDesigner进行 DBMS修改,DataBase创建,用户创建,表空间创建.   1.创建表,填写name,code,comment,owner(需要提前创建) 2.创建表中的对应的列 2.1对主键进行编辑,选择主键后,点击属性按钮(第一个按钮) 2.2确认name,code,table,PrimaryKey之后,添加Sequence,修改name,code,owner 2.3修改s

数据库中创建表(包括创建主键,外键,非空列,唯一)

创建表(包括创建主键,外键,非空列,唯一) - PROS - 博客园 http://www.cnblogs.com/CodingArt/articles/1621921.html **************** 创建主键(三种方法) **************** 创建学生表: 第一种: create table student (sno char(5) primary key,/*学号*/ /*可以直接指定主键*/ sname char(20) not null,/*姓名*/ ssex c

PowerDesigner里面将表中name列值复制到comment列

/** * PowerDesigner里面将表中name列值复制到comment列 * @see -------------------------------------------------------------------------------------------------------------------- * @see pd中的pdm默认生成sql时,字段是没有注释的..想要注释的话,有2个方法 * @see 1.也是推荐的 * @see pdm中双击打开一个Table,

使用sql语句创建表、修改表、添加列等

1. 创建表: CREATE TABLE 学生信息 (    学号 varchar(14) IDENTITY(1,1) PRIMARY KEY,    姓名 varchar(8) UNIQUE NOT NULL,    班级编号 varchar(14) REFERENCES '班级信息',    年级 int null,    性别 varchar(2) CHECK(性别in ('男’','女’)),    民族 varchar(20) DEFAULT '未知该生民族',    籍贯 varch

PowerDesigner创建表datafacotry

PowerDesigner创建表 Mysql创建表 ? ? ? ? ? ? ? ? 导出表结构 ? ? 批量创建数据 ? ? NLS_LANG ? SIMPLIFIED CHINESE_CHINA.ZHS16GBK ?

【转】用sql语句创建表的时候给列指定说明(描述)

用sql语句创建表的时候,如何给列指定说明.主要用到sp_addextendedproperty这个存储过程. 语法   sp_addextendedproperty     [ @name = ] { 'property_name' }     [ , [ @value = ] { 'value' }         [ , [ @level0type = ] { 'level0_object_type' }                     , [ @level0name = ] {