数据库设计,课设满分作业——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
);


四、总结

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

  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
BBS论坛系统数据库设计 0.后台用户管理(TAB_USER) "序号 "字段名称 "字段英文名 "数据类型"长度"PK(Y/N) "NULL(Y/N)"备注 " "1 "自增ID "id "int " "Y "N " " "2 "用户帐号 "usercode "varchar "20 " "N "登录用 " "3 "姓名 "username "varchar "20 " "N " " "3 "密 码 "pwd "varchar "11 " "N "用MD5加" " " " " " " " "密算法 " "4 "性别 "ssex "varchar "10 " " " " "5 "角色 "role "int " " " " " "6 "Email地址"email "varchar "30 " " " " " " 1.前台用户注册表(TAB_USER_REGISTER) "序号 "字段名称 "字段英文名 "数据类型"长度"PK(Y/N) "NULL(Y/N)"备注 " "1 "自增ID "id "int " "Y "N " " "2 "用户帐号 "usercode "varchar "50 " "N "登录用 " "3 "姓名 "username "varchar "50 " "N " " "3 "密 码 "userpsw "varchar "11 " "N "用MD5加" " " " " " " " "密算法 " "4 "昵称 "nickname "varchar "50 " " " " "5 "头像 "image " " " " " " "6 "Email地址"email "varchar "80 " " " " "7 "验证码 "checkno "bigint "10 " " " " " " 用户发帖表(TAB_USER_SENDCARD) "序号 "字段名称 "字段英文名 "数据类型 "长度"PK(Y/N) "NULL(Y/N)"备注 " "1 "发帖ID "sendcardid "int " "Y "N "自增 " "2 "发帖区ID "sendzoneid "int " " " "参照发 " " " " " " " " "帖区 " "3 "用户帐号 "usercode "varchar "30 " " " " "4 "主题 "title "varchar "200 " "N " " "5 "发帖内容 "cardcontent "varchar "1000" " " " "6 "日期 "date "date " " " " " "7 "验证码 "checkno "bigint " " " " " "发帖ID的值来判断级别。 " 用户跟帖表(TAB_USER_FOLLOWCARD) "序号 "字段名称 "字段英文名 "数据类型"长度"PK(Y/N) "NULL(Y/N)"备注 " "1 "跟帖ID "followcardid "int " "Y "N "自增 " "2 "讨论区ID "discussid "int " " " "参照推 " " " " " " " " "荐讨论 " " " " " " " " "区ID和 " " " " " " " " "技术讨 " " " " " " " " "论区ID " "3 "用户帐号 "usercode "varchar "30 " " " " "4 "发帖ID "sendcardid "int " " " "参照发 " " " " " " " " "帖表sen" " " " " " " " "dcardID" " " " " " " " "(1:n " " " " " " " " ") " "5 "跟帖内容 "followcardconte"varchar "1000" " " " " " "nt " " " " " " "6 "日期 "date "date " " " " " "7 "验证码 "checkno " " " " " " " " 公告管理表(TAB_NOTICEMANAGE ) "序号 "字段名称 "字段英文名 "数据类型"长度"PK(Y/N) "NULL(Y/N)"备注 " "1 "公告ID "noticeid "int " "Y "N "自增 " "2 "公告时间 "noticetime "date " " " " " "3 "公告内容 "content "varchar "200 " "N " " "4 "作者 "author "varchar "50 " " " " "5 "备注 "remark "varchar "100 " " " " " " 推荐讨论区表(TAB_RECOMMANDMANAGE) "序号 "字段名称 "字段英文名 "数据 "长度"PK(
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Joshua_yi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值