Quote:
|
If a constraint at the database level prevent things like duplicate entries into a table, do I have to write the same logic at the application level?
|
The database is the best place to ensure that problems don't occur. That way if you forget or make an error in the application code, the program still cannot corrupt the database.
Of course the program needs to be able to handle a database error. It can help by preventing errors in the first place. For example, by giving the user a list of choices or check boxes so they cannot enter an invalid choice. That's more work (and it should get its list from the database so you don't need to update the code if the database changes) but it makes for a better user experience.
Quote:
a) I will have to write the entire logic independent of database
like before the INPUT query I have to make a SELECT query to see if the skill is or not in the database (specific table) and only if it's not to run the INPUT, else to display a message.
|
When the form loads, I would have it query the database to see what options are possible and then make a CheckListBox or series of check boxes so the user cannot add the same skill twice.
Then use error handling just in case something goes wrong despite your best efforts.
Quote:
b) I will have to write only a part and work with the database
like I make just the select query, if the database throw an error I catch it and display the message.
|
That's the minimum you should do. Start with that and then add the fancier CheckListBox stuff if you can.
Quote:
|
c) I do not have to write anything, simply set the constraint to "no action" and discharge the INPUT silently.
|
I wouldn't do that. The user will probably get mad that nothing seems to be happening but he doesn't know why.
Quote:
|
Until now I wrote everything as (a), but now I am wondering if with all the power the db gave me... maybe I can cut some corners or maybe writing all like (a) it is just a waste.
|
I start with (b). Then add (a) if you can. Just be sure to get the information about what choices are possible from the database instead of hard coding that into the program. That way if you add or remove a choice, the program automatically adjusts so you don't need to change the code in both places.