English 中文(简体)
努力进行数据库设计/关系
原标题:Struggling with database design/relations

I m trying to make a database for a construction depot (there where are stored materials for construction). I need to know all the materials stored (products in), all the products sold and all the products that had left. I m thinking to do like this:


Products--> Deliver <--Depot (many to many) - here I see all the products in.

Depot--> Sell <--Products (many to many) - here I see what I have sold.

And what is left: To make a difference between "Deliver" and "Sell".

有什么正确之处吗?你还有别的主意吗?谢谢你的帮助。

最佳回答

处理清单跟踪系统的另一个办法是,将清单跟踪系统像“强”双入式会计(/强)系统一样处理。这将需要您将您的 Deliver 表格合并成一个清单movement 表格。每次移动包括两个记录,一个记录为正数,另一个记录为负数。

以这种方式对待库存系统的优点是,很容易使用汇总查询来获得任何仓库某一时间点的任何产品的库存状况(库存)。


<强度 > EDIT: 表结构...

PRODUCT
-ID (PK)
-Description
-...

DEPOT
-ID (PK)
-Name
-Location
-...

MOVEMENT
-ID (PK)
-DateTime
-ProductID (FK)
-DepotID (FK)
-Quantity /* Positive=Increase, Negative=Decrease */
-OffsettingMovementID (FK) /* Points to the other half of the entry */
问题回答

暂无回答




相关问题
How to model a many-to-many relationship in App Engine?

I have a question regarding how to model a many-to-many relationship in App Engine: A Blogentry can have many tags, a tag can apply to many blog entries. I see a couple of scenarios: Use a Set of ...

How to emulate tagged union in a database?

What is the best way to emulate Tagged union in databases? I m talking about something like this: create table t1 { vehicle_id INTEGER NOT NULL REFERENCES car(id) OR motor(id) -- not valid ... } ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

How to best implement a 1:1 relationship in a RDBMS?

Yesterday while working on a project I came up on a peculiar 1:1 relationship which left me wondering - how to best implement this (clearly, we had done it wrong :D) The idea is that there are two ...

Automatic filling entity properties

I have some type an architect(?) question I develop an application, based on Spring and Hibernate (annotated configuration) For each table in my database I added 4 fields: createdBy and modifiedBy(...