4
I need to create an agenda where I allocate a service provider to work for a client.
For example: Prestadordeservicos João will provide services to the customer condominium valley of the sun on the day March 15, 2016 from 10:00 to 12:00.
João can not be registered on the same day/ time for another client.
Having the table Service provider with name and PK cod_provider, Client with razaoSocial and PK cod_client and Scheduling with Datetime Inicio , Datetime Fim, Fk_prestador, Fk_cliente e PK cod_agendamento.
How do I ensure that a service provider is never allocated at the same time to different customers?
Using Trigger : http://stackoverflow.com/questions/1355921/sql-server-2008-help-writing-simple-insert-trigger, http://stackoverflow.com/questions/18502802/trigger-to-prevent-insertion-for-duplicate-data-of-two-columns
– Guilherme Lautert
@Guilhermelautert if anyone tries to register John from 11:00 to 13:00 on March 15, 2016, as I know this time schedule conflicts with the 10:00 and 12:00 schedule of March 15, 2016?
– John Diego
http://stackoverflow.com/questions/11012099/query-to-check-overlapping-ranges-in-sql-server, no postgres serial overlaps
(TIMESTAMP '2016-03-10 10:00:00', TIMESTAMP '2016-03-10 12:00:00') OVERLAPS (TIMESTAMP '2016-03-10 11:00:00', TIMESTAMP '2016-03-10 13:00:00')
– Guilherme Lautert
@Guilhermelautert Excellent, Rigadão !!
– John Diego