一直不是對PowerDesigner很熟悉,近期頻繁筆試,很多都問這個工具,所以今天下午簡單學習了一下。
一、建立概念性模型
1.在File下選擇New中的Conceptual Data Model:
2.在開啟的視圖視窗中使用工具箱中的實體工具建立兩個實體,分別為學生表和班級表:
實體的屬性視窗:
添加屬性:
其中:M:即Mandatory ,強制屬性,表示該屬性必填,不可為空;
P:即Primary Identifer 是否是主標識符,表示實體的唯一識別碼,即主鍵;
D:即Displayed 表示在實體符號中是否顯示。
單擊Data Type下方的方塊按鈕可以選擇資料類型:
使用上面方法建立班級表,結果圖如下:
建立外鍵關係,學生表和班級表是多對一的關係,使用工具箱的關聯建立工具在班級表上單擊並拖到學生表上放開,形成如下的圖:
二、物理模型
單擊功能表列上的Tools菜單中的Check Model來檢查上面的概念性模型的正確性。
如果沒有錯誤存在,則選擇Tools菜單中的Genterate Physical Data Model,出現如下視窗:
我選用的是mysql5.0資料庫,生產結果如下:
我們可以看到在學生表中自動建立了班級表的外鍵。
再來看一下怎麼設定主鍵的自動成長:
雙擊學生表或班級表開啟表屬性視窗,選擇Columns選項卡,在主鍵欄位上雙擊,彈出Columns Properties視窗:
只需選中Identity屬性即可(註:這個必須在物理模型下完成,在概念性模型下是沒有這個選項的,因為不同資料庫的自增長的實現方式是不一樣的)。
三、產生SQL檔案
選擇功能表列中的DataBases菜單中的Grenerate DataBase,彈出如下視窗:
點擊確定,可以看到產生的sql: 1 /*==============================================================*/
2 /* DBMS name: MySQL 5.0 */
3 /* Created on: 2007-6-7 0:27:29 */
4 /*==============================================================*/
5
6
7 drop table if exists Student;
8
9 drop table if exists classes;
10
11 /*==============================================================*/
12 /* Table: Student */
13 /*==============================================================*/
14 create table Student
15 (
16 sid int not null auto_increment,
17 cid int,
18 sname varchar(50) not null,
19 primary key (sid)
20 );
21
22 /*==============================================================*/
23 /* Table: classes */
24 /*==============================================================*/
25 create table classes
26 (
27 cid int not null,
28 cname varchar(50) not null,
29 primary key (cid)
30 );
31
32 alter table Student add constraint FK_Relationship_1 foreign key (cid)
33 references classes (cid) on delete restrict on update restrict;
34
35
這樣就完成了PowerDesigner的簡單應用。
<我的原創,轉載請註明出處!!!>