如何利用powerdesigner自动生成一个具有外键的数据库

如何利用powerdesigner自动生成一个具有外键的数据库,第1张

Powerdesigner对于一个刚开始接触的人,需要知道和了解的是 *** 作,只有 *** 作会了才会慢慢理解其中含义,而不是一来就讲发展背景,原理等等一大堆,后来也记不住,先把 *** 作记清楚了,这些含义和原理会再不断的学习中显现出来,那时候再深究就会很深刻。

第一步:建立模型

clip_image002

第二步,选择物理模型进行创建工作空间

clip_image004

第三:生成后的工作空间:

clip_image006

第四步,简单了解工具栏中的相关工具 *** 作

clip_image008

第五步,实际建立一个空表

clip_image010

第六步:在表中放入表名

clip_image012

第七步:在表中放入相应的字段名,数据类型,字段长,主外键

clip_image014

最后按确定即可完成一个表。

第八步:继续建立一个表,步骤和之前一样

clip_image016

第九步:将两个表关联起来,通过工具中的关系进行自动生成外键

clip_image018

第十步:生成外键之后的物理模型图

clip_image020

第十一步:生成数据库

clip_image022

第十二步:生成数据库时的一些数据库文件名和路径的编辑

clip_image024

第十三:数据库文件生成完毕。

clip_image026

桌面上会出现这样一份文件:

clip_image028

将数据库文件右击txt打开时会看到sql语句:

/*==============================================================*/

/* DBMS name: Sybase SQL Anywhere 11 */

/* Created on: 2012/4/20 9:57:13 */

/*==============================================================*/

if exists(select 1 from sys.sysforeignkey where role=’FK_CLASS_REFERENCE_USER’) then

alter table class

delete foreign key FK_CLASS_REFERENCE_USER

end if

if exists(

select 1 from sys.systable

where table_name=’class’

and table_type in (‘BASE’, ‘GBL TEMP’)

) then

drop table class

end if

if exists(

select 1 from sys.systable

where table_name=’user’

and table_type in (‘BASE’, ‘GBL TEMP’)

) then

drop table "user"

end if

/*==============================================================*/

/* Table: class */

/*==============================================================*/

create table class

(

class_id varchar(64) not null,

class_name varchar(64) null,

user_id varchar(64) null,

constraint PK_CLASS primary key clustered (class_id)

)

comment on column class.class_id is

‘班级ID’

comment on column class.class_name is

‘班级名’

comment on column class.user_id is

‘用户ID’

/*==============================================================*/

/* Table: "user" */

/*==============================================================*/

create table "user"

(

user_id varchar(64) not null,

user_name varchar(64) null,

password varchar(64) null,

constraint PK_USER primary key clustered (user_id)

)

comment on column "user".user_id is

‘用户ID’

comment on column "user".user_name is

‘用户名’

comment on column "user".password is

‘密码’

alter table class

add constraint FK_CLASS_REFERENCE_USER foreign key (user_id)

references "user" (user_id)

on update restrict

on delete restrict

至此,如何利用powerdesigner自动生成,建立一个具有外键的数据库 *** 作就完成了!

转载,仅供参考。

powerdesigner中取消外键的方法

用powerdesigner打开pdm模型,可以看到没有连接关系的表图形展示,并且在表属性中看到外键复选框被选中。

点击工具-model options选项菜单 ,进入perference选项界面,取消选中auto-migrate columns复选框,点击确认。

点击模型-perference菜单,打开list of perferences窗口,可以看到当前模型界面的外键关联列表信息。

选中外键列表记录,点击删除图标按钮删除外键关联列,关闭窗口后,可以在模型图形展示区域看到外键标识已消失。

CDM的话先建立好相应的表格,Palette面板上有个Relationship的图标,单击它,然后在相关的两个表之间,在一个表上单击,注意不要松开鼠标,拖至第二个表上松开,就会在两个表之间产生一条线,表示这这个表之间有了主外键关联.


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11757427.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存