Depends on what these services are.
If the services are specific to this request, that is, they are line items that the request should have, then it is 1-N
. For each request you have multiple services. But a service can only be on one request.
But if the services are generic and are registered in the request directly, then you have a relationship N-M
(N-N
would mean that the relationship should have a number of symmetrical items). You have a request that is composed of multiple services. Each service can be in as many requests as needed.
So the description is the second way. But in general this is design bad. It would be right to have a table of Itens de solicitação
in relation to 1-N
. And each item have a relationship with Serviços
of N-1
. That is, each request item has a related service, but each service can be in any number of request items.
With the question editing and placement of the diagram, it seems that the table Servico
works as a request item, so it would be 1-N
. The name gives wrong indication of what the table is. The column codigo
also weird. Is the code of this service? And how links with the request? If this is the request code, it has a link, but then it would have to be 1-1
since it would not be possible to have a primary key otherwise.
Modeling depends a lot on the specific situation. You have some basic ideas to follow but without fully understanding the problem it is difficult to say anything. And from what I see, one of the biggest difficulties for developers is completely understanding the problem. When escapes a detail and models wrong will pay up there. I still miss a lot, even with more than 35 years of experience. But I make a great effort to get it right because this is more important than most of the other skills in our work. Understanding the wrong problem will certainly produce the wrong solution and it is not always obvious until it is too late and it is much more difficult to fix the problem.
One more detail: you are using double
for monetary values, this is terrible, see What is the correct way to use the float, double and decimal types?. The use of long
for the codes does not seem appropriate to me.
if your service can only have one request then it would be 1-N ( one request for multiple services).
– Rafael
Like, is this service only good for this request at the time of this registration? For example if I start a second registration and use the same service registered in the first would still be 1-n?
– DiegoAugusto