Database modeling helps!

1

I need to make a library system for book loans, in which I wrote this database diagram. the teacher said that this diagram is inconsistent. What needs to be done, are these tables just what I really need?

    
asked by anonymous 06.07.2015 / 00:52

1 answer

3

When modeling tables in a relational database you should start by trying not to repeat the information in different tables by making use of the relationships.

For example, there is a t_alunos_has_t_emprestimos table that seems to be used to relate loans to students and at the same time to books. But the student information already appears to exist in the t_emprestimos table.

I would advise the following process:

  • Define your entities.
    • In this case they will be at least the following Alunos , Emprestimos and Livros . However depending on the requirements you may decide to add more entities. For example, imagine the case where a Student has more than one contact. It may make sense to add a Contacto entity. It's your decision.
    • Be suspicious of tables with many columns. Often this is a sign of the existence of a new entity that deserves its own table.
  • In each of your entities add columns that only relate to that entity.
    • For example fields as nome for entity Aluno . Or titulo , ano , isbn for entity Livros .
  • Think about relationships. Will they be "one for many" or "many for many"?
    • As an example Emprestimo is related only to Aluno , it is a "one to many" relationship. You should put a aluno field in the Emprestimo table.
    • Suppose each Emprestimo can contain several Livros . It's a "many-to-many" relationship. This type of relationship requires a new table. You should define a (pivot) table that contains the relationship between Emprestimo and Livro .
  • Read more about database normalization. You can find some information about the "Normal Forms" here or, if you feel comfortable with the English, here . Try to follow the Third Normal Form.

    It's hard to help otherwise, because everything depends on your requirements.

        
    06.07.2015 / 01:47