个人博客开发之数据库设计
前言
分享完需求,我们就按照需求去设计数据库就可以了,这里我数据库选用
Mysql
原因呢Mysql相对于其他数据库如ORACLE
等轻巧,方便,开源,免费,好用,而且效率也够用
数据库设计
这里数据库设计我推荐大家一款数据库设计工具,我一直在使用觉得还不错叫PDMan
多平台版本,Mac Windows,Linux 系统都有 。总之功能非常强大 ,PDMan官网
分表设计
用户表
CREATE TABLE users(
user_Id BIGINT NOT NULL AUTO_INCREMENT COMMENT "用户ID" ,
user_name VARCHAR(128) COMMENT "用户名" ,
user_nickname VARCHAR(128) COMMENT "用户昵称" ,
pwd VARCHAR(64) COMMENT "用户密码" ,
email VARCHAR(64) COMMENT "用户邮箱" ,
avatar VARCHAR(128) COMMENT "用户头像" ,
create_time DATETIME COMMENT "注册时间" ,
birthday DATE COMMENT "用户生日" ,
age INT COMMENT "用户年龄" ,
moble_phone VARCHAR(32) COMMENT "用户手机号" ,
PRIMARY KEY (user_Id)
) COMMENT = "用户 ";;
文章表
CREATE TABLE article(
article_id BIGINT NOT NULL AUTO_INCREMENT COMMENT "博文ID" ,
push_data DATETIME COMMENT "发布日期" ,
article_user VARCHAR(32) COMMENT "发表用户" ,
title VARCHAR(1024) COMMENT "博文标题" ,
like_count INT COMMENT "点赞数" ,
comment_count INT COMMENT "评论数" ,
read_count INT COMMENT "浏览量" ,
top_flag VARCHAR(1) COMMENT "是否置顶" ,
create_time DATETIME COMMENT "创建时间" ,
article_summary VARCHAR(1024) COMMENT "文章摘要" ,
PRIMARY KEY (article_id)
) COMMENT = "文章 ";;
文章详情
CREATE TABLE article_detail(
article_detail_id BIGINT NOT NULL AUTO_INCREMENT COMMENT "文章详情id" ,
content_md TEXT COMMENT "文章markdown内容" ,
content_html TEXT COMMENT "文章html内容" ,
article_id BIGINT COMMENT "文章id" ,
PRIMARY KEY (article_detail_id)
) COMMENT = "文章详情 ";;
文章标签
CREATE TABLE article_tag_referenced(
atr_Id BIGINT NOT NULL AUTO_INCREMENT COMMENT "引用id" ,
article_id BIGINT COMMENT "文章id" ,
tag_id BIGINT COMMENT "标签id" ,
PRIMARY KEY (atr_Id)
) COMMENT = "文章标签 ";;
文章分类
CREATE TABLE article_category_referenced(
acr_id BIGINT NOT NULL AUTO_INCREMENT COMMENT "引用id" ,
article_id BIGINT COMMENT "文章id" ,
category_id BIGINT COMMENT "类目id" ,
PRIMARY KEY (acr_id)
) COMMENT = "文章分类 ";;
分类表
CREATE TABLE category(
category_id BIGINT NOT NULL AUTO_INCREMENT COMMENT "分类ID" ,
category_name VARCHAR(64) COMMENT "分类名称" ,
alias_name VARCHAR(64) COMMENT "分类别名" ,
description VARCHAR(128) COMMENT "分类描述" ,
parennt_id BIGINT COMMENT "父分类ID" ,
create_time DATETIME COMMENT "创建时间" ,
PRIMARY KEY (category_id)
) COMMENT = "分类 ";;
标签表
CREATE TABLE tag(
tag_id BIGINT NOT NULL AUTO_INCREMENT COMMENT "标签ID" ,
tag_name VARCHAR(64) COMMENT "标签名称" ,
alias_name VARCHAR(64) COMMENT "标签别名" ,
description VARCHAR(128) COMMENT "标签描述" ,
create_time DATETIME COMMENT "创建时间" ,
PRIMARY KEY (tag_id)
) COMMENT = "标签 ";;
评论表
CREATE TABLE discuss(
discuss_id BIGINT NOT NULL AUTO_INCREMENT COMMENT "评论ID" ,
create_time DATETIME COMMENT "评论日期" ,
like_count INT COMMENT "点赞数" ,
discuss_user BIGINT COMMENT "发表用户" ,
article_id BIGINT COMMENT "评论文章ID" ,
content VARCHAR(3072) COMMENT "评论内容" ,
parent_id BIGINT COMMENT "父评论ID" ,
PRIMARY KEY (discuss_id)
) COMMENT = "评论 ";;
关注公众号猿小叔领取sql