Powerdesigner数据库设计指南

1. <!-- [endif]-->概述

本指南只介绍用 Powerdesigner 设计概念模型、物理模型及仓库的使用, Powerdesigner 其它模型的使用不在本指南的介绍范围。

本指南使用的工具为 Powerdesigner12.5 。因 Powerdesigner 各版本间在概念模型、物理模型设计操作上的改变不大,本指南对使用其它版本的 Powerdesigner 具有一定的指导作用。

本指南以组织机构模型作为实例。

本指南的重点是介绍 Powerdesigner 工具的使用,不介绍建模技术。

在实际的设计过程中,不强制要求一定要先建概念模型,再建物理模型。而是根据个人或项目的要求决定建什么模型。

<!-- [if !supportLists]-->2. <!-- [endif]-->术语

工作区: workspace 。保存当前在 Powerdesigner 中使用的模型文件,下次执行 Powerdesigner 时,自动把工作区中的模型文件显示出来。

域: Domain 。自定义的数据类型。

概念模型: Conceptual Data Model

物理模型: Physical Data Model

仓库: Repository 。用于保存提交的模型文件,每次提交的模型文件都有一个版本号。方便多人协同设计和版本管理。

<!-- [if !supportLists]-->3. <!-- [endif]-->Powerdesigner 的一些特性应用

<!-- [if !supportLists]-->3.1 <!-- [endif]-->NameCode 的镜像设置

Powerdesigner 的每一个对象都包含 namecode ,在生成代码时,使用的是 codename 是方便我们阅读。

建议在建模时, name 栏输入中文, code 栏输入英文字符,这样既方便我们阅读,也方便生成代码。

默认情况下,在 name 栏输入的内容会自动填写到 code 。如果不希望这样,可执行菜单“ Tools/ General Options ”,在弹出窗口中选择 Dialog ,如下图:

<!-- [if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"/> <v:f eqn="sum @0 1 0"/> <v:f eqn="sum 0 0 @1"/> <v:f eqn="prod @2 1 2"/> <v:f eqn="prod @3 21600 pixelWidth"/> <v:f eqn="prod @3 21600 pixelHeight"/> <v:f eqn="sum @0 0 1"/> <v:f eqn="prod @6 1 2"/> <v:f eqn="prod @7 21600 pixelWidth"/> <v:f eqn="sum @8 21600 0"/> <v:f eqn="prod @7 21600 pixelHeight"/> <v:f eqn="sum @10 21600 0"/> </v:formulas> <v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/> <o:lock v:ext="edit" aspectratio="t"/> </v:shapetype><v:shape id="_x0000_i1043" type="#_x0000_t75" style='width:414.75pt; height:348.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image001.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

取消 Name to Code mirroring 前的选择就可以了。

<!-- [if !supportLists]-->3.2 <!-- [endif]-->与仓库的连接设置

如果需要设置与仓库连接的参数,可执行“ Tools/ General Options ”,在弹出窗口中选择 Repository ,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1044" type="#_x0000_t75" style='width:414.75pt;height:348.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image003.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

相信大家从窗口上各选项的字面意思就能明白该选项是起什么作用了。

<!-- [if !supportLists]-->3.3 <!-- [endif]-->排列图元

Powerdesigner 提供了快速排列图元位置的工具条 Layout 。在工具条位置单击鼠标右键,弹出如下选择:

<!-- [if gte vml 1]><v:shape id="_x0000_i1045" type="#_x0000_t75" style='width:114pt;height:207pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image005.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

选中 Layout ,在工具条位置就会出现如下图元排列调整的工具条:

<!-- [if gte vml 1]><v:shape id="_x0000_i1046" type="#_x0000_t75" style='width:268.5pt;height:21.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image007.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

<!-- [if !supportLists]-->4. <!-- [endif]-->设计概念模型

<!-- [if !supportLists]-->4.1 <!-- [endif]-->为什么要建概念模型

概念模型的理论基础是实体 / 关系理论,建立的图形也叫 实体 / 关系 图,或者 E/R 图。我们也可以把 E/R 图看着是没有方法、只有属性的类图,是类图的一种特例。 实体 / 关系 图能够使我们在建模时先抛开数据库表设计的细节,集中精力把现实世界的实体和关系转换为 实体 / 关系 模型,以使我们建立的 实体 / 关系 模型尽量真实的反映现实世界。

概念模型与使用的数据库无关,当我们的系统需要使用不同的数据库系统时,我们就可以使用概念模型生成对应该数据库的物理模型,而不需要重新设计。

<!-- [if !supportLists]-->4.2 <!-- [endif]--><!-- [if gte vml 1]><v:group id="_x0000_s1029" style='position:absolute;left:0;text-align:left; margin-left:30pt;margin-top:19pt;width:342pt;height:114.95pt;z-index:1' coordorigin="2397,11546" coordsize="6840,2299"> <v:shapetype id="_x0000_t48" coordsize="21600,21600" o:spt="48" adj="-10080,24300,-3600,4050,-1800,4050" path="m@0@1l@2@3@4@5nfem,l21600,r,21600l,21600xe"> <v:stroke joinstyle="miter"/> <v:formulas> <v:f eqn="val #0"/> <v:f eqn="val #1"/> <v:f eqn="val #2"/> <v:f eqn="val #3"/> <v:f eqn="val #4"/> <v:f eqn="val #5"/> </v:formulas> <v:path arrowok="t" o:extrusionok="f" gradientshapeok="t" o:connecttype="custom" o:connectlocs="@0,@1;10800,0;10800,21600;0,10800;21600,10800"/> <v:handles> <v:h position="#0,#1"/> <v:h position="#2,#3"/> <v:h position="#4,#5"/> </v:handles> <o:callout v:ext="edit" on="t"/> </v:shapetype><v:shape id="_x0000_s1030" type="#_x0000_t48" style='position:absolute; left:2397;top:13339;width:840;height:506' adj="67114,-22667,45746,7684,24686,7684,9257,20874"> <v:textbox> <![if !mso]> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td><![endif]> <div> <p class=MsoNormal style='text-indent:0cm;mso-char-indent-count:0'><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman"'>实体</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> <o:callout v:ext="edit" minusx="t"/> </v:shape><v:shape id="_x0000_s1031" type="#_x0000_t48" style='position:absolute; left:5517;top:11546;width:1200;height:506' adj="-2970,48237,-2556,7684,-2160,7684,-8640,34791"> <v:textbox> <![if !mso]> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td><![endif]> <div> <p class=MsoNormal style='text-indent:0cm;mso-char-indent-count:0'><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman"'>实体关系</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> <o:callout v:ext="edit" minusy="t"/> </v:shape><v:shape id="_x0000_s1032" type="#_x0000_t48" style='position:absolute; left:8037;top:11709;width:1200;height:506' adj="-41310,41919,-21510,7684,-2160,7684,-75600,38077"> <v:textbox> <![if !mso]> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td><![endif]> <div> <p class=MsoNormal style='text-indent:0cm;mso-char-indent-count:0'><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman"'>继承关系</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> <o:callout v:ext="edit" minusy="t"/> </v:shape><v:shape id="_x0000_s1033" type="#_x0000_t48" style='position:absolute; left:4557;top:13339;width:1200;height:506' adj="27810,-20618,25650,7684,23760,7684,-17280,-31504"> <v:textbox> <![if !mso]> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td><![endif]> <div> <p class=MsoNormal style='text-indent:0cm;mso-char-indent-count:0'><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman"'>关联实体</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> <o:callout v:ext="edit" minusx="t"/> </v:shape><v:shape id="_x0000_s1034" type="#_x0000_t48" style='position:absolute; left:6597;top:13339;width:1200;height:506' adj="-2790,-19380,-2448,7684,-2160,7684,-42750,-221080"> <v:textbox> <![if !mso]> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td><![endif]> <div> <p class=MsoNormal style='text-indent:0cm;mso-char-indent-count:0'><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman"'>关联连接</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> </v:shape></v:group><![endif]--><!-- [if !vml]--> <!-- [endif]-->界面图标说明

<!-- [if gte vml 1]><v:shape id="_x0000_s1035" type="#_x0000_t48" style='position:absolute;left:0;text-align:left; margin-left:36pt;margin-top:11.9pt;width:30pt;height:25.3pt;text-indent:0; z-index:2' adj="76680,35474,51120,7684,25920,7684,17280,93742"> <v:textbox> <![if !mso]> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td><![endif]> <div> <p class=MsoNormal style='text-indent:0cm;mso-char-indent-count:0'><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman"'>包</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> <o:callout v:ext="edit" minusx="t" minusy="t"/> </v:shape><![endif]--><!-- [if !vml]-->

<!-- [endif]-->  

 

 

<!-- [if gte vml 1]><v:shape id="_x0000_i1047" type="#_x0000_t75" style='width:415.5pt;height:22.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image011.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

 

 

 

<!-- [if !supportLists]-->4.3 <!-- [endif]-->模型设置

执行“ Tools/Model Options ”,在弹出窗口中选择 Model Options ,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1054" type="#_x0000_t75" style='width:414.75pt;height:317.25pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image013.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

其中的主要选项说明:

<!-- [if !supportLists]-->l         <!-- [endif]-->Name/Code case sensitiveName/Code 栏区分大小写。

<!-- [if !supportLists]-->l         <!-- [endif]-->Notation :实体间关系的几种不同图形表示方式。建议统一选择 E/R+Merise 方式。

<!-- [if !supportLists]-->4.4 <!-- [endif]-->设置图元

执行“ Tools/Display Preferences ”,弹出如下窗口:

<!-- [if gte vml 1]><v:shape id="_x0000_i1055" type="#_x0000_t75" style='width:415.5pt;height:306pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image015.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

Object View 中可设置各对象需要显示的内容,在 Format 中可设置显示的图形样式。

 

<!-- [if !supportLists]-->4.5 <!-- [endif]-->新建一个概念模型

点击 New 按钮,在弹出窗口中选择 Conceptual Data Model ,给出模型名称,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1056" type="#_x0000_t75" style='width:415.5pt;height:220.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image017.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

确定后即进入概念模型编辑界面。

<!-- [if !supportLists]-->4.6 <!-- [endif]-->建立域

执行菜单“ Model/Domains ”,即弹出域列表窗口,在此窗口中增加《数据库设计规范》中的域定义,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1057" type="#_x0000_t75" style='width:388.5pt;height:246pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image019.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

 

<!-- [if !supportLists]-->4.7 <!-- [endif]-->建立实体 / 关系图

<!-- [if !supportLists]-->4.7.1 <!-- [endif]-->建立包

在开始建立实体关系图前,我们先按照分类或者模块建立包。建立包的好处是便于分类存放实体,增加模型的可读性。

不要在一个图上画过多的实体及关系,这样会大大降低 E/R 图的易读性;也不要在一个图上画多页实体及关系,因为在生成文档时,系统是把一个图处理成一个图片,如果一个图上有很多页,生成图片上的实体图就会小到看不清楚。尽量在一个图上只画一页。

我们把组织机构模型分成三个包:组织机构信息,人员信息,字典数据。组织机构信息包存放组织机构的实体关系图,人员信息包存放人员的实体关系图,字典数据包存放所有的类别实体。

<!-- [if !supportLists]-->4.7.2 <!-- [endif]-->关系图元说明

关系图元含义如下:

<!-- [if gte vml 1]><v:shape id="_x0000_i1058" type="#_x0000_t75" style='width:152.25pt;height:41.25pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image021.emz" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]--> :一对多关系。一个实体 A 对应 0 到多个实体 B ,一个实体 B 对应 01 个实体 A 。对应到物理模型, A 的主键作为 B 的外键,可为空。

<!-- [if gte vml 1]><v:shape id="_x0000_i1059" type="#_x0000_t75" style='width:152.25pt;height:41.25pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image023.emz" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]--> :强制一对多关系。一个实体 A 对应 0 到多个实体 B ,一个实体 B 必须对应一个实体 A 。对应到物理模型, A 的主键作为 B 的外键,不能为空。

<!-- [if gte vml 1]><v:shape id="_x0000_i1060" type="#_x0000_t75" style='width:152.25pt;height:41.25pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image025.emz" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]--> :依赖关系。实体 B 依赖实体 A 而存在,即存在实体 A 不一定存在实体 B ,不存在实体 A 肯定不存在实体 B 。对应到物理模型, A 的主键作为 B 的主键之一,不能为空。

<!-- [if !supportLists]-->4.7.3 <!-- [endif]-->建立图

假设我们建立的组织机构模型要满足如下要求:

<!-- [if !supportLists]-->1.         <!-- [endif]-->有多个同级别不同行业的组织机构,有的组织机构可能跨多个行业;

<!-- [if !supportLists]-->2.         <!-- [endif]-->各组织机构的子机构层数不尽相同;

<!-- [if !supportLists]-->3.         <!-- [endif]-->组织机构的类型可能不同;

<!-- [if !supportLists]-->4.         <!-- [endif]-->组织机构所处的行政区域不尽相同。

我们在组织机构信息包中初步建立的 E/R 图如下:

<!-- [if gte vml 1]><v:shape id="_x0000_i1061" type="#_x0000_t75" style='width:415.5pt;height:132pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image027.emz" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

在这个 E/R 图中,我们只是从上面的描述中识别出实体和实体间的关系。因组织机构和行业是多对多的关系,图中的“组织机构的行业”即是组织机构和行业间的关联实体。

建立初步的 E/R 图后,我们再检查各实体及实体间的关系。如果要对一个关系做小的调整,双击该关系,弹出关系属性窗口,切换到 cardinalities 页,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1062" type="#_x0000_t75" style='width:391.5pt;height:354pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image029.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

在此页面上即可调整关系。

建议: 在建立、修改 E/R 图的过程中,不要急于输入实体、实体属性的 code 栏内容,也不要急于确定实体属性的数据类型。因为我们在整个建模过程中,会不断增加、删除实体及实体的属性,如果一开始就先给 code 栏输入内容,会增加我们的工作量。等到 E/R 图定型后,再根据《数据库设计规范》要求一次性输入 code 栏内容、确定实体属性的数据类型。

<!-- [if !supportLists]-->4.7.4 <!-- [endif]-->使用另一个包中的实体

假设人员信息有如下要求:

<!-- [if !supportLists]-->1.         <!-- [endif]-->一个人员必须且只能属于一个组织机构;

<!-- [if !supportLists]-->2.         <!-- [endif]-->一个人员可能会有一个职称。

我们在人员信息包中建人员模型时,就需要用到组织机构信息包中的组织机构实体。 Powerdesigner 提供了 Paste as Shourcut 功能(快捷键 Ctrl+K )来满足这个操作要求。先在组织机构实体上按 copy (快捷键 Ctrl+C ),然后回到人员信息包中的图上按 Paste as Shourcut 功能(快捷键 Ctrl+K )。最后建模的结果如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1063" type="#_x0000_t75" style='width:347.25pt;height:49.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image031.emz" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

在组织机构名称下面注明其来源于组织机构信息包,在左下角有个快捷符号。

有的机构中,一个人员可能会在多个部门任职,这种情况在政府机构中比较常见。我们上面的人员信息模型就无法满足这种要求,需要改成下面这个模型了:

<!-- [if gte vml 1]><v:shape id="_x0000_i1064" type="#_x0000_t75" style='width:341.25pt;height:49.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image033.emz" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

<!-- [if !supportLists]-->4.7.5 <!-- [endif]-->完善设计

在实体及实体关系基本确定后,我们就需要完善各实体的具体内容了。有的人习惯在建实体时就把实体的所有属性都录入进去,这也没什么问题。

在前面的 E/R 图中,我们只给出了实体少量属性,这显然是远远不够的。前面之所以这样做,是因为我们想把精力和工作重点放在识别实体和实体关系上。现在我们就需要补充实体的属性了。要补充的属性包括如下几方面:

<!-- [if !supportLists]-->1.         <!-- [endif]-->实体本来具有的属性;

<!-- [if !supportLists]-->2.         <!-- [endif]-->基于设计考虑要添加的属性;

<!-- [if !supportLists]-->3.         <!-- [endif]-->《数据库设计规范》中要求添加的属性。

建议

<!-- [if !supportLists]-->1.         <!-- [endif]-->对同一个实体,设计时的视角不同,系统的要求不同,所需要的实体属性也就不同。尽量不要引入当前系统不需要的属性。

<!-- [if !supportLists]-->2.         <!-- [endif]-->尽量多写注释,尤其是一些不容易理解的实体和属性,更应该写上注释。因为设计人员明白的实体和属性,其他人员未必能够明白。或者自己设计时明白了,过了一段时间后可能又忘了。

小技巧 :在建模时为了方便,我们直接在各包中画需要的字典实体。模型稳定后,再按住各字典实体,拖到字典数据包中。被拖走字典实体的组织结构模型如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1065" type="#_x0000_t75" style='width:415.5pt;height:138pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image035.emz" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

说明 :本指南中就不完善各实体的属性了,有兴趣的同事可以去补充完善。

<!-- [if !supportLists]-->4.7.6 <!-- [endif]-->确定编码和数据类型

前面的工作完成后,这一步的工作就比较简单了。按照《数据库设计规范》,输入实体、属性的 Code ,选择实体的数据类型就行了。

选择实体的数据类型时,优先使用前面定义的域,域中没有需要的数据类型时,再自己选择数据类型。

双击一个实体,然后切换到 Attributes 页,就是属性的编码和数据类型编辑界面了,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1066" type="#_x0000_t75" style='width:390.75pt;height:279.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image037.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

上图中三个选择列的意思如下:

<!-- [if !supportLists]-->l         <!-- [endif]-->M :强制。选上该项后,即表示该属性的值不能为空。

<!-- [if !supportLists]-->l         <!-- [endif]-->P :主键。这个就不用解释了。

<!-- [if !supportLists]-->l         <!-- [endif]-->D :显示。如果不选该项,即表示该属性不需要显示。这个主要是针对 C/S 结构设计的,使用默认值就行了。

当我们选择域后,该域的数据类型就自动显示在属性的数据类型列了。

<!-- [if !supportLists]-->4.8 <!-- [endif]-->检查

Powerdesigner 提供的 Check Model 功能可帮助我们找出、改正设计模型中的错误和疏漏。执行“ Tools/Check Model ”,弹出如下窗口:

<!-- [if gte vml 1]><v:shape id="_x0000_i1035" type="#_x0000_t75" style='width:352.5pt;height:279.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image039.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

在“ Options ”页选择要检查的项目,在“ Selection ”页选择要检查的内容,然后确定, Powerdesinger 就开始检查并把检查结果显示出来。

建议 :在生成物理模型前一定要执行检查功能。检查结果中没有错误,最好也没有警告后才生成物理模型。

<!-- [if !supportLists]-->4.9 <!-- [endif]-->生成物理模型

完成前面各步骤的工作,通过检查后,就可以生成物理模型了。

执行“ Tools/Generate Physical Data Model ”,弹出如下窗口:

<!-- [if gte vml 1]><v:shape id="_x0000_i1067" type="#_x0000_t75" style='width:352.5pt;height:297.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image041.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

General 页上有“生成新的物理模型”、“修改存在的物理模型”选项。

生成新的物理模型:选择物理模型使用的数据库,给出物理模型的 NameCode (都有默认值)。

修改存在的物理模型:系统会先进行差异比较,并把比较结果显示出来,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1068" type="#_x0000_t75" style='width:415.5pt;height:333.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image043.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

上图中的“性别”是概念模型有而存在的物理模型中没有的,用户可以选择是否生成到物理模型中。

<!-- [if !supportLists]-->4.10 <!-- [endif]-->生成报表

Powerdesigner 提供了比较方便的报表模板定制和报表生成功能。

用好这个功能,以后就不用再辛苦的写数据库设计文档,直接根据建好的模型生成数据库设计文档就行了。

<!-- [if !supportLists]-->4.10.1 <!-- [endif]-->定制报表模板

执行“ Report/Report Templates ”,弹出如下窗口:

<!-- [if gte vml 1]><v:shape id="_x0000_i1069" type="#_x0000_t75" style='width:235.5pt;height:249.75pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image045.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

Powerdesigner 提供了几种报表模板,如果觉得不合适,可以点击上图中的新建按钮来创建一个新的报表模板,也可以修改现有的模板。

Powerdesigner 报表模板定制不仅能定制段内容,还能定制表格列、列的标题、列宽、字体。

<!-- [if !supportLists]-->4.10.2 <!-- [endif]-->生成报表

执行“ Report/Generate Report ”,弹出如下窗口:

<!-- [if gte vml 1]><v:shape id="_x0000_i1042" type="#_x0000_t75" style='width:267.75pt;height:251.25pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image047.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

选择报表模板,生成报表的格式和保存路径,就可以生成报表了。

<!-- [if !supportLists]-->5. <!-- [endif]-->设计物理模型

<!-- [if !supportLists]-->5.1 <!-- [endif]-->界面图标说明

<!-- [if gte vml 1]><v:group id="_x0000_s1036" style='position:absolute;left:0;text-align:left;margin-left:42pt;margin-top:4.4pt; width:342pt;height:106.8pt;z-index:3' coordorigin="2637,2907" coordsize="6840,2136"> <v:shape id="_x0000_s1037" type="#_x0000_t48" style='position:absolute;left:2637; top:4537;width:840;height:506' adj="67114,-22667,45746,7684,24686,7684,9257,20874"> <v:textbox> <![if !mso]> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td><![endif]> <div> <p class=MsoNormal style='text-indent:0cm;mso-char-indent-count:0'><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman"'>表</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> <o:callout v:ext="edit" minusx="t"/> </v:shape><v:shape id="_x0000_s1038" type="#_x0000_t48" style='position:absolute; left:2997;top:2907;width:1200;height:506' adj="45900,38718,34578,7684,23760,7684,15120,27832"> <v:textbox> <![if !mso]> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td><![endif]> <div> <p class=MsoNormal style='text-indent:0cm;mso-char-indent-count:0'><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman"'>视图</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> <o:callout v:ext="edit" minusx="t" minusy="t"/> </v:shape><v:shape id="_x0000_s1039" type="#_x0000_t48" style='position:absolute; left:8277;top:2907;width:1200;height:506' adj="-41310,41919,-21510,7684,-2160,7684,-75600,38077"> <v:textbox> <![if !mso]> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td><![endif]> <div> <p class=MsoNormal style='text-indent:0cm;mso-char-indent-count:0'><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman"'>关联关系</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> <o:callout v:ext="edit" minusy="t"/> </v:shape><v:shape id="_x0000_s1040" type="#_x0000_t48" style='position:absolute; left:4797;top:4537;width:1200;height:506' adj="26190,-21258,24894,7684,23760,7684,-17280,-31504"> <v:textbox> <![if !mso]> <table cellpadding=0 cellspacing=0 width="100%"> <tr> <td><![endif]> <div> <p class=MsoNormal style='text-indent:0cm;mso-char-indent-count:0'><span style='font-family:宋体;mso-ascii-font-family:"Times New Roman";mso-hansi-font-family: "Times New Roman"'>存储过程</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> <o:callout v:ext="edit" minusx="t"/> </v:shape></v:group><![endif]--><!-- [if !vml]-->

<!-- [endif]-->  

 

 

<!-- [if gte vml 1]><v:shape id="_x0000_i1026" type="#_x0000_t75" style='width:415.5pt;height:21pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image050.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

 

 

 

<!-- [if !supportLists]-->5.2 <!-- [endif]-->模型设置

执行“ Tools/Model Options ”,在弹出窗口中选择 Model Settings ,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1025" type="#_x0000_t75" style='width:414.75pt;height:336pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image052.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

其中的主要选项说明:

<!-- [if !supportLists]-->l         <!-- [endif]-->Name/Code case sensitiveName/Code 栏区分大小写。

<!-- [if !supportLists]-->l         <!-- [endif]-->Notation :表间关系的几种不同图形表示方式。建议统一选择 CODASYL 方式。

<!-- [if !supportLists]-->5.3 <!-- [endif]-->设置图元

执行“ Tools/Display Preferences ”,弹出如下窗口:

<!-- [if gte vml 1]><v:shape id="_x0000_i1027" type="#_x0000_t75" style='width:415.5pt;height:306pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image054.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

Object View 中可设置各对象需要显示的内容,在 Format 中可设置显示的图形样式。

<!-- [if !supportLists]-->5.4 <!-- [endif]-->新建一个物理模型

点击 New 按钮,在弹出窗口中选择 Conceptual Data Model ,给出模型名称,选择数据库类型,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1028" type="#_x0000_t75" style='width:415.5pt;height:220.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image056.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

确定后即进入概念模型编辑界面。

<!-- [if !supportLists]-->5.5 <!-- [endif]-->建立表及表关联

与概念数据模型中不同,在物理模型中,当我们建立两个表间的关联关系时,系统会自动把一个表的主键作为另一个表的外键插入到该表中。下图是从概念模型生成的物理模型:

<!-- [if gte vml 1]><v:shape id="_x0000_i1029" type="#_x0000_t75" style='width:414pt;height:143.25pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image058.emz" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

对比一下概念模型:

<!-- [if gte vml 1]><v:shape id="_x0000_i1030" type="#_x0000_t75" style='width:415.5pt;height:138pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image060.emz" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

“组织机构的行业”表生成了复合主键。组织机构表中的自关联关系生成了一个外键,并自动给了个命名,我们可以修改这个命名,使其符合我们的命名规范。

如果是根据已建好的概念模型生成的物理模型,在表及关联上就不需要做什么调整了。

<!-- [if !supportLists]-->5.6 <!-- [endif]-->建立视图

Powerdesigner 建立视图时,需要输入 SQL 语句,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1031" type="#_x0000_t75" style='width:390.75pt;height:310.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image062.png" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

得到的视图显示如下:

<!-- [if gte vml 1]><v:shape id="_x0000_i1033" type="#_x0000_t75" style='width:414pt;height:169.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image064.emz" o:title=""/> </v:shape><![endif]--><!-- [if !vml]--><!-- [endif]-->

奇怪,在我印象中,建视图时只需要把相关表中的字段选择过来,就会自动生成 SQL 语句,怎么 Powerdesigner 还需要输入 SQL 语句呢。

我们还可以在 General 页面设置视图的用途,如下图:

<!-- [if gte vml 1]><v:shape id="_x0000_i1032" type="#_x0000_t75" style='width:390.75pt;height:310.5pt'> <v:imagedata src="file:///C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\msohtml1\01\clip_image066.png" o:title=""/> </v:shape><![endif]--&

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值