Standard information for a record

0

I have a [produto] table and a [produto_embalagem] table, which can contain multiple packages of a single product.

The discussion is whether the default product packaging should be a markup in the [produto_embalagem] table or a [id_produto_embalagem] field in the [produto] table.

    
asked by anonymous 11.12.2017 / 14:00

1 answer

0

Technically it works with either one of the ways. You should check which of the two forms provides the best% of% of the bank. This will depend on the queries that are posted to the database, so you need to analyze the applications that connect to that database and see which queries they usually launch.

For example, if the application usually needs to get the product from a certain standard package, the following query will repeat itself enough:

select * from produto where id_embalagem_padrao = 123

So in this case, it makes sense to have FK in the index table and create an index for it.

However, if it is more common for the application to fetch the default packaging for a given product, the following query will repeat itself enough:

select * from produto_embalagem where id_produto_padrao = 123

Then in this second scenario you will prefer to have FK in the produto table and have an index for it.

You should review your application and see which of the two situations is most common.

    
11.12.2017 / 14:32