2

我目前正在使用 MySQL 数据库表结构。我在网上找到了一个表结构,但我不确定如何复制确切的表结构。这些表彼此共享外键和索引。我附上了一个链接,显示表格是在我想复制的模型中设置的。我请求帮助创建一个查询,该查询将创建所有表及其相关数据。 链接表结构

外键

semester_id
faculty_id
schedule_id
section_id
class_id
major_minor_id
4

1 回答 1

3
CREATE TABLE event
(
    ID INT,
    event_description VARCHAR(30),
    event_heading  VARCHAR(30),
    event_photo BLOB,
    event_datetime  VARCHAR(30),
    CONSTRAINT event_pk PRIMARY KEY (ID)
);

CREATE TABLE semester
(
    ID INT,
    Semester_Name VARCHAR(25),
    CONSTRAINT sem_pk PRIMARY KEY (ID),
    CONSTRAINT sem_uq UNIQUE (semester_Name)
);

CREATE TABLE Major_Minor
(
    ID INT,
    Major_Minor_Name VARCHAR(30),
    Major_Minor_Description VARCHAR(50),
    CONSTRAINT mm_pk PRIMARY KEY (ID),
    CONSTRAINT mm_uq UNIQUE (Major_Minor_Name)
);

CREATE TABLE class
(
    ID INT,
    class_caption VARCHAR(30),
    class_name VARCHAR(30),
    class_description VARCHAR(30),
    class_credit_hours INT,
    CONSTRAINT cc_pk PRIMARY KEY (ID),
    CONSTRAINT cc_uq UNIQUE (class_caption)
);

CREATE TABLE Major_Class_br
(
    ID INT, 
    Class_ID INT,
    Major_Minor_ID INT,
    CONSTRAINT mbr_pk PRIMARY KEY (ID), 
    CONSTRAINT cc_fk1 FOREIGN KEY (Class_ID) REFERENCES class(ID),
    CONSTRAINT cc_fk2 FOREIGN KEY (Major_Minor_ID) REFERENCES Major_Minor(ID)
);

CREATE TABLE Faculty
(
    ID INT,
    faculty_fName VARCHAR(30),
    faculty_lname VARCHAR(30),
    faculty_bio VARCHAR(100),
    faculty_pic_path  VARCHAR(30),
    CONSTRAINT f_pk PRIMARY KEY (ID),
    CONSTRAINT cc_uq UNIQUE (faculty_fName, faculty_lname)
);

CREATE TABLE Faculty_Titles
(
    ID INT,
    faculty_ID INT,
    faculty_title VARCHAR(30),
    CONSTRAINT ft_pk PRIMARY KEY (ID),
    CONSTRAINT ft_fk1 FOREIGN KEY (faculty_ID) REFERENCES Faculty(ID)
);

CREATE TABLE Faculty_Education
(
    ID INT,
    faculty_ID INT,
    faculty_ed VARCHAR(30),
    CONSTRAINT fe_pk PRIMARY KEY (ID),
    CONSTRAINT fe_fk1 FOREIGN KEY (faculty_ID) REFERENCES faculty(ID)
);

CREATE TABLE Section
(
    ID INT, 
    Class_ID INT,
    faculty_ID INT,
    section_number INT,
    section_callnumber INT,
    CONSTRAINT ss_pk PRIMARY KEY (ID),  
    CONSTRAINT ss_fk1 FOREIGN KEY (Class_ID) REFERENCES class(ID),
    CONSTRAINT ss_fk2 FOREIGN KEY (faculty_ID) REFERENCES faculty(ID)
);

CREATE TABLE Schedule
(
    ID INT,
    Semester_ID INT,
    schedule_start_time DATETIME,
    schedule_end_time DATETIME,
    schedule_monday TINYINT(1),
    schedule_tuesday TINYINT(1),
    schedule_wednesday TINYINT(1),
    schedule_thursday TINYINT(1),
    schedule_friday TINYINT(1),
    CONSTRAINT sc_pk PRIMARY KEY (ID),
    CONSTRAINT sc_fk1 FOREIGN KEY (Semester_ID) REFERENCES semester(ID)
);

CREATE TABLE Office_Hours
(
    ID INT, 
    faculty_ID INT,
    schedule_ID INT,
    CONSTRAINT oh_pk PRIMARY KEY (ID),  
    CONSTRAINT oh_fk1 FOREIGN KEY (schedule_ID) REFERENCES Schedule(ID),
    CONSTRAINT oh_fk2 FOREIGN KEY (faculty_ID) REFERENCES faculty(ID)
);

CREATE TABLE sched_sect_br
(
    ID INT, 
    schedule_ID INT,
    section_ID INT,
    room_number INT,
    CONSTRAINT ssb_pk PRIMARY KEY (ID), 
    CONSTRAINT ssb_fk1 FOREIGN KEY (schedule_ID) REFERENCES Schedule(ID),
    CONSTRAINT ssb_fk2 FOREIGN KEY (section_ID) REFERENCES Section(ID)
);
于 2012-11-07T05:08:45.027 回答