Answer the question
In order to leave comments, you need to log in
Triggers in MySQl, PostgreSQL?
I can’t understand triggers at all: everything is muddy in Google.
There is a table with columns: id, balance, refer. It is necessary, for example, when requesting
UPDATE talbe SET balance = balance + 100 WHERE id = 1
, execute also the request ( in the request: 50 = 100 from the first request / 2 )UPDATE talbe SET balance = balance + 50 WHERE id = РЕФЕР 1-го
. This whole thing can be implemented through triggers, but how?
Answer the question
In order to leave comments, you need to log in
It is possible, but if it is cloudy for you, then it is better not to do it.
Execute these two queries from code.
Because with this logic of work, you may have cyclic execution of triggers depending on the correctness of your database data and the code of the triggers themselves
. Problem:
https://stackoverflow.com/questions/10699673/a-tri...
One of the options for solving it:
https://stackoverflow.com/questions/9570204/how-to...
EMNIP, in the trigger it is impossible to change the table on which the trigger works. So either in the client or write a stored procedure.
First, you get an infinite loop.
Secondly, if you need this, I advise you to seriously think about the architecture, such a task should not have arisen.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question