Alter ADD Index: 'Student' 'Student - Id'

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Create database newtest 1) Create table students( student_id int(3 NOT NULL AUTO_INCREMENT, student_name VARCHAR(40), student_address VARCHAR

(100), student_email VARCHAR(40), student_phonenumber int(10), PRIMARY KEY(student_id) ) Dupa adaugarea tabelului se mai adauga ALTER TABLE `student` ADD INDEX ( `student_id` )
Adaugare cheie primara ALTER TABLE `courses` ADD FOREIGN KEY ( `student_id_fk` ) REFERENCES `newtest`. `courses` (`course_id`) ON DELETE CASCADE ON UPDATE CASCADE ;

ALTER TABLE `courses` DROP FOREIGN KEY `courses_ibfk_1` , ADD FOREIGN KEY ( `student_id_fk` ) REFERENCES `newtest`.`student` ( `student_id`) ON DELETE CASCADE ON UPDATE CASCADE ;

2) Create table courses( course_id INT(3) NOT NULL AUTO_INCREMENT, course_name VARCHAR(30) , course_details VARCHAR(200), course_duration VARCHAR(10), student_id_fk INT(3), PRIMARY KEY(course_id) ) Dupa adaugarea tabelului se mai adauga ALTER TABLE `courses` ADD INDEX ( `course_id` )
Dupa se trece pe structure - > relation view Student_id_fk->new test.courses.course.id->on delete cascade->on update cascade Course -> structure-> relation view

You might also like