MySQL - Foreign Key Constraint between Tables

1

Below I've created 4 fictional tables for illustration

The Teacher and Student tables are referenced by Address and Documents. However, how can I create a foreign key in the last two tables that Professor OR Student references? If I create a key for each, can the bank be inconsistent? Is there another way?

    
asked by anonymous 26.12.2017 / 19:58

1 answer

2

Two alternatives:

1 - Create a table TB_PESSOA with id, id_address and id_document

TB_ALUNO and TB_PROFESSOR receive the field id_people

It is easier if you want to create a third type of user, besides being easier to convert to object oriented programming logic

2 - Create another TB_PESSOA table, and move all fields from TB_ENDERE and TB_DOCUMENT to TB_PESSOA and make them optional . It gets less fragmented and easier to manage.

    
26.12.2017 / 20:03