开发者

Abstract table design question

I am working on one document system and got some logic/architectual problems. In th开发者_JAVA百科is system will be many types of documents - incoming, outgoing, etc. Every document type have its own number of cols whitch must be filled. On the paper all is easy, but in software - I need some advice :)

For example:

incoming document type 1 have 16 cols, 
outgoing document type 1 have 15cols, 
inner document have 9 cols,
etc...

At first I thought, that I will make one table, named "Categories" where will be stored (in tree) document types (incoming, outgoing, etc) and one generic table "Documents" with maximum of possible rows (for example 25) where would be stored all documents and if not used some cell, then ignored it.

After I thougth that I can make a much simpler - for every type of document - own table, but after some thinking is seemed to be worst solution.

So I want the best possible solution for this.

Maybe you can help me?

Thanks!


This is a typical example for table inheritance. You'd do something like this:

Document
----------
DocumentId (PK)
DocumentType
... any columns common to the different formats

DocumentIncoming
----------
DocumentId (PK, FK to Document)
... columns specific to Incoming

DocumentOutgoing
----------
DocumentId (PK, FK to Document)
... columns specific to Outgoing


Use a central "Documents" table that contains a category code and only those columns that apply to every single category.

Then, for each category use a table that links back to the appropriate record in Documents and "adds" the additional columns appropriate for that category.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜