Validation - Data Integrity
A table can only store 10 records in a particular state, 10 users over 30 years for example, the others must be less than 30 years. It is a business rule and as such should be respected. How to 开发者_如何学运维ensure that state? Think: multiple users accessing this table.
Explicit Locking?
This requires a business layer method for create and update operations. read and delete can be allowed. Those synchronized add and create methods implement the business rule and respond with an error status.
Either make some ugly database procedure (and be hated forever by whoever is forced to maintain it), or simply enforce the rule in the bussiness layer (probably in some "storeUser(User user)" method). If you have many different places in the code from where you are storing users, then this will be a valuable lesson in architecture design :)
SIRA_PRISE allows you to just declare that constraint in algebraic form, and SIRA_PRISE will enforce your constraint for you without you having to write any code what so ever.
Or, second-best option, you can write triggered code in some SQL system and hope you haven't made any mistakes/overlooked anything, but your chances for that are not so good. "Applied Mathematics for database professionals" has a whole chapter devoted to this very problem. Be in for quite a few aha-erlebnisses.
Or, third-best option, you can write application code to enforce your constraint and hope no one will ever make another application doing updates to your database and overlook the constraint (the chances of which are pretty high, because, honestly, where is the appropriate place that you can document the existence, let alone the formal specification, of your constraint ?). I haven't seen any great facilities for that in neither ER nor UML.
精彩评论