I have finished designing the tables structures for a school course catalog. I am using four tables majors, courses, course_hours, course_date. Below I have detailed the components of each table. Some of the tables will use indexing based on course_id. I am new with database and struggling with building these tables inside my database. How can I make these tables link together with using course_id? Or is there a better way to structure these tables for my purpose. If possible providing a query to create these tables will be great.
Hopefully I am using the righ type(int,varchar, text, etc) for my variables.
Example of table courses
id serial
course_name varchar
course_code varchar
description text
Example of table course_dates (using index)
id int
course_id int
year date
semester int
Example of table course_hours (using index)
id int
course_id int
hours int
Example of table majors (one to many relationship- index)
major_id int
course_id int
major_name varchar
So a populated database would contain the following:
Table courses
course_id course_code course_name course_description
1 INF1000 Visual Studio I "Basic programming"
2 INF1001 Visual Stuido II "More programming"
Table course_dates (0 for spring, 1 for fall, 2 all year)
id course_id year semester
1 1 2012 0
2 1 2013 1
3 2 2013 1
Table course_hours
id course_id course_hours
1 1 3
2 1 4
3 2 4
Table majors
id course_id major_name
1 1 Computer Engineering
2 1 Information Systems
3 2 Network Administrator
i would do some restructuring:
any advantage to extracting hours to a seperate table)
giving you a structure like:

edit: made it back to a mysql box. here’s the script for this structure. remember you might want to change charset and engine type as those can change per database, these are probably fine as is for default