Below I have shown a basic example of my proposed database tables.
I have two questions:
Categories " Engineering ", " Client " and " Vendor " will have exactly the same " Disciplines ", " DocType1 " and "DocType2", does this mean I have to enter these 3 times over in the " Classification " table, or is there a better way? Bear in mind there is the " Vendor " category that is also covered in the classification table.
In the " Documents " table I have shown " category_id " and " classification_id ", I'm not sure if the will depend on the answer to the first question, but is " category_id " necessary, or should I just be using a JOIN to allow me to filter the category based on the classification_id ?
Thank you in advance.
Table: Category
id | name ---|------------- 1 | Engineering 2 | Client 3 | Vendor 4 | Commercial
Table: Discipline
id | name ---|------------- 1 | Electrical 2 | Instrumentation 3 | Proposals
Table: DocType1
id | name ---|------------- 1 | Specifications 2 | Drawings 3 | Lists 4 | Tendering
Table: Classification
id | category_id | discipline_id | doctype1_id | doctype2 ---|-------------|---------------|-------------|---------- 1 | 1 | 1 | 2 | 00 2 | 1 | 1 | 2 | 01 3 | 2 | 1 | 2 | 00 4 | 4 | 3 | 4 | 00
Table: Documents
id | title | doc_number | category_id | classification_id ---|-----------------|------------|-------------|------------------- 1 | Electrical Spec | 0001 | 1 | 1 2 | Electrical Spec | 0002 | 2 | 3 3 | Quotation | 0003 | 3 | 4
From what you've provided, it looks like we have three simple lookup tables: category, discipline, and doctype1. The part that's not intuitively obvious to me and may also be causing confusion on your end, is that the last two tables are both serving as cross-references of the lookup tables. The classification table in particular seems like it might be out of place. If there are only certain combinations of category, discipline, and doctype that would ever be valid, then the classification table makes sense and the right thing to do would be to look up that valid combination by way of the classification ID from the document table. If this is not the case, then you would probably just want to reference the category, discipline, and document type directly from the document table.
In your example, the need to make this distinction is illuminated by the fact that the document table has a referenc to the classification table and a references to the category table. However the row that is looked up in the classification table also references a category ID. This is not only redundant but also opens the door to the possibility of having conflicting category IDs.
I hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.