My database schema has a ‘locked’ setting meaning that the entry can not be changed once it is set.
Before the locked flag is set we can update other attributes. So:
- Would you check the locked flag in code and then update the entry
or
- would it be better to combine that into a SQL query, if so, any examples?
EDIT: how would you combine the update & check into one SQL statement?
You should do both. The database should use an update trigger to decide if a row can be updated – this would prevent any one updating the row from the back tables accidentally. And the application should check to see if it should be able to update the rows and act accordingly.