Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Buat kueri untuk membuat tabel

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)
);



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Hapus dari satu tabel dengan bergabung

  2. Masalah membaca/menulis data UTF-8 di MySQL dari Java menggunakan konektor JDBC 5.1

  3. Spring, MySQL dan Hibernate:Database error jika sistem tidak digunakan dalam waktu 8 jam

  4. Jquery datepicker dengan Ajax tidak berfungsi

  5. Menyimpan entitas serupa di tabel yang sama vs di beberapa tabel dalam database