Data Model Inventory TypeOperations Movements

1

I have a doubt in my data model in the Movements table, in that table I have an AffectedId field, which is going to relate to Sales, Purchases, Promotions, Prizes, Donations, Warehousing, etc. In the Table TypeOperacion is where these operations that I just mentioned will go.

How can I control the referential integrity of AffectedId that is in Movements ?, would there be another modeling solution for this case?

This modeling could be another option.

In the table Operaciones register the ID afectado in which I indicate the type of operation, by TipoOpearacionId and it would not be made with Compras , Ventas , Promocion , etc. The referential integrity could be controlled by a Triggers.

    
asked by Pedro Ávila 26.08.2016 в 18:52
source

1 answer

0

Do not follow that path because it is a bad idea

In the Movements table define two fields SaleId and BuyId (this will of course allow null)

Then when inserting the record in Motion you assign VentaId in case of a sale or to CompraId in case of a purchase, leaving the one that does not correspond in null

Can not relate a single field with two different tables

    
answered by 26.08.2016 / 19:12
source