數據庫基礎入門(二)——具體項目實現

寵物社交網站數據庫設計

 

 項目簡介:用戶通過給自己的寵物申請賬號,從而在網路上以寵物爲第一人稱與其他寵物進行社交(類似微博)。

    數據庫基本架構:

 

  用戶(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;

 



 

  • 6d8bf8ab-e8d6-3ba8-8be7-0b39dbf2b9ed-thumb.png
  • 大小: 61.2 KB
  • 9b863cc2-264d-3c74-ade8-63096db27dd3-thumb.png
  • 大小: 70.5 KB
  • 04f63e50-2795-3962-90d1-1bd68c66ff5d-thumb.png
  • 大小: 10.7 KB
  • 54de1226-be51-3f1e-a0c6-960ca629fc00-thumb.png
  • 大小: 76.8 KB
  • ad18d0a5-341f-378c-995f-a0fb433d02fc-thumb.png
  • 大小: 10.1 KB
  • eb608746-eacd-320f-b8c6-7771e11ba56c-thumb.png
  • 大小: 36.9 KB
  • 624dbc97-eb75-3cc4-94c4-7e8d3f7c3a9d-thumb.png
  • 大小: 94 KB
  • cf693d25-37d9-39e3-bb68-1793bfcee4e9-thumb.png
  • 大小: 97.6 KB
  • 0b786e70-a93e-3eee-9bfb-e1f36e0f8a4c-thumb.png
  • 大小: 75.8 KB
  • df6af1df-9951-3db3-a6a7-27d012bf61cf-thumb.png
  • 大小: 36.1 KB
  • d30ced86-e45d-3fec-91cf-72a3cede8b31-thumb.png
  • 大小: 63.2 KB
  • 9985c510-8d91-3863-8fff-d5ad3aafdf20-thumb.png
  • 大小: 13.7 KB
  • 6cbe6d78-45d0-38c8-887a-58f5efa5eb5b-thumb.png
  • 大小: 58.1 KB
  • 106944f1-f472-332c-9501-de776721fb62-thumb.png
  • 大小: 26.3 KB
  • 5bc96b4f-4fc8-38ee-a3fa-25826766ccfc-thumb.png
  • 大小: 93.9 KB
  • 11b9bdc6-aaf5-3ff4-9ec1-6d01fcddcc41-thumb.png
  • 大小: 31.2 KB
發佈了54 篇原創文章 · 獲贊 6 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章