Bank related creation

Asked

Viewed 114 times

1

I am doubtful whether or not I am doing the right thing in setting up this bank. They could help if the way is right or wrong. For now I just put id in the tables.

Gang

Turma | Turmaid
    A  1
    B  2
    C  3
    D  4

Municipality

   Municipio | municipioid
   municipioA  1
   municipioB  2
   municipioC  3
   municipioD  4

Professor

Professor | turmaid | municipioid 
  José      3            1
  Maria     2            2
  Allna     4            3

Pupil

 Nome | turmaid | municipioid | ano_ensino
 Joao      1            1         1º
 Cezar     2            2         7º
 Thiago    2            3         5º

I am doubtful because a student may have several teachers or only one, just as the teacher will have several students. I need the teacher to list his students. And that in admin I know which teachers that student has.

Would that be? inserir a descrição da imagem aqui

  • 1

    This is called n:n relationship, or actually, a teacher can have 0:n students, just as a student can have 0:n teachers, at the beginning of the semester, when students have not yet been allocated in classrooms, for example

  • You should create an auxiliary table, aluno_professor, where to store the id_aluno as fk, the id_professor also as fk, and id_aluno_professor being the pk.

  • @Marcelobonifazio I started to do this but I thought I was wrong then I stopped.

  • 1

    No, that’s right, inside the table aluno_professor you may also have other attributes, such as id_sala, id_turma, and etc... it varies from the scope of your problem

  • But both are related by id of the class, what’s the problem ?

  • @Marcelobonifazio would be like I asked the question?

  • last doubt rsrsr @Marcelobonifazio when I will popular the tables I will need popular at the same time this teacher relacao_correct student?

Show 2 more comments

1 answer

2


Relationship between entities is the type of occurrence between entities.

Types of relationship:

There are three types of relationship between entities:

one-on-one

one-to-many

many-to-many

In your case applies many relationship to many N:N.

You can define the relationship as follows: Cardinalidade N:N

Cardinality

Cardinality is an important concept to help define the relationship, it defines the number of occurrences in a relationship. To determine the cardinality, one must ask the question concerning the relationship in both directions.

A teacher has how many students?

  • not less than 1 and not more than N.

One student is allocated in how many classes?

  • not less than 1 and not more than 1

Adding the cardinalities, we define the final result of the relationship, i.e., 1:N

More information here.

  • would be as I put in question?

  • This msm, you can create an auxiliary table to make the relations between teacher and students, so you can see which teachers have certain students and which students have certain teachers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.