Home>

It is possible to set restrictions on the database side.
For example, foreign key constraints, string length constraints, type constraints, and so on.

So I have a question.
Do you think it makes sense for the program to set the same restrictions again?
For example, in a function that saves in a column with a foreign key constraint, the program (non-database) side confirms "whether a" value "exists in the externally referenced table" and provides an if branch. Etc.

Is it unnecessary because the processing will increase?
If i think you need it, please tell us about the scenarios and benefits you will need.

  • Answer # 1

    If you think you need it, please tell us about the scenarios and benefits you will need.

    You can leave the integrity process to the database side, but the error returned when it failsDatabase errorIf you try to detect "which value is exceeded", handling is troublesome.

    If only the API is provided, it is possible to divide it as "the responsibility for not throwing out-of-range values ​​lies with the API caller", but in the case of a Web system that draws the input form by itself, an error will occur in the input form. In order to correctly understand "where failed" when redrawing, it is better to check the consistency before throwing it to the DB.

  • Answer # 2

    DB foreign key constraints have a strong meaning of master management by normalization.
    For the purpose of validation, I think it makes sense to apply appropriate processing on the program side.

  • Answer # 3

    hola soy PERU, estoy de acuerdo.