In the Database Design part of this course we will spend a lot of time studying constraints. Constraints play an important role in improving the quality of a database by eliminating errors in the data manipulation.
Constraints indicate that the data in the database must have a certain property. If someone tries to change the data in such a way that the database no longer satisfies that property the database will refuse the update. The constraint can be a property of the database as a whole, in which case we call it a static constraint, or it can be a property of the change caused by the update, in which case we call it a dynamic constraint. In this course we only look at static constraints. A good example of a simple constraint is a checksum embedded in certain numbers, like bank accounts and student identities. A typo in such a number is immediately detected by the database and the transaction is then refused. Other examples of constraints are that a birth-date cannot be in the future, people are allowed to have only one birth-date, some bank accounts are not allowed to have a negative balance, the amount withdrawn through an ATM cannot exceed 1000€, etc.
Constraints cannot prevent all errors. You can transfer 120 or 130€ to a friend and the bank has no way of knowing whether 120 or 130 is the correct amount.
Constraints can also be used to help a database designer in changing the database schema in order to avoid redundant storage of information. For instance, it is not a good idea to store people's birth-date and age as one can be derived from the other. And since a bank account can have only one balance, the database schema should be such that the balance of an account is stored only once, even if for instance the account is shared between two people.