Trigger sum constraints [message #446276] |
Sun, 07 March 2010 07:45 |
cronin
Messages: 2 Registered: March 2010
|
Junior Member |
|
|
First of all, I'm very new to oracle and sql in general so this question may be obvious, impossible, or anywhere in between.
Basically, I need to fulfil the constraint:
"student cannot have more than 100 points"
I'm pretty sure I need to use a trigger to do this, but I don't understand how this would work.
Written in plain english I imagine it work work something like:
AFTER UPDATE
WHERE student.lessonid = lesson.lessonid
IF SUM(lesson.points) > 100 then ROLLBACK
lessonid is the only field relating the two tables.
--
Again, I apologise if this is a daft question, I hope someone can at least point me in the right direction to being able to fulfil that criteria, whether it be using triggers or not.
Thanks!
|
|
|
Re: Trigger sum constraints [message #446277 is a reply to message #446276] |
Sun, 07 March 2010 08:03 |
gkrishn
Messages: 506 Registered: December 2005 Location: Putty a dark screen
|
Senior Member |
|
|
why dont you write it in a plsql block.
if (your condition)
then
exit;
end if;
you can even create within a procedure or function.
|
|
|
|
|
|
|
Re: Trigger sum constraints [message #446288 is a reply to message #446276] |
Sun, 07 March 2010 09:11 |
cronin
Messages: 2 Registered: March 2010
|
Junior Member |
|
|
My apologies for not being clear, the student should be able to take more than one lesson (each lesson is a maximum of 20 points), summing up to a total of <= 100.
|
|
|
|