Advertisement
horozov86

8.Study Session

Oct 3rd, 2023
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. CREATE TABLE students(
  2.     id SERIAL PRIMARY KEY,
  3.     student_name VARCHAR(20)
  4. );
  5.  
  6. CREATE TABLE exams(
  7.     id INTEGER GENERATED ALWAYS AS IDENTITY (START WITH 101 INCREMENT 1) PRIMARY KEY,
  8.     exam_name VARCHAR(20)
  9. );
  10.  
  11. CREATE TABLE study_halls(
  12.     id SERIAL PRIMARY KEY,
  13.     study_hall_name VARCHAR(30),
  14.     exam_id INTEGER,
  15.  
  16.     CONSTRAINT fk_study_halls_exams
  17.     FOREIGN KEY (exam_id)
  18.     REFERENCES exams(id)
  19. );
  20.  
  21.  
  22. CREATE TABLE students_exams(
  23.     student_id INT,
  24.     exam_id INT,
  25.  
  26.     CONSTRAINT pk_students_exams
  27.     PRIMARY KEY (student_id, exam_id),
  28.    
  29.     CONSTRAINT fk_students_exams_students
  30.     FOREIGN KEY (student_id)
  31.     REFERENCES students(id),
  32.  
  33.     CONSTRAINT fk_students_exams_exams
  34.     FOREIGN KEY (exam_id)
  35.     REFERENCES exams(id)
  36.  
  37. );
  38.  
  39. INSERT INTO students(student_name)
  40. VALUES
  41.     ('Mila'),
  42.     ('Toni'),
  43.     ('Ron');
  44.  
  45. INSERT INTO exams(exam_name)
  46. VALUES
  47.     ('Python Advanced'),
  48.     ('Python OOP'),
  49.     ('PostgreSQL');
  50.  
  51. INSERT INTO study_halls(study_hall_name, exam_id)
  52. VALUES
  53.     ('Open Source Hall', 102),
  54.     ('Inspiration Hall', 101),
  55.     ('Creative Hall', 103),
  56.     ('Masterclass Hall', 103),
  57.     ('Information Security Hall', 103);
  58.  
  59. INSERT INTO students_exams
  60. VALUES
  61.     (1, 101),
  62.     (1, 102),
  63.     (2, 101),
  64.     (3, 103),
  65.     (2, 102),
  66.     (2, 103);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement