I have a system that carries out a general inspection of the entire labor process on a daily basis, assigning certain values to it.
Each inspection is formed by 3 stages, where each stage has its own set of values (3 records).
The tables are as follows:
--INSPECCION--
ID_inspeccion
fecha
hora_inspeccion
etapa
realizador
--CALCULOS--
ID_calculo
valores
--INSPECCION_CALCULOS--
ID_inspeccion_calculo
inspeccion_fk
calculo_fk
The relationship is as follows:
INSPECTION will keep a unique ID for each record, next to the date, time and stage of the inspection.
There would be 3 records in the database .
INSPECCION_CALCULOS will save the id of the inspection to which the group of calculations belongs and the id of each group of calculations.
It would be 9 records, because 3 times the inspection appears, plus 3 groups of calculations .
CALCULATIONS saves the values of the calculations corresponding to each stage of the general inspection.
This is a string with values .
A serious example of a serious inspection day:
--INSPECCION--
ID_inspeccion | fecha | hora |etapa
1 | 1-3-2018 | 9am | primera
2 | 1-3-2018 | 2pm | segunda
3 | 1-3-2018 | 11pm |tercera
--CALCULOS--
ID_calculo |valores
1 | 100, 200, 300
2 | 100, 200, 300
3 | 100, 200, 300
4 | 100, 200, 300
5 | 100, 200, 300
6 | 100, 200, 300
7 | 100, 200, 300
8 | 100, 200, 300
9 | 100, 200, 300
--INSPECCION_CALCULOS--
ID_inspeccion_calculo | inspeccion_fk | calculo_fk
1 | 1 | 1
2 | 1 | 2
3 | 1 | 3
4 | 2 | 4
5 | 2 | 5
6 | 2 | 6
7 | 3 | 7
8 | 3 | 8
9 | 3 | 9
I already have the insertion and the view of the data ready.
I make my inquiries using the date, because the date should not be repeated three times daily, so I get the group of 3 inspections.
My problem is : wanting to centralize these three general inspection records in a table, I do not know how to generate a unique id for each collection of three records, in order to erase the records easily.
I ask: Would it be effective to erase by date, validating (assuring) that there are only three records per day and that there can not be more with the same date?.
I thought about generating a central call table like this:
--CENTRAL--
id | id_central | inspeccion_fk
And that something like this would remain:
**CENTRAL**
id | id_central | inspeccion_fk
1 | 1 | 1
2 | 1 | 2
3 | 1 | 3
Where the id_central
is a unique value per day.
How can I unify these three records per day? Does any form of auto increase every 3 records?