Jump to content

Implementing new table


gmc1103
Go to solution Solved by Barand,

Recommended Posts

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

  • Solution

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.

post-3105-0-58813100-1455196638_thumb.png

Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.