This is a conceptual question. In general, modern programs are built in 3 layers:
- Presentation
- Business logic
- Database
As a rule, Level 1 can choose to check all the input data in a modern application, providing the user with quick feedback about possible problems (for example, the JS pop-up message "this is not a valid email address").
Level 2 must always perform a full audit. This is the gateway to the server, and it can check complex relational constraints. This ensures that no corrupted data can enter the database in any way that is validated against the limitations of the application. These restrictions are more complicated than you can check in the database in any case (for example, the bank account number here in the Netherlands should be from 3 to 7 numbers, or 9 or 10 and correspond to the value to check the check digit ).
Level 3 can perform a check. If there is only one “client”, this is not a necessity in itself, if there is more (especially if there are “less trusted” users of the same database), it must also be in the database. If the application is critical, it is recommended that you also perform a full check in the database using triggers and restrictions, just to have double protection against errors in the business logic. The task of the database is to ensure its integrity, and not compliance with certain business rules.
There are no clear answers to this question, it depends on what your application does and how important it is. In the banking application - check all 3 levels. In an online forum, check only where necessary and serve additional users with performance benefits.
Niels keurentjes
source share