this is my first question on stack-overflow, i am a full-stack developer i work with the following stack: Java - spring - angular - MySQL. i am working on a side project and i have a database design questions.
i have some information that are common between multiple tables like:
- Document information (can be used initially in FOLDER and CONTRACT tables).
- Type information(tables: COURT, FOLDER, OPPONENT, ...).
- Status (tables: CONTRACT, FOLDER, ...).
- Address (tables: OFFICE, CLIENT, OPPONENT, COURT, ...).
To avoid repetition and coupling the core tables with "Technical" tables (information that can be used in many tables). i am thinking about merging the "Technical" tables into one functional table. for example we can have a generic DOCUMENT table with the following columns:
- ID
- TITLE
- DESCRIPTION
- CREATION_DATE
- TYPE_DOCUMENT (FOLDER, CONTRACT, ...)
- OBJECT_ID (Primary key of the TYPE_DOCUMENT Table)
- OFFICE_ID
- PATT_DATA
for example we can retrieve the information about a document with the following query:
SELECT * FROM DOCUMENT WHERE OFFICE_ID = "office 1 ID" AND TYPE_DOCUMENT = "CONTRACT" AND OBJECT_ID= "contract ID";
we can also use the following index to optimize the query: CREATE INDEX idx_document_retrieve ON DOCUMENT (OFFICE_ID, TYPE_DOCUMENT, OBJECT_ID);
My questions are:
- is this a good design.
- is there a better way of implementing this design.
- should i just use normal database design, for example a Folder can have many documents, so i create a folder_document table with the folder_id as a foreign key. and do the same for all the tables.
Any suggestions or notes are very welcomed and thank you in advance for the help.