Should data validation be done at the database level?

后端 未结 12 1486
半阙折子戏
半阙折子戏 2021-02-07 02:45

I am writing some stored procedures to create tables and add data. One of the fields is a column that indicates percentage. The value there should be 0-100. I started thinkin

12条回答
  •  走了就别回头了
    2021-02-07 03:23

    If you have a good data access tier, it almost doesn't matter which approach you take.

    That said, a database constraint is a lot harder to bypass (intentionally or accidentally) than an application-layer constraint.

    In my work, I keep the business logic and constraints as close to the database as I can, ensuring that there are fewer potential points of failure. Different constraints are enforced at different layers, depending on the nature of the constraint, but everything that can be in the database, is in the database.

提交回复
热议问题