簡單的BBS論壇 資料庫設計

FantJ發表於2018-03-28

#####最近幫一個練手的專案組設計了一個bbs論壇的資料庫。記錄一下,同時也免費分享給大家。 大概包括這麼幾個表:

  • admin使用者表
  • 文章表
  • 文章型別表/標籤表'
  • 關注表
  • 文章收藏表
  • 一級評論表
  • 多級評論表
  • 使用者資訊表

#####大家不要全部複製sql去跑,我建議大家一個一個表複製去建立。注意外來鍵關聯關係的去建立。每個欄位幾乎都有註釋。

簡單的BBS論壇 資料庫設計

/* Navicat MySQL Data Transfer

Source Server : localhost Source Server Version : 50624 Source Host : localhost:3306 Source Database : yunding_bbs

Target Server Type : MYSQL Target Server Version : 50624 File Encoding : 65001

Date: 2018-03-23 12:29:24 */

SET FOREIGN_KEY_CHECKS=0;


-- Table structure for bbs_admin


DROP TABLE IF EXISTS bbs_admin; CREATE TABLE bbs_admin ( admin_id int(11) NOT NULL, admin_login_name varchar(50) DEFAULT NULL, admin_login_pwd varchar(50) DEFAULT NULL, PRIMARY KEY (admin_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='admin使用者表';


-- Records of bbs_admin


INSERT INTO bbs_admin VALUES ('1', 'jiao', 'jiao');


-- Table structure for bbs_article


DROP TABLE IF EXISTS bbs_article; CREATE TABLE bbs_article ( art_id int(11) NOT NULL, art_user_id int(11) DEFAULT NULL, art_title varchar(255) DEFAULT NULL COMMENT '標題', art_type_id int(11) DEFAULT NULL COMMENT '型別id', art_content text COMMENT '正文', art_comment_id int(11) DEFAULT NULL COMMENT '評論id', art_cre_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '建立時間', art_view int(11) DEFAULT NULL COMMENT '瀏覽量', art_com_num int(11) DEFAULT NULL COMMENT '評論數', art_hot_num int(11) DEFAULT NULL COMMENT '當日瀏覽量/熱度', art_like_num int(11) DEFAULT NULL COMMENT '點贊數', PRIMARY KEY (art_id), KEY type_index (art_type_id), KEY com_index (art_comment_id), KEY art_index (art_user_id), CONSTRAINT art_index FOREIGN KEY (art_user_id) REFERENCES bbs_user (user_id) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT type_index FOREIGN KEY (art_type_id) REFERENCES bbs_article_type (type_id) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='文章表';


-- Records of bbs_article


INSERT INTO bbs_article VALUES ('1', '1', '第一篇文章', '1', '這裡是內容', '1', '2018-03-23 11:26:29', '999', '9', '9', '9');


-- Table structure for bbs_article_type


DROP TABLE IF EXISTS bbs_article_type; CREATE TABLE bbs_article_type ( type_id int(11) NOT NULL, type_name varchar(255) DEFAULT NULL COMMENT '標籤/型別', type_create_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '建立時間', PRIMARY KEY (type_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='文章型別表/標籤表';


-- Records of bbs_article_type


INSERT INTO bbs_article_type VALUES ('1', '標籤1', '2018-03-23 11:25:51');


-- Table structure for bbs_attention


DROP TABLE IF EXISTS bbs_attention; CREATE TABLE bbs_attention ( att_id int(11) NOT NULL, att_author_id int(11) DEFAULT NULL COMMENT '關注人id', att_user_id int(11) DEFAULT NULL, PRIMARY KEY (att_id), KEY attention_index (att_user_id) USING BTREE, KEY atten_author_index (att_author_id), CONSTRAINT atten_author_index FOREIGN KEY (att_author_id) REFERENCES bbs_user (user_id) ON DELETE SET NULL ON UPDATE NO ACTION, CONSTRAINT atten_user_index FOREIGN KEY (att_user_id) REFERENCES bbs_user (user_id) ON DELETE SET NULL ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='關注表';


-- Records of bbs_attention


INSERT INTO bbs_attention VALUES ('1', '1', '1');


-- Table structure for bbs_collect


DROP TABLE IF EXISTS bbs_collect; CREATE TABLE bbs_collect ( col_id int(11) NOT NULL, col_art_id int(11) DEFAULT NULL COMMENT '收藏文章id', col_user_id int(11) DEFAULT NULL COMMENT '收藏使用者的id/誰收藏了文章', PRIMARY KEY (col_id), KEY col_index (col_user_id), KEY col_art_index (col_art_id), CONSTRAINT col_art_index FOREIGN KEY (col_art_id) REFERENCES bbs_article (art_id) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT col_index FOREIGN KEY (col_user_id) REFERENCES bbs_user (user_id) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='文章收藏表';


-- Records of bbs_collect


INSERT INTO bbs_collect VALUES ('1', '1', '1');


-- Table structure for bbs_comment


DROP TABLE IF EXISTS bbs_comment; CREATE TABLE bbs_comment ( com_id int(11) NOT NULL, com_content varchar(255) DEFAULT NULL COMMENT '評論正文', com_art_id int(11) DEFAULT NULL COMMENT '文章id', com_user_id int(11) DEFAULT NULL COMMENT '評論使用者的id', com_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '評論時間', PRIMARY KEY (com_id), KEY com_user_index (com_user_id), KEY com_art_index (com_art_id), CONSTRAINT com_art_index FOREIGN KEY (com_art_id) REFERENCES bbs_article (art_id) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT com_user_index FOREIGN KEY (com_user_id) REFERENCES bbs_user (user_id) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='一級評論表';


-- Records of bbs_comment


INSERT INTO bbs_comment VALUES ('1', '評論正文', '1', '1', '2018-03-23 12:24:06');


-- Table structure for bbs_comment_multi


DROP TABLE IF EXISTS bbs_comment_multi; CREATE TABLE bbs_comment_multi ( com_multi_id int(11) NOT NULL, com_id int(11) NOT NULL COMMENT '一級評論id', com_multi_content varchar(255) DEFAULT NULL, com_multi_user_id int(11) NOT NULL COMMENT '多級評論使用者id', com_multi_time datetime DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (com_multi_id), KEY multi_user_index (com_multi_user_id), KEY multi_com_index (com_id), CONSTRAINT multi_com_index FOREIGN KEY (com_id) REFERENCES bbs_comment (com_id) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT multi_user_index FOREIGN KEY (com_multi_user_id) REFERENCES bbs_user (user_id) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='多級評論表';


-- Records of bbs_comment_multi


INSERT INTO bbs_comment_multi VALUES ('1', '1', '多級評論', '1', '2018-03-23 12:24:21');


-- Table structure for bbs_user


DROP TABLE IF EXISTS bbs_user; CREATE TABLE bbs_user ( user_id int(11) NOT NULL AUTO_INCREMENT, user_name varchar(50) DEFAULT NULL COMMENT '使用者暱稱', user_email varchar(50) DEFAULT NULL, user_sex varchar(2) DEFAULT NULL COMMENT '使用者性別', user_phone int(11) DEFAULT NULL COMMENT '電話', user_status int(1) DEFAULT NULL COMMENT '使用者狀態 0:未啟用 1:啟用', user_ex varchar(255) DEFAULT NULL COMMENT '使用者經驗', user_time datetime DEFAULT CURRENT_TIMESTAMP COMMENT '註冊時間/更改時間', user_show varchar(255) DEFAULT NULL COMMENT '使用者簽名', user_blog varchar(255) DEFAULT NULL COMMENT '使用者主頁連結', user_img varchar(255) DEFAULT NULL COMMENT '使用者頭像', user_fans int(11) DEFAULT NULL COMMENT '使用者粉絲數', user_concern int(11) DEFAULT NULL COMMENT '使用者關注別人的數量', PRIMARY KEY (user_id), CONSTRAINT user_admin_index FOREIGN KEY (user_id) REFERENCES bbs_admin (admin_id) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='使用者資訊表';


-- Records of bbs_user


INSERT INTO bbs_user VALUES ('1', 'FantJ', 'xxx', '男', '123123123', '1', '1', '2018-03-23 11:20:46', '這是我的個性簽名', 'www.baidu.com', 'https://4f95-8639-e69e8c636570?imageMogr2/auto-orient/strip|imageView2/1/w/240/h/240', '9999', '9999');

相關文章