数据库设计——foodblog论坛

一、背景

a)概述

随着时代的发展,交友方式多种多样,交友平台也多种多样。无论是在贴吧,还是各种论坛都可以根据自己的兴趣来结实更多的朋友。

本项目在于开发一个基于美食的交友社区,在社区中,每个人可以发布关于美食的blog,以及美食的照片,类似于一个blog的社区。

b) 基本功能

系统主要完成以下几方面的功能:

  • 用户管理:用户的的基本信息

    • 包括两种类型:用户普通用户和大厨用户

    • 普通用户可以发表博客、评论,只有大厨用户可以开设教学班级

  • 博文管理:用户可以在网站中发表、修改博文、点赞等

  • 评论管理:用户可以评论博文和回复其他用户的评论(一级评论和多级评论)。

  • 分类管理:给博客设置分类

  • 大厨教学班级管理:包括班级的创立和结束,以及班级的ID,密码,班级简介,和班级地址等基本信息

  • 用户间好友和关注管理

  • 垃圾分类搜索:所用用户均可进行垃圾分类的搜索

    • 每一种垃圾有且只能属于一种类型(可回收、其他垃圾、有害垃圾、厨余垃圾)

二、设计


a)ER图

如下:

(使用visio作图)

在这里插入图片描述

b)关系模型

注:带下划线的为主键,蓝色字体为外键

user(ID, user_name, user_registered, user_email, user_pass, user_birthday, gender)

friend(ID1,ID2,application_time)

follow(ID1,ID2,follow_time)

chef_user(ID, chef_id,user_name, user_registered, user_email, user_pass, user_birthday, gender,chef_time,experience)

build_class(ID,chef_id,class_id,build_class_time)

class(class_id,class_name,class_url,class_pass,class_info,class_endtime)

publish_blog(blog_id,ID,publish_time)

blog(blog_id,blog_category_id,blog_title,blog_excerpt,blog_content,blog_modified,browse_volume,praise_point)

blog_category(blog_category_id,blog_category_name,blog_category_description)

comment(comment_id,ID,blog_id,blog_id,comment_content,comment_time)

multi_comment(comment_id,multi_comment_id,ID,multi_comment_content,multi_comment_time)

search(garbage_id,ID,search_time)

garbage(garbage_id,garbage_category_id,garbage_img,garbage_description,garbage_name)

garbage_category(garbage_category_id,garbage_category_name,garbage_category_description)

c)SQL语句

create table blog_category

(

blog_category_id smallint not null,

blog_category_name varchar(15) not null,

blog_category_description text not null,

primary key (blog_category_id)

);

create table blog

(

blog_id bigint not null,

blog_category_id smallint references blog_category (blog_category_id),

blog_title text not null,

blog_excerpt text,

blog_content text not null,

blog_modified datetime not null,

browse_volume int,

praise_point smallint,

primary key (blog_id),

);

create table user

(

ID bigint not null,

user_name varchar(20) not null,

user_registered datetime not null,

user_email varchar(50) not null,

user_pass varchar(20) not null,

user_birthday date,

gender bool not null,

primary key (ID)

);

create table follow

(

ID1 bigint  references user (ID),

ID2 bigint  references user (ID),

follow_time datetime not null,

primary key (ID1, ID2),

);

create table friend

(

ID1 bigint  references user (ID),

ID2 bigint  references user (ID),

application_time datetime not null,

primary key (ID1, ID2),

);

create table publish_blog

(

blog_id bigint  references blog (blog_id),

ID bigint  references user(ID),

publish_time datetime not null,

primary key (blog_id, ID),

);

create table chef_users

(

ID bigint  references user (ID),

chef_id int not null,

chef_time smallint not null,

experience text not null,

user_name varchar(20) not null,

user_registered datetime not null,

user_email varchar(50) not null,

user_pass varchar(20) not null,

user_birthday date,

gender bool not null,

primary key (ID, chef_id));

create table class

(

class_id int not null,

class_name text not null,

class_url varchar(100) not null,

class_pass varchar(20) not null,

class_info text not null,

class_end_time datetime not null,

primary key (class_id),

);

create table build_class

(

ID bigint.

chef_id int,

class_id int  references class (class_id),

build_class_time datetime not null,

primary key (ID, chef_id, class_id),
foreign key(ID,chef_id) references chef_users(ID,chef_id),

);

create table comment

(

comment_id bigint not null,

ID bigint  references user (ID),

blog_id bigint references blog (blog_id),

comment_content text not null,

comment_time datetime not null,

primary key (comment_id),

);

create table multi_comment

(

comment_id int  references comment (comment_id),

multi_comment_id smallint not null,

ID bigint  references user (ID),

mutil_comment_content text not null,

multi_comment_time datetime,

primary key (comment_id, multi_comment_id),

);

create table garbage_catgory

(

garbage_catgory_id smallint not null,

garbage_catgory_name text not null,

garbage_category_description text not null,

primary key (garbage_catgory_id),

);

create table garbage

(

garbage_id int not null,

garbage_catgory_id smallint references garbage_catgory (garbage_catgory_id),

garbage_img longblob,

garbage_description text,

garbage_name varchar(25) not null,

primary key (garbage_id),

);

create table search

(

garbage_id int  references garbage (garbage_id),

ID bigint  references user (ID),

search_time datetime not null,

primary key (garbage_id, ID),

);

三、Power Designer

a)ER图

在这里插入图片描述

b)关系模式

在这里插入图片描述

c)生成SQL

/*==============================================================*/
/* DBMS name:      MySQL 5.0                                    */
/* Created on:     2020-04-05 20:51:54                          */
/*==============================================================*/


drop index setting_FK on blog;

drop table if exists blog;

drop table if exists blog_category;

drop table if exists build_class;

drop table if exists chef_users;

drop table if exists class;

drop table if exists comment;

drop table if exists follow;

drop table if exists friend;

drop table if exists garbage;

drop table if exists garbage_catgory;

drop table if exists multi_comment;

drop table if exists publish_blog;

drop table if exists search;

drop table if exists user;

/*==============================================================*/
/* Table: blog_category                                         */
/*==============================================================*/
create table blog_category
(
   blog_category_id     smallint not null,
   blog_category_name   varchar(15) not null,
   blog_category_description text not null,
   primary key (blog_category_id)
);

/*==============================================================*/
/* Table: blog                                                  */
/*==============================================================*/
create table blog
(
   blog_id              bigint not null,
   blog_category_id     smallint,
   blog_title           text not null,
   blog_excerpt         text,
   blog_content         text not null,
   blog_modified        datetime not null,
   browse_volume        int,
   praise_point         smallint,
   primary key (blog_id),
   constraint FK_setting foreign key (blog_category_id)
      references blog_category (blog_category_id) on delete restrict on update restrict
);

/*==============================================================*/
/* Index: setting_FK                                            */
/*==============================================================*/
create index setting_FK on blog
(
   
);

/*==============================================================*/
/* Table: user                                                  */
/*==============================================================*/
create table user
(
   ID                   bigint not null,
   user_name            varchar(20) not null,
   user_registered      datetime not null,
   user_email           varchar(50) not null,
   user_pass            varchar(20) not null,
   user_birthday        date,
   gender               bool not null,
   primary key (ID)
);

/*==============================================================*/
/* Table: chef_users                                            */
/*==============================================================*/
create table chef_users
(
   ID                   bigint not null,
   chef_id              int not null,
   chef_time            smallint not null,
   experience           text not null,
   user_name            varchar(20) not null,
   user_registered      datetime not null,
   user_email           varchar(50) not null,
   user_pass            varchar(20) not null,
   user_birthday        date,
   gender               bool not null,
   primary key (ID, chef_id),
   constraint FK_Inheritance_1 foreign key (ID)
      references user (ID) on delete restrict on update restrict
);

/*==============================================================*/
/* Table: class                                                 */
/*==============================================================*/
create table class
(
   class_id             int not null,
   class_name           text not null,
   class_url            varchar(100) not null,
   class_pass           varchar(20) not null,
   class_info           text not null,
   class_end_time       datetime not null,
   primary key (class_id)
);

/*==============================================================*/
/* Table: build_class                                           */
/*==============================================================*/
create table build_class
(
   ID                   bigint not null,
   chef_id              int not null,
   class_id             int not null,
   build_class_time     datetime not null,
   primary key (ID, chef_id, class_id),
   constraint FK_build_class foreign key (ID, chef_id)
      references chef_users (ID, chef_id) on delete restrict on update restrict,
   constraint FK_build_class2 foreign key (class_id)
      references class (class_id) on delete restrict on update restrict
);

/*==============================================================*/
/* Table: comment                                               */
/*==============================================================*/
create table comment
(
   comment_id           bigint not null,
   ID                   bigint not null,
   blog_id              bigint,
   comment_content      text not null,
   comment_time         datetime not null,
   primary key (comment_id),
   constraint FK_belong_comment_blog foreign key (blog_id)
      references blog (blog_id) on delete restrict on update restrict,
   constraint FK_publish_comment foreign key (ID)
      references user (ID) on delete restrict on update restrict
);

/*==============================================================*/
/* Table: follow                                                */
/*==============================================================*/
create table follow
(
   ID                   bigint not null,
   use_ID               bigint not null,
   follow_time          datetime not null,
   primary key (ID, use_ID),
   constraint FK_follow foreign key (ID)
      references user (ID) on delete restrict on update restrict,
   constraint FK_follow2 foreign key (use_ID)
      references user (ID) on delete restrict on update restrict
);

/*==============================================================*/
/* Table: friend                                                */
/*==============================================================*/
create table friend
(
   use_ID               bigint not null,
   ID                   bigint not null,
   application_time     datetime not null,
   primary key (use_ID, ID),
   constraint FK_friend foreign key (use_ID)
      references user (ID) on delete restrict on update restrict,
   constraint FK_friend2 foreign key (ID)
      references user (ID) on delete restrict on update restrict
);

/*==============================================================*/
/* Table: garbage_catgory                                       */
/*==============================================================*/
create table garbage_catgory
(
   garbage_catgory_id   smallint not null,
   garbage_catgory_name text not null,
   garbage_category_description text not null,
   primary key (garbage_catgory_id)
);

/*==============================================================*/
/* Table: garbage                                               */
/*==============================================================*/
create table garbage
(
   garbage_id           int not null,
   garbage_catgory_id   smallint not null,
   garbage_img          longblob,
   garbage_description  text,
   garbage_name         varchar(25) not null,
   primary key (garbage_id),
   constraint FK_belong foreign key (garbage_catgory_id)
      references garbage_catgory (garbage_catgory_id) on delete restrict on update restrict
);

/*==============================================================*/
/* Table: multi_comment                                         */
/*==============================================================*/
create table multi_comment
(
   comment_id           bigint not null,
   multi_comment_id     smallint not null,
   ID                   bigint not null,
   mutil_comment_content text not null,
   multi_comment_time   datetime,
   primary key (comment_id, multi_comment_id),
   constraint FK_belong_comment_multicomt foreign key (comment_id)
      references comment (comment_id) on delete restrict on update restrict,
   constraint FK_publish_multi_comment foreign key (ID)
      references user (ID) on delete restrict on update restrict
);

/*==============================================================*/
/* Table: publish_blog                                          */
/*==============================================================*/
create table publish_blog
(
   blog_id              bigint not null,
   ID                   bigint not null,
   publish_time         datetime not null,
   primary key (blog_id, ID),
   constraint FK_publish_blog foreign key (blog_id)
      references blog (blog_id) on delete restrict on update restrict,
   constraint FK_publish_blog2 foreign key (ID)
      references user (ID) on delete restrict on update restrict
);

/*==============================================================*/
/* Table: search                                                */
/*==============================================================*/
create table search
(
   garbage_id           int not null,
   ID                   bigint not null,
   search_time          datetime not null,
   primary key (garbage_id, ID),
   constraint FK_search foreign key (garbage_id)
      references garbage (garbage_id) on delete restrict on update restrict,
   constraint FK_search2 foreign key (ID)
      references user (ID) on delete restrict on update restrict
);


四、总结

如果觉得本文对你们有帮助的话,请给个三连支持一下小编吧~~
在这里插入图片描述

原创文章 48 获赞 111 访问量 8015

猜你喜欢

转载自blog.csdn.net/weixin_44984664/article/details/105715124
今日推荐