开发者

Help modelling an ER Diagram

I am trying to model the following 2 sentences in an ER Diagram:

Each company has a set of tanks. It is also known for each tank how filled up it is for each time of day.

It is not known if there are specific times of day for which there are logs. It can be once a day, twice, each hour, maybe some days you don't have any info, etc.

This is my current attempt:

Help modelling an ER Diagram

(I forgot to put in the Tanks/Dates association an attribute called "current load")

Although for some reason I don't like it (I guess I don't like the Dates entity!). How do you guys generally model this kind of situations?

I think I could instead have a TankLoads entity, with an attribute "Load" and another attribute on the association called "Date".

Thanks

PS: Sorry fo开发者_高级运维r the crappy DIA Diagram :(


Data modeling and database design are not exactly the same thing, even though people often use ER diagrams to summarize database schemas.

There's nothing "unreal" about a date, or a timestamp composed of a date and time. The fact that they are abstractions is no big deal. A bank account is just as abstract.

Whether you are going to have a table of dates or timestamps is another story. In practice, I've found it very helpful to have a table that catalogues every date, or every workshift, in reporting databases. With appropriate attributes, it makes it trivial to produce reports that are weekly, or monthly, or quarterly, or yearly, even when the enterprise has its own quirky fiscal calendar. Some of the attributes might be redundant with functions that are built into SQL, but even then it's a relatively inconsequential design decision.


Help modelling an ER Diagram


Hmm, I would do that slightly different. Put all dates / times in a separate table (I called it Dates for now, but you can also call it times or timestamps or so), and many-to-many them with Tanks. (I used the table FillLevels.)

The level of which a tank is filled is stored in the FillLevels table.

Companies:
- [...]

Tanks:
- company_id: int
- [...]

FillLevels:
- tank_id: int
- time_id: int
- [...]

Dates:
- [...]

I'm sorry for not having a shiny diagram for you, but I home this makes a bit of sense.

Alternatively, you could create a DateTime field in the FillLevels table, instead of using the Dates table, depending on how you intend to query the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜