I have two tables. I want to create a trigger in a table carthat will be inserted or deleted in the table fueldepending on a specific value.
Car
id - SERIAL
fuel - BOOLEAN
Fuel
car_id - INTEGER
I do not include these lines, since the trigger description is not needed.
Basically, I want to create a trigger in a table carthat:
- Works with insert or update.
- Inserts
Car.idinto a table fuelif Car.fuel is true. - If
Car.fuel is false, the trigger should delete all rows in the table fuel, where Fuel.car_id = Car.id.
How should I do it?
EDIT: To clarify, I'm using Postgres
source
share