c# – Application-level constraints or database-level constraints?


Let's say there is an application that works with a database.

The application is inserting some records and some value must always be unique (This is not a primary key).

For example, in one category there can be no products with the same names.

So, on the side of which is it better to make such restrictions?

If you do it on the side of the database, then the database itself will analyze everything and return an error, if you do it on the side of the application, you will need to write logic.

Simply, I looked at some sources and found that restrictions are made at the application level, and are omitted on the database side.


General restrictions – domain restrictions – are best done on the DBMS side, since they are shared by all applications. This, in addition to control over the data, will avoid code duplication.

Scroll to Top