PowerDesigner--快速创建表模型生成SQL语句

2023-05-16

今天和大家分享一个我常用的设计表模型的工具PowserDesigner

- 选择物理模型

- 创建表、字段、索引等

- 梳理表之间的关系

- 一键生成SQL语句

目录

一、准备工作

二、选择物理模型

​三、创建表、字段等

3.1 创建表

3.2 创建字段

3.2.1 修改表名

3.2.2 设计表字段

四、梳理表之间的关系 

五、一键生成SQL语句

六、结束语


一、准备工作

下载并安装PowerDesigner工具, 链接将在文末给出。需要的自行下载。安装步骤不做详细介绍,没有什么需要注意的点。

二、选择物理模型

打开我们下载好的PD工具,选择文件--->新建模型---->Pyhsical Data---->ok创建我们的表模型。这里我选择是物理模型,可根据项目需求,选择不同的模型进行设计。如下图:

三、创建表、字段等

3.1 创建表

如下图:

3.2 创建字段

3.2.1 修改表名

3.2.2 设计表字段

Name没有什么条件限制,能明白自己这个字段是啥就行,Code用英文,数据类型根据字段设置即可,需要长度的设计值长度, 浮点类型的可以设置几位小数四舍五入。后面的P:主键,F:外键,M:强制。

创建好的效果如图:

四、梳理表之间的关系 

 表与表之间关系即为重要,下面就以我刚才创建的商品表、用户表、商家表这三者之间为例:

分析:

某用户注册进我们的平台,创建一个商家平台,在此商家平台中可以买很多商品。

某商家平台是被某个用户创建,且在此平台中存放着很多商品。

某商品被存放在某个商家平台,且这个商家平台是被某个用户创建。

分析完毕:

翻译成表逻辑为:

用户编号作为用户表中的主键,且作为商家平台的外键

商家编号作为商家表中的主键,且作为商品表中的外键

如下图:

场景:购买商品时

购买的是某用户创建的某商家下的商品,通过主外键关系找到对应数据。  

五、一键生成SQL语句

点击数据库--->生成数据库---->填写保存路径--->ok

 以我写过的项目模型为例:

 生成的SQL语句如下:

/*==============================================================*/
/* DBMS name:      MySQL 5.0                                    */
/* Created on:     2022/6/19 14:47:48                           */
/*==============================================================*/


drop table if exists department;

drop table if exists tb_activity;

drop table if exists tb_apply;

drop table if exists tb_cate;

drop table if exists tb_credit;

drop table if exists tb_evaluate;

drop table if exists tb_feedback;

drop table if exists tb_introduction;

drop table if exists tb_meeting;

drop table if exists tb_notice;

drop table if exists tb_noticecate;

drop table if exists tb_punishment;

drop table if exists tb_registration;

drop table if exists tb_reward;

drop table if exists tb_role;

drop table if exists tb_student;

drop table if exists tb_summary;

drop table if exists tb_system;

drop table if exists tb_university;

/*==============================================================*/
/* Table: department                                            */
/*==============================================================*/
create table department
(
   department_id        integer not null auto_increment,
   name                 varchar(20),
   duty                 varchar(20),
   primary key (department_id)
);

/*==============================================================*/
/* Table: tb_activity                                           */
/*==============================================================*/
create table tb_activity
(
   activity_id          integer not null auto_increment,
   cate_id              integer,
   name                 varchar(20),
   content              varchar(500),
   plan                 text,
   time                 varchar(20),
   primary key (activity_id)
);

/*==============================================================*/
/* Table: tb_apply                                              */
/*==============================================================*/
create table tb_apply
(
   apply_id             integer not null auto_increment,
   department_id        integer,
   student_id           integer,
   name                 varchar(20),
   major                varchar(50),
   grade                varchar(20),
   class                varchar(20),
   content              varchar(50),
   primary key (apply_id)
);

/*==============================================================*/
/* Table: tb_cate                                               */
/*==============================================================*/
create table tb_cate
(
   cate_id              integer not null auto_increment,
   name                 varchar(20),
   primary key (cate_id)
);

/*==============================================================*/
/* Table: tb_credit                                             */
/*==============================================================*/
create table tb_credit
(
   credit_id            integer not null auto_increment,
   student_id           integer,
   reward_id            integer,
   punishment_id        integer,
   registration_id      integer,
   credit               varchar(5),
   primary key (credit_id)
);

/*==============================================================*/
/* Table: tb_evaluate                                           */
/*==============================================================*/
create table tb_evaluate
(
   evaluate_id          integer not null auto_increment,
   student_id           integer,
   tb__student_id       integer,
   content              varchar(100),
   primary key (evaluate_id)
);

/*==============================================================*/
/* Table: tb_feedback                                           */
/*==============================================================*/
create table tb_feedback
(
   feedback_id          integer not null auto_increment,
   student_id           integer,
   content              varchar(100),
   primary key (feedback_id)
);

/*==============================================================*/
/* Table: tb_introduction                                       */
/*==============================================================*/
create table tb_introduction
(
   introduction_id      integer not null auto_increment,
   university_id        integer,
   title                varchar(20),
   content              text,
   primary key (introduction_id)
);

/*==============================================================*/
/* Table: tb_meeting                                            */
/*==============================================================*/
create table tb_meeting
(
   meeting_id           integer not null auto_increment,
   student_id           integer,
   title                varchar(20),
   content              varchar(200),
   primary key (meeting_id)
);

/*==============================================================*/
/* Table: tb_notice                                             */
/*==============================================================*/
create table tb_notice
(
   notice_id            integer not null auto_increment,
   student_id           integer,
   notice_name          varchar(20),
   content              varchar(500),
   primary key (notice_id)
);

/*==============================================================*/
/* Table: tb_noticecate                                         */
/*==============================================================*/
create table tb_noticecate
(
   cate_id              integer not null auto_increment,
   notice_id            integer,
   cate_name            varchar(20),
   primary key (cate_id)
);

/*==============================================================*/
/* Table: tb_punishment                                         */
/*==============================================================*/
create table tb_punishment
(
   punishment_id        integer not null auto_increment,
   student_id           integer,
   content              varchar(50),
   primary key (punishment_id)
);

/*==============================================================*/
/* Table: tb_registration                                       */
/*==============================================================*/
create table tb_registration
(
   registration_id      integer not null auto_increment,
   activity_id          integer,
   student_id           integer,
   name                 varchar(10),
   class                varchar(20),
   sn                   varchar(20),
   primary key (registration_id)
);

/*==============================================================*/
/* Table: tb_reward                                             */
/*==============================================================*/
create table tb_reward
(
   reward_id            integer not null auto_increment,
   student_id           integer,
   activity_id          integer,
   time                 varchar(5),
   prize                varchar(20),
   primary key (reward_id)
);

/*==============================================================*/
/* Table: tb_role                                               */
/*==============================================================*/
create table tb_role
(
   role_id              integer not null auto_increment,
   name                 varc(10),
   primary key (role_id)
);

/*==============================================================*/
/* Table: tb_student                                            */
/*==============================================================*/
create table tb_student
(
   student_id           integer not null auto_increment,
   role_id              integer,
   department_id        integer,
   university_id        integer,
   student_sn           varchar(20),
   pwd                  varchar(20),
   name                 varchar(10),
   sex                  varchar(1),
   major                varchar(50),
   grade                varchar(20),
   class                varchar(50),
   phone                varchar(11),
   primary key (student_id)
);

/*==============================================================*/
/* Table: tb_summary                                            */
/*==============================================================*/
create table tb_summary
(
   summary_id           integer not null auto_increment,
   student_id           integer,
   summary_content      varchar(300),
   summary_time         datetime,
   primary key (summary_id)
);

/*==============================================================*/
/* Table: tb_system                                             */
/*==============================================================*/
create table tb_system
(
   system_id            integer not null auto_increment,
   university_id        integer,
   name                 varchar(20),
   content              text,
   create_time          varchar(20),
   update_time          varchar(20),
   primary key (system_id)
);

/*==============================================================*/
/* Table: tb_university                                         */
/*==============================================================*/
create table tb_university
(
   university_id        integer not null,
   role_id              integer,
   name                 varchar(30),
   phone                varchar(20),
   pwd                  varchar(50),
   primary key (university_id)
);

alter table tb_activity add constraint FK_Reference_11 foreign key (cate_id)
      references tb_cate (cate_id) on delete restrict on update restrict;

alter table tb_apply add constraint FK_Reference_10 foreign key (department_id)
      references department (department_id) on delete restrict on update restrict;

alter table tb_apply add constraint FK_Reference_29 foreign key (student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_credit add constraint FK_Reference_20 foreign key (student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_credit add constraint FK_Reference_23 foreign key (reward_id)
      references tb_reward (reward_id) on delete restrict on update restrict;

alter table tb_credit add constraint FK_Reference_24 foreign key (punishment_id)
      references tb_punishment (punishment_id) on delete restrict on update restrict;

alter table tb_credit add constraint FK_Reference_25 foreign key (registration_id)
      references tb_registration (registration_id) on delete restrict on update restrict;

alter table tb_evaluate add constraint FK_Reference_12 foreign key (student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_evaluate add constraint FK_Reference_13 foreign key (tb__student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_feedback add constraint FK_Reference_18 foreign key (student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_introduction add constraint FK_Reference_28 foreign key (university_id)
      references tb_university (university_id) on delete restrict on update restrict;

alter table tb_meeting add constraint FK_Reference_19 foreign key (student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_notice add constraint FK_Reference_8 foreign key (student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_noticecate add constraint FK_Reference_26 foreign key (notice_id)
      references tb_notice (notice_id) on delete restrict on update restrict;

alter table tb_punishment add constraint FK_Reference_17 foreign key (student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_registration add constraint FK_Reference_21 foreign key (activity_id)
      references tb_activity (activity_id) on delete restrict on update restrict;

alter table tb_registration add constraint FK_Reference_22 foreign key (student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_reward add constraint FK_Reference_15 foreign key (student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_reward add constraint FK_Reference_16 foreign key (activity_id)
      references tb_activity (activity_id) on delete restrict on update restrict;

alter table tb_student add constraint FK_Reference_1 foreign key (role_id)
      references tb_role (role_id) on delete restrict on update restrict;

alter table tb_student add constraint FK_Reference_2 foreign key (department_id)
      references department (department_id) on delete restrict on update restrict;

alter table tb_student add constraint FK_Reference_3 foreign key (university_id)
      references tb_university (university_id) on delete restrict on update restrict;

alter table tb_summary add constraint FK_Reference_14 foreign key (student_id)
      references tb_student (student_id) on delete restrict on update restrict;

alter table tb_system add constraint FK_Reference_27 foreign key (university_id)
      references tb_university (university_id) on delete restrict on update restrict;

alter table tb_university add constraint FK_Reference_4 foreign key (role_id)
      references tb_role (role_id) on delete restrict on update restrict;

有了这些SQL语句之后,我们就可以在我们的编译器上面通过SQL语句,生成我们的表模型。更加方便快捷咯。

六、结束语

PD的基础使用方式就是这样额,感兴趣的朋友还可以去研究一下其他的模型用法,设计出不用的软件项目。喜欢的三连支持。

PD安装包:

链接:https://pan.baidu.com/s/1Kfm9BLzLAm_fmrAJVfzQ0A 
提取码:17h8

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PowerDesigner--快速创建表模型生成SQL语句 的相关文章

  • 学校网络(有向图的强连通分量)

    题目描述 一些学校连接在一个计算机网络上 xff0c 学校之间存在软件支援协议 xff0c 每个学校都有它应支援的学校名单 xff08 学校A支援学校B xff0c 并不表示学校B一定要支援学校A xff09 当某校获得一个新软件时 xff
  • uwsgi+nginx结构下的nginx日志异常

    我的小项目是django 43 uwsgi 43 nginx这样的结构 xff0c nginx的配置如下 xff1a upstream myapp span class hljs built in span test span class
  • 定时器T0赋初值的计算方式

    定时中断初值计算方法是 xff1a 1 确定定时时间化为微妙t 2 晶振频率以MHZ为单位f 3 计算初值 xff1a s 61 65536 tf 12 比如16MHZ晶振 xff0c 定时1毫秒 t 61 11000 61 1000us
  • Ubuntu 17.04更改鼠标移动速度

    升级ubuntu 17 04后发现下面命令不能用来更改鼠标移动速度了 xinput span class hljs subst span span class hljs built in set span span class hljs a
  • 使用 Flask 快速构建 基于langchain 和 chatGPT的 PDF摘要总结

    简介 这里不对 langchain 和 chatGPT 进行介绍 xff0c 仅对实现过程进行整理 环境 Python gt 61 3 8 Flask2 2 3 Jinja23 1 2 langchain0 0 143 openai0 27
  • 汇编语言实现两个任意大的数相加

    实现了输入 xff0c 相加 xff0c 输出功能 xff0c 可在此基础上做出自己的修改 xff0c 代码如下 xff1a DATA SEGMENT MSG1 DB 34 Please Input The First Number 34
  • 十六进制ASCII码表

    xff21 xff33 xff23 xff29 xff29 与 xff11 xff16 进制转换 ASCII 16 进制 ASCII 16 进制 ASCII 16 进制 ASCII 16 进制 NUL 00H DLE 10H SP 20H
  • 以太网数据包TCP、IP、ICMP、UDP、…

    以太网首部 目地MAC地址 xff08 8字节 xff09 源MAC地址 xff08 8字节 xff09 类型 xff08 2字节 xff09 1 IP头的结构 版本 xff08 4位 xff09 头长度 xff08 4位 xff09 服务
  • JPanel无法显示问题

    有两个Panel Panel1 Panel2 Panel1用BorderLayout布局 xff0c Panel2布局为null 也就是自定义布局 xff0c 然后将Panel2 add到Panel1的North区 xff0c 运行时问题就
  • 要求一个语句从study,DICT 表中取出如表三所列格式数据

    问题描述 xff1a 要求一个语句从study xff0c DICT 表中取出如表三所列格式数据 study表 DICT表 表三 答案 xff1a SQL xff1a SELECT Deptname MAX CASE WHEN Mon 61
  • hibernate操作数据库相关注意点

    一 建数据表时 xff0c 若有字段设置了NOTNULL并设置了默认值 xff0c 如果在程序中相应对象中的字段没有赋值 xff0c 是null xff0c 在程序执行插入 xff0c 更新的操作的时候 xff0c 会抛出不能插入的异常 x
  • 欢迎订阅

  • 两个ArrayList做差集效率问题

    工作中需要将表中重复数据只留一条 xff0c 其余删掉 xff0c 第一想法就是用SQL去执行 xff0c 但是由于数据有几十万条 xff0c SQL的效率十分低下 xff0c 于是写个程序去执行 xff0c 也方便看到执行的进度 xff0
  • Python爬取前程无忧职位信息(正则暴力匹配)

    文章目录 写在前面demo主体用到的包初始化变量抓取页数清洗工资数据循环爬取信息保存信息控制函数入口函数 数据可视化存在不足参考文献 写在前面 最近在学习爬虫和数据分析 xff0c 在CSDN看到TRHX 鲍勃的文章 xff0c 受益匪浅
  • 无需部署,python 控制台对话ChatGPT

    简介 很多时候同事想自己使用 Openai 的接口调用完成一些基础操作 但是 xff0c 他们又不能很了解项目如何部署启动 xff0c 所以临时写了一个控制台调用的程序 运行效果 代码 span class token triple quo
  • PC微信逆向--定位sqlite3_exec和数据库句柄

    写在前面 最近在做PC端微信逆向 xff0c 搞定了基本的收发消息 xff0c 通讯录获取等 xff0c 这期间遇到一个小小的问题 xff0c 从通讯录获取到的内容不全 xff0c 除非登录后手动点击过某个好友 xff0c 不然获取不到头像
  • PC微信逆向--调用sqlite3_exec执行SQL

    文章目录 写在前面回顾sqlite3 exec回调函数函数指针编写代码注入的DLL注入程序 输出结果写在后面 写在前面 上一篇文章 xff0c 实现了定位保存微信数据库句柄的容器和微信内部的sqlite3 exec函数地址 xff0c 这一
  • PC微信逆向--定位备份sqlite数据库相关函数

    文章目录 写在前面备份函数编写测试程序配置环境编译 OD调试结果OD地址IDA地址 写在后面 写在前面 上一篇文章 xff0c 介绍了如何使用找到的数据库句柄和sqlite3 exec函数执行SQL xff0c 本篇文章 xff0c 来尝试
  • Windows微信文本压缩算法分析

    文章目录 免责声明写在前面分析过程HEX数据原文 规律总结写在后面2022 12 31补充 免责声明 文章仅供交流学习使用 xff0c 请勿用于非法用途和商业用途 xff0c 如因此产生任何法律纠纷 xff0c 均与作者无关 如您选择继续阅
  • 解析某音X-Bogus参数

    文章目录 写在前面目标正向梳理主要加密函数主要算法解析 逆向梳理结论测试进阶写在后面 写在前面 本文主要介绍从X Bogus还原19位数组的过程 xff0c 方便理解算法 目标 span class token comment 从 span

随机推荐