Advertisement
pavelperc

tutors_script

Nov 3rd, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.79 KB | None | 0 0
  1. drop database tutors;
  2. create database tutors;
  3. use tutors;
  4.  
  5. create table Persons (
  6.   id          int                 not null auto_increment primary key,
  7.  
  8.   email       varchar(255) unique not null,
  9.   login       varchar(255) unique not null,
  10.  
  11.   first_name  varchar(255),
  12.   middle_name varchar(255),
  13.   last_name   varchar(255)
  14. );
  15.  
  16. create table Tutors (
  17.   id        int not null primary key,
  18.   person_id int not null unique, # is it good ??? it is not one to one?
  19.  
  20.   foreign key (person_id) references Persons (id)
  21.     on delete cascade
  22. );
  23.  
  24. create table Subjects (
  25.   id   int          not null auto_increment primary key,
  26.   name varchar(255) not null
  27. );
  28.  
  29. create table TutorSubjects (
  30.   tutor_id   int not null,
  31.   subject_id int not null,
  32.  
  33.   foreign key (tutor_id) references Tutors (person_id)
  34.     on delete cascade,
  35.   foreign key (subject_id) references Subjects (id),
  36.  
  37.   primary key (tutor_id, subject_id)
  38. );
  39.  
  40. create table TutorCertificates (
  41.   tutor_id    int          not null,
  42.   name        varchar(255) not null,
  43.   description varchar(255),
  44.  
  45.   foreign key (tutor_id) references Tutors (id)
  46.     on delete cascade,
  47.   primary key (tutor_id, name)
  48. );
  49.  
  50. create table Courses (
  51.   id         int          not null auto_increment primary key,
  52.   name       varchar(255) not null,
  53.   subject_id int,
  54.  
  55.   foreign key (subject_id) references Subjects (id)
  56. );
  57.  
  58. create table TutorCourses (
  59.   tutor_id  int not null,
  60.   course_id int not null,
  61.  
  62.   foreign key (tutor_id) references Tutors (id)
  63.     on DELETE cascade,
  64.   foreign key (course_id) references Courses (id),
  65.  
  66.   primary key (tutor_id, course_id)
  67. );
  68.  
  69. create table Students (
  70.   id        int not null auto_increment primary key,
  71.   person_id int not null unique, # is it good ??? it is not one to one?
  72.  
  73.   foreign key (person_id) references Persons (id)
  74.     on delete cascade
  75. );
  76.  
  77. create table StudentCourses (
  78.   student_id int not null,
  79.   course_id  int not null,
  80.  
  81.   foreign key (student_id) references Students (id)
  82.     on delete cascade,
  83.   foreign key (course_id) references Courses (id),
  84.  
  85.   primary key (student_id, course_id)
  86. );
  87.  
  88. create table Lesson (
  89.   id         int not null auto_increment primary key,
  90.   tutor_id   int not null,
  91.   student_id int not null,
  92.   course_id  int not null, # how to check validity in TutorCourses??
  93.   time_id    int not null,
  94.   paid_money double,
  95.  
  96.   foreign key (tutor_id) references Tutors (id),
  97.   foreign key (student_id) references Students (id),
  98.   foreign key (course_id) references Courses (id)
  99. );
  100.  
  101. create table Time (
  102.   id             int      not null auto_increment primary key,
  103.   start_time     datetime not null,
  104.   length_minutes int      not null,
  105.   lesson_id      int      not null unique,
  106.  
  107.   foreign key (lesson_id) references Lesson (id)
  108.     on delete cascade
  109. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement