-1

One of my professor said: "If we consider that, if constraints are sometimes completely avoided and therefore not defined in some database of some project, it is only at the application level that we can manage data integrity."

In which condition can we avoid constraints on database? Please I need your help

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Miguel
  • 11
  • 1
  • You should ask your professor for examples. – Gordon Linoff Aug 21 '19 at 16:26
  • I don't think your professor meant to say "don't use data integrity at database level". What he said was, if you don't use data integrity at database level, you will have to implement all that at the applicative level. I've been in some projects without database constraints, and was a real pain in the ... But that happened because the begginer of the project didn't have the knowledge to use all the tools the database have. – Antonio Veneroso Contreras Aug 21 '19 at 16:32
  • If a professor said it, why would you not ask for clarification or go to office hours? – dfundako Aug 21 '19 at 16:49

1 Answers1

1

You should ask your professor to clarify their statements, not Stack Overflow.

It's appropriate to use database constraints in many cases.

For example, consider a case where a single database is used by multiple applications. If you were to enforce data integrity in the application, then you would have to implement the data integrity rules multiple times, perhaps even in different programming languages if the client apps are written in different languages. If you don't implement the data integrity logic with the same behavior in all apps, then you might create data in one app that is invalid for the other apps.

Whereas if you implement data integrity constraints in the database, then all apps must conform to a single set of constraints. Data will be valid for all apps, and there's no chance of anomalies. This is a good thing.

There are exceptions to every rule, of course, but in general it's a good idea to implement logic in one place. This is sometimes referred to as the DRY principle of software design, i.e. Don't Repeat Yourself.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
  • I finally found the Answer of my question. My lecturer told me that, we manage data integrity at the applicative level to optimize the computing performance of the RDBMS and facilitate database evolution – Miguel Sep 03 '19 at 12:06
  • That's risky, because if you have multiple apps or even one app with multiple code paths writing data to that database, you could have inconsistent enforcement of the data integrity you want. How much do you trust that all code accessing that database has exactly the same implementation? – Bill Karwin Sep 03 '19 at 16:59
  • Anyway, I'm glad you got your lecturer to give you their reasons. – Bill Karwin Sep 03 '19 at 17:00