關於資料庫表的設計

來源:互聯網
上載者:User
關鍵字 mysql sql oracle sqlserver php

我的項目需要將已經爬取的coursera資料匯入資料庫,以備後續工作使用,如php等
現在資料已經爬取完畢,格式存在檔案夾中,圖片所示屬於一個目錄,我是一個資料菜鳥,不知道如何設計資料庫才能將這幾級資料正確的存在mysql中呢?(使用navicat),望各位高手不吝賜教,小弟感激不盡!

回複內容:

我的項目需要將已經爬取的coursera資料匯入資料庫,以備後續工作使用,如php等
現在資料已經爬取完畢,格式存在檔案夾中,圖片所示屬於一個目錄,我是一個資料菜鳥,不知道如何設計資料庫才能將這幾級資料正確的存在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. ");    

外鍵是讓你看清楚表的關係,並不是一定要有。

mysql> select * from course \G*************************** 1. row ***************************         id: 1course_name: Software Engineering Management        url: https://course.scut.cn/semcategory_id: 4course_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 課程父節點編號
name 課名
desc 課資訊
url 課程url
...

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.