Advertisement
MarkUa

Untitled

Jun 30th, 2019
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 5.13 KB | None | 0 0
  1. USE [master]
  2.  
  3. IF NOT EXISTS (SELECT name FROM sys.DATABASES WHERE name = N'Quiz')
  4.     CREATE DATABASE [Quiz]
  5. ELSE
  6.     DROP DATABASE [Quiz]
  7.     CREATE DATABASE [Quiz]
  8. GO
  9. USE [Quiz]
  10.  
  11. CREATE TABLE Lecturer
  12. (
  13. lecturer_id_ INT IDENTITY(1,1)  NOT NULL,
  14. lecturer_nickname_  VARCHAR(50) NOT NULL,
  15. lecturer_password_ VARCHAR(50) NOT NULL,
  16. lecturer_email_ VARCHAR(50) NOT NULL,
  17. PRIMARY KEY(lecturer_id_)
  18. )
  19.  
  20. CREATE TABLE Student
  21. (
  22. student_id_ INT IDENTITY(1,1)  NOT NULL,
  23. student_nickname_  VARCHAR(50) NOT NULL,
  24. student_password_ VARCHAR(50) NOT NULL,
  25. student_email_ VARCHAR(50) NOT NULL,
  26. PRIMARY KEY(student_id_)
  27. )
  28.  
  29.  
  30. CREATE TABLE Course(
  31. course_id INT IDENTITY(1,1)  NOT NULL,
  32. course_description_  VARCHAR(50) NOT NULL,
  33. course_lecturer_id int NOT NULL,
  34. course_creation_time VARCHAR(50) NOT NULL,
  35.  
  36.  
  37. PRIMARY KEY(course_id)
  38. )
  39.  
  40. ALTER TABLE Course
  41. WITH CHECK ADD CONSTRAINT FK_course_lecturer_id FOREIGN KEY(course_lecturer_id)
  42. REFERENCES Lecturer(lecturer_id_);
  43.  
  44.  
  45. create table  CourseSubscriptions
  46. (
  47.  course_subscription_id INT IDENTITY(1,1) not null,
  48.  course_id int,
  49.  student_id int,
  50.  PRIMARY KEY(course_subscription_id)
  51. );
  52.  
  53. ALTER TABLE CourseSubscriptions
  54. WITH CHECK ADD CONSTRAINT FK_coursesubs_id FOREIGN KEY( course_id)
  55. REFERENCES  Course( course_id);
  56.  
  57. ALTER TABLE CourseSubscriptions
  58. WITH CHECK ADD CONSTRAINT FK_studentss_id FOREIGN KEY(student_id)
  59. REFERENCES Student(student_id_ );
  60.  
  61.  
  62. Create Table CourseLesson(
  63. lesson_id INT IDENTITY(1,1)  NOT NULL,
  64. lesson_description_  VARCHAR(50) NOT NULL,
  65. lesson_creator VARCHAR(50) NOT NULL,
  66. lesson_creation_time DATETIME NOT NULL,
  67. course_id int
  68. PRIMARY KEY(lesson_id)
  69. )
  70.  
  71. ALTER TABLE CourseLesson
  72. WITH CHECK ADD CONSTRAINT FK_courselesson_id FOREIGN KEY(course_id)
  73. REFERENCES Course(course_id);
  74.  
  75. Create table LessonFiles
  76. (
  77. lesson_file_id INT IDENTITY(1,1)   NOT NULL,
  78. file_content  Varbinary not null,
  79. lesson_id INT,
  80. file_creation_time DATETIME NOT NULL,
  81. PRIMARY KEY(lesson_file_id)
  82. )
  83.  
  84. ALTER TABLE LessonFiles
  85. WITH CHECK ADD CONSTRAINT FK_lessonfile_id FOREIGN KEY(lesson_id)
  86. REFERENCES CourseLesson(lesson_id);
  87.  
  88. Create table CourseChat
  89. (
  90. Chat_id INT IDENTITY(1,1)   NOT NULL,
  91. course_id int,
  92. creation_time DATETIME NOT NULL,
  93. PRIMARY KEY(Chat_id)
  94. )
  95.  
  96. ALTER TABLE CourseChat
  97. WITH CHECK ADD CONSTRAINT FK_coursechat_id FOREIGN KEY(course_id)
  98. REFERENCES Course(course_id);
  99.  
  100. Create table ChatMessages
  101. (
  102. message_id INT IDENTITY(1,1)   NOT NULL,
  103. message_text Varchar(100) Not null,
  104. belong_to_chat int,
  105. author_lecturer_id int ,
  106. author_student_id int,
  107. creation_time DATETIME NOT NULL,
  108. PRIMARY KEY(message_id)
  109. )
  110.  
  111. ALTER TABLE ChatMessages
  112. WITH CHECK ADD CONSTRAINT FK_author_lecturer_id FOREIGN KEY(author_lecturer_id)
  113. REFERENCES Lecturer(lecturer_id_);
  114.  
  115.  
  116. ALTER TABLE ChatMessages
  117. WITH CHECK ADD CONSTRAINT FK_author_student_id FOREIGN KEY(author_student_id)
  118. REFERENCES Student(student_id_);
  119.  
  120. Create table SearchTags
  121. (
  122. search_tag_id int IDENTITY(1,1)   NOT NULL,
  123. search_tag_text Varchar(100) Not null,
  124. PRIMARY KEY(search_tag_id)
  125. )
  126.  
  127. Create table CourseSearchTags
  128. (
  129. course_search_tag_id int IDENTITY(1,1)   NOT NULL,
  130. course_id int,
  131. search_tag_id int,
  132. PRIMARY KEY(course_search_tag_id)
  133. )
  134.  
  135. ALTER TABLE CourseSearchTags
  136. WITH CHECK ADD CONSTRAINT FK_coursesearch_id FOREIGN KEY(course_id)
  137. REFERENCES Course(course_id);
  138.  
  139. ALTER TABLE CourseSearchTags
  140. WITH CHECK ADD CONSTRAINT FK_coursesearchtags_id FOREIGN KEY(search_tag_id)
  141. REFERENCES SearchTags(search_tag_id);
  142.  
  143. Create table LessonTestQuiz(
  144. quiz_id int IDENTITY(1,1)   NOT NULL,
  145. quiz_title Varchar(100) Not null,
  146. lesson_id int
  147. PRIMARY KEY(quiz_id)
  148. );
  149.  
  150. ALTER TABLE LessonTestQuiz
  151. WITH CHECK ADD CONSTRAINT FK_testlesson_id FOREIGN KEY(lesson_id)
  152. REFERENCES  CourseLesson(lesson_id);
  153.  
  154. Create table TestQuizQuestions(
  155. question_id int IDENTITY(1,1)   NOT NULL,
  156. question_title Varchar(100) Not null,
  157. quiz_id int
  158. PRIMARY KEY(question_id)
  159. );
  160.  
  161. ALTER TABLE TestQuizQuestions
  162. WITH CHECK ADD CONSTRAINT FK_TestQuizQuestions_id FOREIGN KEY(quiz_id )
  163. REFERENCES  LessonTestQuiz(quiz_id);
  164.  
  165. Create table QuestionsAnswerResult(
  166. answer_result_id int IDENTITY(1,1)   NOT NULL,
  167. answer Varchar(100) Not null,
  168. result int Not null,
  169. question_id int
  170. PRIMARY KEY(answer_result_id)
  171. );
  172.  
  173. ALTER TABLE QuestionsAnswerResult
  174. WITH CHECK ADD CONSTRAINT FK_QuestionsAnswerResult_id FOREIGN KEY(question_id)
  175. REFERENCES  TestQuizQuestions(question_id );
  176.  
  177.  
  178. Create table TestQuizStudent(
  179. pair_id int IDENTITY(1,1)   NOT NULL,
  180. quiz_id int,
  181. student_id int,
  182.  
  183. PRIMARY KEY(pair_id)
  184. );
  185.  
  186. ALTER TABLE TestQuizStudent
  187. WITH CHECK ADD CONSTRAINT FK_TestQuizStudent_id FOREIGN KEY(quiz_id)
  188. REFERENCES  LessonTestQuiz(quiz_id);
  189.  
  190. ALTER TABLE TestQuizStudent
  191. WITH CHECK ADD CONSTRAINT FK_TestQuizStudent555_id FOREIGN KEY(student_id)
  192. REFERENCES  Student(student_id_);
  193.  
  194. Create table TestQuizStudentAnswers
  195. (
  196.     id int IDENTITY(1,1)   NOT NULL,
  197.     quiz_question Varchar(100) Not null,
  198.     student_answer  Varchar(100) Not null,
  199.     TestQuizStudent_id int not null,
  200.     PRIMARY KEY(id)
  201. );
  202.  
  203. ALTER TABLE TestQuizStudentAnswers
  204. WITH CHECK ADD CONSTRAINT FK_TestQuizStudentAnswers_id FOREIGN KEY(TestQuizStudent_id)
  205. REFERENCES  TestQuizStudent(pair_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement