4

I am working with a basic table design for a MySQL database. This database project was given as an idea, mainly aimed for an educational purpose. There are a total of 11 tables which 2 are used for bridging purposes. I tried to properly set primary and foreign keys. I am not sure how to write the query that will create the 11 tables and bridge them all at once. HERE I have attached a visual diagram of these tables.

Through basic learning I can create one table but not sure how to advance from here:

CREATE TABLE Course (
          Course_ID INT,
          Course_Abbreviation VARCHAR(5),
      Course_Number INT,
      Section_Number INT,
      Professor_ID INT,
      Status VARCHAR(10)        
        ) TYPE=innodb;
4

1 に答える 1

4

テーブル内の属性に PRIMARY キーと FOREIGN キーを定義する必要があります。Students、Course、および Course_Br_Students テーブルの例を次に示します。

CREATE TABLE Students(
PRIMARY KEY Student_ID SERIAL INTEGER,
Username VARCHAR(255),
First_name VARCHAR(255),
Email VARCHAR(255),
Phone number INTEGER,
Beginning_Date TIME,
Ending_Date TIME,
Max_hours INTEGER,
)

CREATE TABLE Student_Br_Course(
FOREIGN KEY Student_ID REFERENCES Students(Student_ID),
FOREIGN KEY Course_ID REFERENCES Courses(Course_ID),
Role VARCHAR(255),
Status BOOLEAN,
)

CREATE TABLE Courses(
PRIMARY KEY Course_ID INTEGER,
Course_Abbreviation VARCHAR(255),
Course_Number INTEGER,
Section_number INTEGER,
Professor_ID INTEGER,
)

PRIMARY キーと FOREIGN キーを使用してテーブルを作成する方法を理解するためのリファレンスを次に示します。

http://www.w3schools.com/sql/sql_foreignkey.asp

于 2013-03-14T00:31:08.477 に答える