4
I am developing a report in my system to control the productivity of teams, the table of teams has the following information:
(tblequipe)
| id (pk) | nome | meta |
| 1 | EQ01 | 5 |
| 2 | EQ02 | 7 |
| 3 | EQ03 | 6 |
One problem I found was to display the productivity of teams when data did not exist, for example, how I will consider the team’s productivity on 01/01 if there is no release (this release is in a table that contains the raw data, that is, several records that will be summed giving the total amount executed on a certain day) on that date? So I thought I’d create these two tables:
(tblmapa)
| data | id_equipe | meta |
| 01/01 | 1 | 5 |
| 02/01 | 1 | 5 |
. . .
. . .
. . .
| 31/01 | 1 | 5 |
---------------------------------
(tblprodutividade)
| data | id_equipe | executado |
| 01/01 | 1 | 9 |
| 05/01 | 1 | 3 |
| 06/01 | 1 | 5 |
Done this would be able to recover the data with this select:
SELECT
m.data,
m.id_equipe,
m.meta,
isnull(p.executado, 0) executado
FROM
tblmapa m
left join tblprodutividade p on (p.data = m.data and p.id_equipe = m.id_equipe)
My question is about tblmapa
and the tblprodutividade
, would like to know if it is more appropriate to create a column id in each of them as Identity Primary key and define the columns data
and id_equipe
as Unic or maybe just create the columns data
and id_equipe
as Primary key composed.
Additional
I would like an answer that takes into account the performance and storage space of Primari key + Unic or Primary key composed, the columns being of the type date and int respectively.
Related question
When the use of composite primary key is recommended?