[原创]用PowerDesigner制作数据库升级脚本

很多人使用PD的时候就问有没有制作自动升级脚本的功能。其实是有的。

操作原理:
1、保存原来的版本,另存为apm的文件,生成一个Archive Model。
2、生成升级脚本,需要选择原来的版本

操作步骤:
1、打开PDM文件,选择Save as .... 另存为,在弹出的窗口中选择apm的文件类型,输入文件名保存即可。
2、修改相关的数据模型的内容,然后保存。
3、选择DataBase菜单中的modify database... 菜单(15.3版本是在DataBase中的Apply Model Changes to Database)
4、在弹出的窗口中设置升级脚本的目录及文件名后,在synchronization页框中的obtains database schema中选择using an archive model: 选择原先保存的apm文件。后面的其它页框设置与生成脚本的类似。

 


5、点一下确定,PD就会自动生成数据库的对比信息,弹出一个database synchronization窗口,这里这个窗口里列出了所有的差异信息,你可以选择需要升级的内容。点ok就可以看到升级脚本了。



生成脚本分析:
总体来讲还是很智能化的一个工具。
比如增加一个列,生成就的脚本就很简单。脚本如下:
alter table SY_MsgSend add Column_8 CHAR(10)
/

在删除列的时候就充分体现出智能化的升级脚本,如下所示,做了一个删除列的操作会生成一系列的升级脚本:

/*==============================================================*/
/* Database name:  Database                                     */
/* DBMS name:      ORACLE Version 9i                            */
/* Created on:     2007-9-6 11:12:26                            */
/*==============================================================*/


alter table SY_MsgReceiver
   drop constraint FK_SY_MSGRE_SY_MSGREC_SY_MSGSE
/


drop table tmp_SY_MsgSend cascade constraints
/


/*==============================================================*/
/* Table: tmp_SY_MsgSend                                        */
/*==============================================================*/


create table tmp_SY_MsgSend  (
   MS_ID                NUMBER(10)                       not null,
   MS_Content           VARCHAR2(4000),
   MS_SendTime          DATE,
   MS_Type              VARCHAR2(4),
   MS_Sender            NUMBER(8),
   MS_Status            NUMBER(1)                      default 1  not null,
   MS_MsgSource         NUMBER(2)                      default 1  not null,
   Column_8             CHAR(10)
)
/

 

insert into tmp_SY_MsgSend (MS_ID, MS_Content, MS_SendTime, MS_Type, MS_Sender, MS_Status, MS_MsgSource)
select MS_ID, MS_Content, MS_SendTime, MS_Type, MS_Sender, MS_Status, MS_MsgSource
from SY_MsgSend
/


drop table SY_MsgSend cascade constraints
/


/*==============================================================*/
/* Table: SY_MsgSend                                            */
/*==============================================================*/


create table SY_MsgSend  (
   MS_ID                NUMBER(10)                       not null,
   MS_Content           VARCHAR2(4000),
   MS_SendTime          DATE,
   MS_Type              VARCHAR2(4),
   MS_Sender            NUMBER(8),
   MS_Status            NUMBER(1)                      default 1  not null,
   MS_MsgSource         NUMBER(2)                      default 1  not null,
   constraint PK_SY_MSGSEND primary key (MS_ID)
)
tablespace TBS_EOFFICE
/


insert into SY_MsgSend (MS_ID, MS_Content, MS_SendTime, MS_Type, MS_Sender, MS_Status, MS_MsgSource)
select MS_ID, MS_Content, MS_SendTime, MS_Type, MS_Sender, MS_Status, MS_MsgSource
from tmp_SY_MsgSend
/


/*==============================================================*/
/* Index: Index_47                                              */
/*==============================================================*/
create index Index_47 on SY_MsgSend (
   MS_Sender ASC
)
tablespace TBS_IDX_Eoffice
/


alter table SY_MsgReceiver
   add constraint FK_SY_MSGRE_SY_MSGREC_SY_MSGSE foreign key (MS_ID)
      references SY_MsgSend (MS_ID)
      on delete cascade
/


 


posted @ 2007-09-06 11:17  小草  阅读(3039)  评论(6编辑  收藏  举报
Google+