Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE students(
- student_id INT(11) AUTO_INCREMENT NOT NULL,
- name VARCHAR(50)
- );
- CREATE TABLE exams(
- exam_id INT(11) NOT NULL,
- name VARCHAR(50)
- );
- ALTER TABLE stutends
- ADD CONSTRAINT pk_student_id PRIMARY KEY(student_id);
- ALTER TABLE exams
- ADD CONSTRAINT pk_exam_id PRIMARY KEY (exam_id);
- CREATE TABLE studetns_exams(
- sutdent_id INT NOT NULL,
- exam_id INT NOT NULL
- );
- ALTER TABLE students_exams
- ADD CONSTRAINT pk_students_exams PRIMARY KEY (student_id, exam_id);
- ALTER TABLE students_exams
- ADD CONSTRAINT fk_student_exams_student_id FOREIGN KEY(student_id) REFERENCE students(student_id);
- ALTER TABLE students_exams
- ADD CONSTRAINT fk_student_exam_exam_id FOREIGN KEY(exam_id) REFERENCE exams(exam_id);
- INSERT INTO students VALUES
- (1, 'Mila'),
- (2, 'Toni'),
- (3, 'Ron');
- INSERT INTO exams VALUES
- (101, 'Spring MVC'),
- (102, 'Neo4j'),
- (103, 'Oracle 11g');
- INSERT INTO students_exams VALUES
- (1, 101),
- (1, 102),
- (2, 101),
- (2, 102),
- (3, 101),
- (3, 102);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement