对于数据库进行设计在PHP,关于数据库表的设计
如圖所示
我的項目需要將已經(jīng)爬取的coursera數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫,以備后續(xù)工作使用,如php等
現(xiàn)在數(shù)據(jù)已經(jīng)爬取完畢,如圖格式存在文件夾中,圖片所示屬于一個目錄,我是一個數(shù)據(jù)菜鳥,不知道如何設(shè)計數(shù)據(jù)庫才能將這幾級數(shù)據(jù)正確的存在mysql中呢?(使用navicat),望各位高手不吝賜教,小弟感激不盡!
回復(fù)內(nèi)容:
如圖所示
我的項目需要將已經(jīng)爬取的coursera數(shù)據(jù)導(dǎo)入數(shù)據(jù)庫,以備后續(xù)工作使用,如php等
現(xiàn)在數(shù)據(jù)已經(jīng)爬取完畢,如圖格式存在文件夾中,圖片所示屬于一個目錄,我是一個數(shù)據(jù)菜鳥,不知道如何設(shè)計數(shù)據(jù)庫才能將這幾級數(shù)據(jù)正確的存在mysql中呢?(使用navicat),望各位高手不吝賜教,小弟感激不盡!
很簡單,你需要把課程和目錄分開保存,我舉個例子:
create table course(
id int not null auto_increment,
course_name varchar(32),
url varchar(64),
category_id int,
course_desc varchar(512),
primary key (id),
foreign key (category_id) references category(id) on delete cascade
);
create table category(
id int not null auto_increment,
category_name varchar(32),
parent_id int,
primary key (id),
foreign key (parent_id) references category(id) on delete cascade
);
insert into category(id, category_name, parent_id)
values (1, "Computer science", null), (2, "Algorithms", 1), (3, "Design & Product", 1), (4, "Software development", 1);
insert into course(id, course_name, url, category_id, course_desc)
values (1, "Software Engineering Management", "https://course.scut.cn/sem", 4,
"Software engineering management could be described simply as a management position in the software industry. ");
外鍵是讓你看清楚表的關(guān)系,并不是一定要有。
mysql> select * from course \G
*************************** 1. row ***************************
id: 1
course_name: Software Engineering Management
url: https://course.scut.cn/sem
category_id: 4
course_desc: Software engineering management could be described simply as a management position in the software industry.
1 row in set (0.00 sec)
mysql> select * from category;
+----+----------------------+-----------+
| id | category_name | parent_id |
+----+----------------------+-----------+
| 1 | Computer science | NULL |
| 2 | Algorithms | 1 |
| 3 | Design & Product | 1 |
| 4 | Software development | 1 |
+----+----------------------+-----------+
4 rows in set (0.00 sec)
id 課程編號
pid 課程父節(jié)點編號
name 課名
desc 課信息
url 課程url
...
本文原創(chuàng)發(fā)布php中文網(wǎng),轉(zhuǎn)載請注明出處,感謝您的尊重!
總結(jié)
以上是生活随笔為你收集整理的对于数据库进行设计在PHP,关于数据库表的设计的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做唐氏筛查多少钱啊?
- 下一篇: iPhone PHP获取文件,IOS中获