'Limiting the number of data user can insert in database using java [closed]
So I am making a course management system using java I completed everything but could not figure out how I can limit the number of data for a certain data.
So in my database, I have two columns: courses and modules:

So in the database, a course can have multiple modules so what I want to is that course in a semester can have only four modules and if the module is for level six students for each semester user can give Two compulsory modules and two electives(optional) modules where each level consists of Two Semesters so if the user tries to enter error message will pop up. Even a simple suggestion will be great I just need to get an idea of how I could do it. Any help is appreciated.
Solution 1:[1]
Sounds like you have a business rule where parent records on one table are expected to have a certain number of related child records in another table. For example, you might have a rule where an invoice row must have one or more related line_item rows, and not zero.
You can enforce that rule in at least these two ways:
- Your app checks for this during (a) data-entry and (b) data-retrieval.
- You establish a database trigger that runs in the server automatically when inserting or updating or removing rows from those particular tables. A trigger can throw an error if the rule is violated. That error causes the transaction to be rejected.
The safest approach is to do both. Checking within the app is often more convenient, before involving the database. But if your app has any bugs there in that checking code, or admins may be altering the data outside of you app, the trigger is your fallback to make sure the business rule is observed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

