2
I am creating an application where I thought of a possibility to insert all existing addresses in the system in a single table, both for users, customers, suppliers etc. the structure of my table then would look like this:
__id => CHAVE_PRIMÁRIA
__status
* idReferencia => CHAVE_EXTRANGEIRA_CONJUNTA (REF. GENÉRICA COM BASE NO txTabela)
* txTabela => CHAVE_EXTRANGEIRA_CONJUNTA (STRING: 'CLIENTE','FORNECEDOR',etc)
txGenero
nmCep
txLogradouro
txComplemento
txBairro
txLocalidade
txUf
txIbge
Is there any way I can mount this foreign key using an existing string in the field txTabela
? or will I have to keep these addresses on numerous different tables and significantly increase the size of my database without need? (Bs, this would also occur with contacts, documents and other types of generic values)
I am sure that if I do not use foreign keys I will be able to build the structure of my system completely, but with the keys the data loading improves..
Yeah, but by doing so, I’d raise a relationship. and as addresses are not records so flexible it’s okay for me to have a data-based link within the table... my intention is to reduce the number of repetitive tables based on associative columns from within the program
– LeandroLuk
Anything other than this you are creating a reference fragility within your bank. Some Frameworks use discriminators, which are columns string indicating which table the key came from, but are weak associations, not checked by the database. I can give another much more complex answer, with conference by triggers, but I find a whim close to the answer provided.
– Leonel Sanches da Silva
yes agree, that could generate a weakness in the database, but for the type of data to be used, and the form of administration of what I want to build, I believe it is a "creative" option. in the case of the information that will be inserted they are already weak associations so there is no problem ;D
– LeandroLuk