寵物社交網站數據庫設計
項目簡介:用戶通過給自己的寵物申請賬號,從而在網路上以寵物爲第一人稱與其他寵物進行社交(類似微博)。
數據庫基本架構:
用戶(ID,用戶名,密碼,郵箱,電話,地址,身份證號,性別,姓名,生日)
寵物(ID,名字,性別,生日,智商,簡介,用戶ID,品種ID)
科目(ID,科目名)
品種(ID,品種名,科目ID)
動態(ID,用戶ID,內容,時間,贊數)
評論(ID,用戶ID,內容,時間,動態ID)
回覆(ID,用戶ID,內容,時間,評論ID)
管理員(ID,用戶名,密碼)
用戶表
create table user(
-> id int not null auto_increment,
-> usr_name varchar(20) not null,
-> password varchar(20) not null,
-> email varchar(20) not null,
-> tel varchar(11),
-> address varchar(50),
-> sex boolean,
-> true_name varchar(20),
-> birthday Date,
-> primary key(id));
寵物表
create table pet(
-> id int not null auto_increment,
-> name varchar(20) not null,
-> sex boolean,
-> birthday Date,
-> IQ int,
-> intro varchar(200),
-> user_id int not null,
-> kind_id int not null,
-> primary key(id));
//設置外鍵
alter table pet add constraint fk_pet_user foreign key(user_id) references user(id) on delete cascade on update cascade;
alter table pet add constraint fk_pet_kind foreign key(kind _id) references kind (id) on delete cascade on update cascade;
科目表
mysql> create table family(
-> id int not null primary key auto_increment,
-> family varchar(20));
品種表
mysql> create table kind(
-> id int not null primary key auto_increment,
-> kind varchar(20) not null,
-> family_id int not null);
//設置外鍵
alter table kind add constraint fk_breed_family foreign key(family_id) references family(id) on delete cascade on update cascade;
動態表
mysql> create table dynamic(
-> id int not null primary key auto_increment,
-> user_id int not null,
-> content varchar(280) not null,
-> time time not null,
-> praise int);
//設置外鍵
alter table dongtai add constraint fk_dynamic_user foreign key(user_id)
references user(id) on delete cascade on update cascade;
評論表
mysql> create table comment(
-> id int not null primary key auto_increment,
-> user_id int not null,
-> content varchar(280) not null,
-> time time not null,
-> from_id int not null);
//設置外鍵
alter table comment add constraint fk_comment_user foreign key(user_id) references user(id) on delete cascade on update cascade;
alter table comment add constraint fk_comment_dongtai foreign key(from_id) references dongtai(id) on delete cascade on update cascade;
管理員表
mysql> create table admin(
-> id int not null primary key auto_increment,
-> name varchar(20) not null,
-> password varchar(20) not null);
回覆表
create table reply_comment(
id int not null auto_increment,
user_id int not null,
time Time not null,
owner_id int not null,
primary key(id));
//設置外鍵
alter table reply_comment add constraint fk_reply_user foreign key(user_id) references user(id) on delete cascade on update cascade;
alter table reply_comment add constraint fk_reply_comment foreign key(owner_id) references comment(id) on delete cascade on update cascade;