There is a way to use as a value default field, so that it does this update as per condition?
Not in every database I know, although technically it would be possible, but it would probably be extension to the default SQL. Mysql does not allow.
Otherwise, you’d have to do update or even by Trigger?
For update
you can do whatever you want, but it does not seem to be what you want, even because parole could not be used alone, and is not guaranteed.
Triggers were created precisely for this scenario, every time a specific change is made an action must be made, that is, one action fires another under the control of the SGDB itself.
Obviously this scenario requires a conditional and the trigger needs to be powerful enough to support this kind of thing, so it is likely that something more than pure SQL is required, probably needs a programming language, even if based on SQL. Mysql has IF
.
What other options?
Do in the application, which has its advantages there, but also disadvantages, especially if you do not know how to do it correctly, is not guaranteed, the application needs to be correct (which for me is not a problem if the person knows what they are doing, it depends on the person having a Dev or DBA bias).
from to make the Rigger after update, my recommendation would be to do this in the backend.
– HudsonPH
@Hudsonph There is no way to use default expression then?
– rbz
It would be a duplicate of that: https://answall.com/a/172551/112052 ?
– hkotsubo
@hkotsubo No, as I would like by default expression. Trigger would be if there is no option.
– rbz
but DEFAULT GETDATE() would be for Insert and not update
– HudsonPH