1
I have a table A
with a field start_date
and another end_date
.
I have a table B
with a field date
.
Is there any way to ensure that a record is only saved on B
when B.date
be among A.start_date
and A.end_date
?
I know how to handle insertion via PHP. But I want to know if there is something that can be done in the Bank that guarantees this type and integrity. I’m looking for something in the constraints' line of action (but any solution is welcome!)
Search how to create a TRIGGER in UPDATE
– Bacco
Via Trigger is possible, but I believe you will need to use the 3 (Insert, delete and update) to ensure that none operation is made in case of non-compliance with these rules. Advice: If this rule is something related to 'closing' control (retroactive or out-of-jurisdiction drives) run away from the bank and deal with the application, since you have more. Otherwise you will become the trusted database squire for the rest of this system’s life
– Diego Rafael Souza
@Diegorafaelsouza totally agree on the application part. I think delegating too much intelligence to DB is losing control of the situation. By the way, if there’s one thing I see ugly in some common systems here in the region (especially Delphi + Pgsql) is that the guys put so much logic in DB, that the thing has side effect all the time.
– Bacco
@Bacco Yes, it is a very common practice in legacy systems and a problem that if we do not take care of ends up spreading in the current ones. The technology (and techniques) that we have available today have come to solve highly hairy problems of these types of conduits that were adopted in the older systems... if we don’t watch out, we’ll just keep wiping ice with hi-tec wipes -.-'
– Diego Rafael Souza
@Diegorafaelsouza It is a simple operation and will not backdate. When creating an event, I need to ensure that it is between the availability interval.
– Brunno Vianna