Springboot系列 1 - 简单个人博客数据库结构设计

要搭建博客系统,首先要做的就是搭建一个数据库。

我们选择的数据库是MySQL5.7,安装教程请自行百度。

数据库建模工具是PowerDesigner16.6,下载及安装教程也请自行百度。

既然是简单的博客系统,我只简单的建立了几张必要的表(为了保持系统简洁,og表什么暂时不添加了,后期需要再添加),分别为:

sys_user:系统用户表

t_article:文章表

t_content:文章内容表

t_comment:文章评论表

t_category:文章分类表

数据库结构见下图

SQL建表语句

 1 /*==============================================================*/
 2 /* Table: sys_user                                              */
 3 /*==============================================================*/
 4 create table sys_user
 5 (
 6    id                   int not null auto_increment  comment '',
 7    user_name            varchar(20)  comment '',
 8    hashed_password      varchar(50)  comment '',
 9    primary key (id)
10 );
11 
12 /*==============================================================*/
13 /* Table: t_article                                             */
14 /*==============================================================*/
15 create table t_article
16 (
17    id                   int(11) not null auto_increment  comment '',
18    title                varchar(50)  comment '',
19    submit               varchar(300)  comment '',
20    is_top               tinyint  comment '',
21    category_id          int  comment '',
22    create_time          datetime  comment '',
23    modified_time        char(10)  comment '',
24    primary key (id)
25 );
26 
27 /*==============================================================*/
28 /* Table: t_category                                            */
29 /*==============================================================*/
30 create table t_category
31 (
32    id                   int(11) not null auto_increment  comment '',
33    category_name        varchar(50)  comment '',
34    article_number       int  comment '',
35    primary key (id)
36 );
37 
38 /*==============================================================*/
39 /* Table: t_comment                                             */
40 /*==============================================================*/
41 create table t_comment
42 (
43    id                   int(11) not null auto_increment comment '',
44    comment_content      text  comment '',
45    name                 varchar(20)  comment '',
46    email                varchar(50)  comment '',
47    ip_address           varchar(15)  comment '',
48    volt_number          int  comment '',
49    article_id           int(11)  comment '',
50    parent_id            int(11)  comment '',
51    is_auther            tinyint  comment '',
52    primary key (id)
53 );
54 
55 /*==============================================================*/
56 /* Table: t_content                                             */
57 /*==============================================================*/
58 create table t_content
59 (
60    id                   int(11) not null auto_increment comment '',
61    article_id           int(11)  comment '',
62    content              text  comment '',
63    primary key (id)
64 );
65 
66 alter table t_article add constraint FK_T_ARTICL_REFERENCE_T_CATEGO foreign key (category_id)
67       references t_category (id) on delete restrict on update restrict;
68 
69 alter table t_comment add constraint FK_T_COMMEN_REFERENCE_T_ARTICL foreign key (article_id)
70       references t_article (id) on delete restrict on update restrict;
71 
72 alter table t_comment add constraint FK_T_COMMEN_REFERENCE_T_COMMEN foreign key (parent_id)
73       references t_comment (id) on delete restrict on update restrict;
74 
75 alter table t_content add constraint FK_T_CONTEN_REFERENCE_T_ARTICL foreign key (article_id)
76       references t_article (id) on delete restrict on update restrict;

基础工作就到这里了,下一步马上进入我们正式的springboot学习了

猜你喜欢

转载自www.cnblogs.com/dranched/p/9296690.html
今日推荐