1. <!-- [endif]--> 概述
本指南只介紹用 Powerdesigner 設(shè)計概念模型、物理模型及倉庫的使用, Powerdesigner 其它模型的使用不在本指南的介紹范圍。
本指南使用的工具為 Powerdesigner12.5 。因 Powerdesigner 各版本間在概念模型、物理模型設(shè)計操作上的改變不大,本指南對使用其它版本的 Powerdesigner 具有一定的指導(dǎo)作用。
本指南以組織機構(gòu)模型作為實例。
本指南的重點是介紹 Powerdesigner 工具的使用,不介紹建模技術(shù)。
在實際的設(shè)計過程中,不強制要求一定要先建概念模型,再建物理模型。而是根據(jù)個人或項目的要求決定建什么模型。
<!-- [if !supportLists]--> 2. <!-- [endif]--> 術(shù)語
工作區(qū): workspace 。保存當(dāng)前在 Powerdesigner 中使用的模型文件,下次執(zhí)行 Powerdesigner 時,自動把工作區(qū)中的模型文件顯示出來。
域: Domain 。自定義的數(shù)據(jù)類型。
概念模型: Conceptual Data Model 。
物理模型: Physical Data Model 。
倉庫: Repository 。用于保存提交的模型文件,每次提交的模型文件都有一個版本號。方便多人協(xié)同設(shè)計和版本管理。
<!-- [if !supportLists]--> 3. <!-- [endif]--> Powerdesigner 的一些特性應(yīng)用
<!-- [if !supportLists]--> 3.1 <!-- [endif]--> Name 和 Code 的鏡像設(shè)置
Powerdesigner 的每一個對象都包含 name 和 code ,在生成代碼時,使用的是 code , name 是方便我們閱讀。
建議在建模時, name 欄輸入中文, code 欄輸入英文字符,這樣既方便我們閱讀,也方便生成代碼。
默認(rèn)情況下,在 name 欄輸入的內(nèi)容會自動填寫到 code 。如果不希望這樣,可執(zhí)行菜單“ 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]--> 與倉庫的連接設(shè)置
如果需要設(shè)置與倉庫連接的參數(shù),可執(zhí)行“ 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 。在工具條位置單擊鼠標(biāo)右鍵,彈出如下選擇:
<!-- [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 ,在工具條位置就會出現(xiàn)如下圖元排列調(diào)整的工具條:
<!-- [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]--> 設(shè)計概念模型
<!-- [if !supportLists]--> 4.1 <!-- [endif]--> 為什么要建概念模型
概念模型的理論基礎(chǔ)是實體 / 關(guān)系理論,建立的圖形也叫 實體 / 關(guān)系 圖,或者 E/R 圖。我們也可以把 E/R 圖看著是沒有方法、只有屬性的類圖,是類圖的一種特例。 實體 / 關(guān)系 圖能夠使我們在建模時先拋開數(shù)據(jù)庫表設(shè)計的細(xì)節(jié),集中精力把現(xiàn)實世界的實體和關(guān)系轉(zhuǎn)換為 實體 / 關(guān)系 模型,以使我們建立的 實體 / 關(guān)系 模型盡量真實的反映現(xiàn)實世界。
概念模型與使用的數(shù)據(jù)庫無關(guān),當(dāng)我們的系統(tǒng)需要使用不同的數(shù)據(jù)庫系統(tǒng)時,我們就可以使用概念模型生成對應(yīng)該數(shù)據(jù)庫的物理模型,而不需要重新設(shè)計。
<!-- [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"'>實體關(guān)系</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"'>繼承關(guān)系</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"'>關(guān)聯(lián)實體</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"'>關(guān)聯(lián)連接</span></p> </div> <![if !mso]></td> </tr> </table> <![endif]></v:textbox> </v:shape></v:group><![endif]--><!-- [if !vml]-->
<!-- [endif]-->
界面圖標(biāo)說明
<!-- [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]-->
|
?
?
<!-- [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]--> 模型設(shè)置
執(zhí)行“ 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 sensitive : Name/Code 欄區(qū)分大小寫。
<!-- [if !supportLists]--> l ???????? <!-- [endif]--> Notation :實體間關(guān)系的幾種不同圖形表示方式。建議統(tǒng)一選擇 E/R+Merise 方式。
<!-- [if !supportLists]--> 4.4 <!-- [endif]--> 設(shè)置圖元
執(zhí)行“ 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 中可設(shè)置各對象需要顯示的內(nèi)容,在 Format 中可設(shè)置顯示的圖形樣式。
?
<!-- [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]--> 建立域
執(zhí)行菜單“ Model/Domains ”,即彈出域列表窗口,在此窗口中增加《數(shù)據(jù)庫設(shè)計規(guī)范》中的域定義,如下圖:
<!-- [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]--> 建立實體 / 關(guān)系圖
<!-- [if !supportLists]--> 4.7.1 <!-- [endif]--> 建立包
在開始建立實體關(guān)系圖前,我們先按照分類或者模塊建立包。建立包的好處是便于分類存放實體,增加模型的可讀性。
不要在一個圖上畫過多的實體及關(guān)系,這樣會大大降低 E/R 圖的易讀性;也不要在一個圖上畫多頁實體及關(guān)系,因為在生成文檔時,系統(tǒng)是把一個圖處理成一個圖片,如果一個圖上有很多頁,生成圖片上的實體圖就會小到看不清楚。盡量在一個圖上只畫一頁。
我們把組織機構(gòu)模型分成三個包:組織機構(gòu)信息,人員信息,字典數(shù)據(jù)。組織機構(gòu)信息包存放組織機構(gòu)的實體關(guān)系圖,人員信息包存放人員的實體關(guān)系圖,字典數(shù)據(jù)包存放所有的類別實體。
<!-- [if !supportLists]--> 4.7.2 <!-- [endif]--> 關(guān)系圖元說明
關(guān)系圖元含義如下:
<!-- [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]-->
:一對多關(guān)系。一個實體
A
對應(yīng)
0
到多個實體
B
,一個實體
B
對應(yīng)
0
~
1
個實體
A
。對應(yīng)到物理模型,
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]-->
:強制一對多關(guān)系。一個實體
A
對應(yīng)
0
到多個實體
B
,一個實體
B
必須對應(yīng)一個實體
A
。對應(yīng)到物理模型,
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]-->
:依賴關(guān)系。實體
B
依賴實體
A
而存在,即存在實體
A
不一定存在實體
B
,不存在實體
A
肯定不存在實體
B
。對應(yīng)到物理模型,
A
的主鍵作為
B
的主鍵之一,不能為空。
<!-- [if !supportLists]--> 4.7.3 <!-- [endif]--> 建立圖
假設(shè)我們建立的組織機構(gòu)模型要滿足如下要求:
<!-- [if !supportLists]--> 1. ???????? <!-- [endif]--> 有多個同級別不同行業(yè)的組織機構(gòu),有的組織機構(gòu)可能跨多個行業(yè);
<!-- [if !supportLists]--> 2. ???????? <!-- [endif]--> 各組織機構(gòu)的子機構(gòu)層數(shù)不盡相同;
<!-- [if !supportLists]--> 3. ???????? <!-- [endif]--> 組織機構(gòu)的類型可能不同;
<!-- [if !supportLists]--> 4. ???????? <!-- [endif]--> 組織機構(gòu)所處的行政區(qū)域不盡相同。
我們在組織機構(gòu)信息包中初步建立的 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 圖中,我們只是從上面的描述中識別出實體和實體間的關(guān)系。因組織機構(gòu)和行業(yè)是多對多的關(guān)系,圖中的“組織機構(gòu)的行業(yè)”即是組織機構(gòu)和行業(yè)間的關(guān)聯(lián)實體。
建立初步的 E/R 圖后,我們再檢查各實體及實體間的關(guān)系。如果要對一個關(guān)系做小的調(diào)整,雙擊該關(guān)系,彈出關(guān)系屬性窗口,切換到 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]-->
在此頁面上即可調(diào)整關(guān)系。
建議: 在建立、修改 E/R 圖的過程中,不要急于輸入實體、實體屬性的 code 欄內(nèi)容,也不要急于確定實體屬性的數(shù)據(jù)類型。因為我們在整個建模過程中,會不斷增加、刪除實體及實體的屬性,如果一開始就先給 code 欄輸入內(nèi)容,會增加我們的工作量。等到 E/R 圖定型后,再根據(jù)《數(shù)據(jù)庫設(shè)計規(guī)范》要求一次性輸入 code 欄內(nèi)容、確定實體屬性的數(shù)據(jù)類型。
<!-- [if !supportLists]--> 4.7.4 <!-- [endif]--> 使用另一個包中的實體
假設(shè)人員信息有如下要求:
<!-- [if !supportLists]--> 1. ???????? <!-- [endif]--> 一個人員必須且只能屬于一個組織機構(gòu);
<!-- [if !supportLists]--> 2. ???????? <!-- [endif]--> 一個人員可能會有一個職稱。
我們在人員信息包中建人員模型時,就需要用到組織機構(gòu)信息包中的組織機構(gòu)實體。 Powerdesigner 提供了 Paste as Shourcut 功能(快捷鍵 Ctrl+K )來滿足這個操作要求。先在組織機構(gòu)實體上按 copy (快捷鍵 Ctrl+C ),然后回到人員信息包中的圖上按 Paste as Shourcut 功能(快捷鍵 Ctrl+K )。最后建模的結(jié)果如下圖:
<!-- [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]-->
在組織機構(gòu)名稱下面注明其來源于組織機構(gòu)信息包,在左下角有個快捷符號。
有的機構(gòu)中,一個人員可能會在多個部門任職,這種情況在政府機構(gòu)中比較常見。我們上面的人員信息模型就無法滿足這種要求,需要改成下面這個模型了:
<!-- [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]--> 完善設(shè)計
在實體及實體關(guān)系基本確定后,我們就需要完善各實體的具體內(nèi)容了。有的人習(xí)慣在建實體時就把實體的所有屬性都錄入進去,這也沒什么問題。
在前面的 E/R 圖中,我們只給出了實體少量屬性,這顯然是遠(yuǎn)遠(yuǎn)不夠的。前面之所以這樣做,是因為我們想把精力和工作重點放在識別實體和實體關(guān)系上。現(xiàn)在我們就需要補充實體的屬性了。要補充的屬性包括如下幾方面:
<!-- [if !supportLists]--> 1. ???????? <!-- [endif]--> 實體本來具有的屬性;
<!-- [if !supportLists]--> 2. ???????? <!-- [endif]--> 基于設(shè)計考慮要添加的屬性;
<!-- [if !supportLists]--> 3. ???????? <!-- [endif]--> 《數(shù)據(jù)庫設(shè)計規(guī)范》中要求添加的屬性。
建議 :
<!-- [if !supportLists]--> 1. ???????? <!-- [endif]--> 對同一個實體,設(shè)計時的視角不同,系統(tǒng)的要求不同,所需要的實體屬性也就不同。盡量不要引入當(dāng)前系統(tǒng)不需要的屬性。
<!-- [if !supportLists]--> 2. ???????? <!-- [endif]--> 盡量多寫注釋,尤其是一些不容易理解的實體和屬性,更應(yīng)該寫上注釋。因為設(shè)計人員明白的實體和屬性,其他人員未必能夠明白。或者自己設(shè)計時明白了,過了一段時間后可能又忘了。
小技巧 :在建模時為了方便,我們直接在各包中畫需要的字典實體。模型穩(wěn)定后,再按住各字典實體,拖到字典數(shù)據(jù)包中。被拖走字典實體的組織結(jié)構(gòu)模型如下圖:
<!-- [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]--> 確定編碼和數(shù)據(jù)類型
前面的工作完成后,這一步的工作就比較簡單了。按照《數(shù)據(jù)庫設(shè)計規(guī)范》,輸入實體、屬性的 Code ,選擇實體的數(shù)據(jù)類型就行了。
選擇實體的數(shù)據(jù)類型時,優(yōu)先使用前面定義的域,域中沒有需要的數(shù)據(jù)類型時,再自己選擇數(shù)據(jù)類型。
雙擊一個實體,然后切換到 Attributes 頁,就是屬性的編碼和數(shù)據(jù)類型編輯界面了,如下圖:
<!-- [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 結(jié)構(gòu)設(shè)計的,使用默認(rèn)值就行了。
當(dāng)我們選擇域后,該域的數(shù)據(jù)類型就自動顯示在屬性的數(shù)據(jù)類型列了。
<!-- [if !supportLists]--> 4.8 <!-- [endif]--> 檢查
Powerdesigner 提供的 Check Model 功能可幫助我們找出、改正設(shè)計模型中的錯誤和疏漏。執(zhí)行“ 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 ”頁選擇要檢查的內(nèi)容,然后確定, Powerdesinger 就開始檢查并把檢查結(jié)果顯示出來。
建議 :在生成物理模型前一定要執(zhí)行檢查功能。檢查結(jié)果中沒有錯誤,最好也沒有警告后才生成物理模型。
<!-- [if !supportLists]--> 4.9 <!-- [endif]--> 生成物理模型
完成前面各步驟的工作,通過檢查后,就可以生成物理模型了。
執(zhí)行“ 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 頁上有“生成新的物理模型”、“修改存在的物理模型”選項。
生成新的物理模型:選擇物理模型使用的數(shù)據(jù)庫,給出物理模型的 Name 和 Code (都有默認(rèn)值)。
修改存在的物理模型:系統(tǒng)會先進行差異比較,并把比較結(jié)果顯示出來,如下圖:
<!-- [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 提供了比較方便的報表模板定制和報表生成功能。
用好這個功能,以后就不用再辛苦的寫數(shù)據(jù)庫設(shè)計文檔,直接根據(jù)建好的模型生成數(shù)據(jù)庫設(shè)計文檔就行了。
<!-- [if !supportLists]--> 4.10.1 <!-- [endif]--> 定制報表模板
執(zhí)行“ 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 提供了幾種報表模板,如果覺得不合適,可以點擊上圖中的新建按鈕來創(chuàng)建一個新的報表模板,也可以修改現(xiàn)有的模板。
Powerdesigner 報表模板定制不僅能定制段內(nèi)容,還能定制表格列、列的標(biāo)題、列寬、字體。
<!-- [if !supportLists]--> 4.10.2 <!-- [endif]--> 生成報表
執(zhí)行“ 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]--> 設(shè)計物理模型
<!-- [if !supportLists]--> 5.1 <!-- [endif]--> 界面圖標(biāo)說明
<!-- [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"'>關(guān)聯(lián)關(guān)系</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]-->
|
?
?
<!-- [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]--> 模型設(shè)置
執(zhí)行“ 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 sensitive : Name/Code 欄區(qū)分大小寫。
<!-- [if !supportLists]--> l ???????? <!-- [endif]--> Notation :表間關(guān)系的幾種不同圖形表示方式。建議統(tǒng)一選擇 CODASYL 方式。
<!-- [if !supportLists]--> 5.3 <!-- [endif]--> 設(shè)置圖元
執(zhí)行“ 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 中可設(shè)置各對象需要顯示的內(nèi)容,在 Format 中可設(shè)置顯示的圖形樣式。
<!-- [if !supportLists]--> 5.4 <!-- [endif]--> 新建一個物理模型
點擊 New 按鈕,在彈出窗口中選擇 Conceptual Data Model ,給出模型名稱,選擇數(shù)據(jù)庫類型,如下圖:
<!-- [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]--> 建立表及表關(guān)聯(lián)
與概念數(shù)據(jù)模型中不同,在物理模型中,當(dāng)我們建立兩個表間的關(guān)聯(lián)關(guān)系時,系統(tǒng)會自動把一個表的主鍵作為另一個表的外鍵插入到該表中。下圖是從概念模型生成的物理模型:
<!-- [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]-->
“組織機構(gòu)的行業(yè)”表生成了復(fù)合主鍵。組織機構(gòu)表中的自關(guān)聯(lián)關(guān)系生成了一個外鍵,并自動給了個命名,我們可以修改這個命名,使其符合我們的命名規(guī)范。
如果是根據(jù)已建好的概念模型生成的物理模型,在表及關(guān)聯(lián)上就不需要做什么調(diào)整了。
<!-- [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]-->
奇怪,在我印象中,建視圖時只需要把相關(guān)表中的字段選擇過來,就會自動生成 SQL 語句,怎么 Powerdesigner 還需要輸入 SQL 語句呢。
我們還可以在 General 頁面設(shè)置視圖的用途,如下圖:
<!-- [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]--&
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
