I’m pretty new to databases and SQL, but as a homework I have to create a database for a homeless shelter.

This is the relational model.

My problem is the following: I want to create a trigger that won’t allow me to insert a new entry of a person that already exists in Persoane (so inserting into Cazare will fail) if the previous Gravitate abatere (if there is one) from Observatii is above 6 and it hasn’t passed x months from last accommodation.

The idea behind this logic is to not let someone who has done a bad thing rated above 6 in the shelter for x months. This being the first database course that i have to take in my uni we don’t learn triggers yet so i have no idea on how to do it. Any help is appreciated.