connect 3 tables with cascade SQL(phpmyadmin)

20 Views Asked by At

I have 3 tables, first table is "user" that contain all users. second table is "teacher" that contain just teachers, and the last table is "student" that contain just students. Now I want to connect all this table together and when I add new user with role teacher its should added just to teacher table, and when I add new user with role student it should be added just to student table.

user table: https://prnt.sc/fioCEiBtc2dr without relations

teacher table: https://prnt.sc/zrJcHeSQKsUg with relation https://prnt.sc/04iyp6MzDFoa

student table: https://prnt.sc/yYnYIX7eFuI1 with relation https://prnt.sc/MQTtyfiDAUq1

For now if I add new user with teacher role or student role it adding this user just to teacher table. What should I do?

1

There are 1 best solutions below

0
Alex On

Ok, that is the answer all want need to do it just add triggers to user table.

BEGIN IF NEW.role = 'teacher' THEN INSERT INTO teacher (id_user) VALUES (NEW.id_user); END IF; END

and same trigger for student table