Question

here are the structures of my two tables(primary keys in bold and foreign keys in italic text)

service_agreements(id, client_id, amount, date_begin, duration, *services_id_1*, *services_id_2*, *services_id_3*, *services_id_4*) services(id, date_provided, description, staff_person)

the idea behind the tables is that based on an agreement the company provides service up to four time. so as seen, the four fields of service_agreements table (services_id_1,...)has four one-to-one separate relationships with services tables(id field). it seems to me a little bit unusual, because usually i have seen only one relationship between two tables. so.i know whether this is unusual or it is OK, if it is unusual what is the better solution(without merging the fields of services to the service_agreements. because the services tables has also some records on service provided without an agreement.)

Was it helpful?

Solution

The structure could be even nicer:

service_agreements(id, client_id, amount, date_begin, duration);

services(id, date_provided, description, staff_person);

service_agreements_services(id, type enum(service1,service2 etc), service_agreement_id, service_id);

New table, service_agreements_services add a many to one relationship between service_agreement and services;

Advantages:
1) For every new service you provide there will be new insertions(usually less overhead than update)
2) You can even provide larger no services :)
3) Table relationships get easier.

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top