Why are constraint applied in Database? Will it not be more flexible to be in code?
I'm reading a beginners book on implementing databases, So this is a beginner's question!
Let's say I design a database model, Which has this entity model:
Person, Has subtypes: Employee , Student
Student's subtypes: Graduate, Undergraduate
Employee's subtypes: Teacher, Administrator
A registered person on system can be only an Student, Or Employee, Person entity requires uniqueness of social number (which every person has only one ofcourse).
If one day the college decides that teachers (an Employee subtype) can also be student, Taking courses in their free time (It's very improbable but I cant think of anything else right now), It's much harder to change database design which could have thousands of entries, Rather than just changing the logic in code that didn't allow a person be registered both as an student and an employee.
Why do we care about business rules in database design rather than in code?