gmc1103 Posted February 11, 2016 Share Posted February 11, 2016 Hi I would to have some opinions about a new task i have regarding inserting records into database This is school scenario The school has private lessons and the principal wants to know wich students going to get in the end of the year a full report The students belongs to class The private lessons can have several classes So when i will insert records into database wich approach i must follow 1- Insert by class then choose every student of that class 2- Insert by students and then by student id i can get his class 3- another one Thank you for any opinion Quote Link to comment Share on other sites More sharing options...
Barand Posted February 11, 2016 Share Posted February 11, 2016 Not sure we have the full picture yet Can a student belong to more than one class? Can a student have more than one private lesson? Can a class have more than one one private lesson? Quote Link to comment Share on other sites More sharing options...
gmc1103 Posted February 11, 2016 Author Share Posted February 11, 2016 Not sure we have the full picture yet Can a student belong to more than one class? Can a student have more than one private lesson? Can a class have more than one one private lesson? Can a student belong to more than one class? No, a student belong to one class only (ex 10ºA) Can a student have more than one private lesson? Yes but not in same time (Ex can have English, Maths in different hours time) Can a class have more than one one private lesson? yes (One private lesson can have class A and B and more) Quote Link to comment Share on other sites More sharing options...
gmc1103 Posted February 11, 2016 Author Share Posted February 11, 2016 What i have so far is Table class CREATE TABLE `esmaior_turma` ( `id_turma` int(11) NOT NULL AUTO_INCREMENT, `turma` varchar(100) COLLATE utf8_bin NOT NULL, `estado` tinyint(1) NOT NULL, PRIMARY KEY (`id_turma`) ) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8 COLLATE=utf8_bin and table students Create Table CREATE TABLE `esmaior_alunos` ( `id_aluno` int(11) NOT NULL AUTO_INCREMENT, `user_proc` int(11) NOT NULL, `user_name` varchar(200) COLLATE utf8_bin NOT NULL, `user_id_ano_turma` int(11) NOT NULL, `user_num_turma` int(20) NOT NULL, PRIMARY KEY (`id_aluno`), KEY `user_id_ano_turma` (`user_id_ano_turma`), CONSTRAINT `esmaior_alunos_ibfk_1` FOREIGN KEY (`user_id_ano_turma`) REFERENCES `esmaior_turma` (`id_turma`) ) ENGINE=InnoDB AUTO_INCREMENT=50 DEFAULT CHARSET=utf8 COLLATE=utf8_bin Now i need to think about a table where i can insert records by id_user, what i pretend to to is: When the teacher add new record, he select the class, then select all the students (user_id) presents of that classes and when i make a query by user_id i can check all the lessons he went.. Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted February 11, 2016 Solution Share Posted February 11, 2016 (edited) From what you have said, a lesson can have many classes and each class has many lessons. You therefore have a many-to-many relationship between class and lesson. This would be resolved by using another table to link the two. In this case I suggest it could be a "timetable" table which schedules when each class has a lesson. (See attached model) Given a class it is then easy to find the students in that class. Following the links in the diagram you can find which lessons a student has. Edited February 11, 2016 by Barand Quote Link to comment Share on other sites More sharing options...
gmc1103 Posted February 11, 2016 Author Share Posted February 11, 2016 Hi Barand, i will try to implement your schema. Any doubt i will open a new topic Thank you again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.