How to relate tables

1

Good afternoon.

I have three tables: tbl_alunos, tbl_responsible_financial, tbl_responsavel_pedagogico.

The idea is for a student to have a financial officer and a teacher.

But there are three situations:

A) A student can be responsible for himself, both financially and pedagogically.

B) A single person can be responsible for a student, both in the financial and in the pedagogical part.

C) A parent can account for more than one student (in the case of one parent and multiple children).

So I can not build the structure so that it is consistent. For example:

  • In situation A, I end up having to create the data in the student table and repeat the same data in the other tables. For the student is responsible for himself.

  • In situation B, I have to create the same data in the tables of responsible financial and pedagogical. Because the same person plays the role of both.

In the way that I thought (creating the tbl_alumns with foreign keys of the tbl_responsible_financial and tbl_responsevel_pedagogic tables, it is not good). Thus we assume that there may be a student with 0, 1 or more responsible.

But considering that there is no student without responsibility, it would completely change the relationships I created.

How could I create tables and relationships, but taking care of the three situations, without repeating information and being consistent?

    
asked by anonymous 24.11.2017 / 17:37

1 answer

0

Create only one table by unifying the student, financial and pedagogical registers with some column that refers to what type of register there simply add a column of financial responsibility with respect to it to itself, something like this:

Of course, and the rest of your table information.

For example: Let's start treating the records as a person not to confuse So we would have 3 people as an example, where 1 would be responsible for himself in the 2 cases 2 would have as responsible person 1 and himself and 3 would be responsible himself and 2. And student 4 would not have responsible.

There you would have in the type field, the type of person that is that record, if necessary in your case.

ID | TYPE | NAME | RESP FIN | RESP PEDA |

1 | Student | Person 1 | 1 | 1 |

2 | Student | Person 2 | 1 | 2 |

3 | Student | Person 3 | 3 | 1 |

4 | Student | Person 3 | null | null |

    
24.11.2017 / 17:45