If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Need help creating a trigger

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-15-03, 20:39
klecks21 klecks21 is offline
Registered User
 
Join Date: Apr 2003
Posts: 5
Need help creating a trigger

I have a table called Enrollment which contains StdID, CourseNumber, and EnrollGrade.
StdID CourseNumber EnrollGrade
101 2201 A
101 2203 B
102 2203 C
103 2203 B
103 2201 C
103 1101 B

I need to create a trigger that will not allow a Student to enroll in CourseNumber 2205 until they have completed 2201 and 2203. I can't figure out how to go through each StdID and see if they've taken 2201 and 2203 yet.

Here's what I have so far:
Create or Replace Trigger Enroll_Rule
Before Insert on Enrollment
For Each Row
Begin
--i know i need a select statement here and then and If statement.

and now i'm totally lost. does anybody have any ideas to get me started?? Thanks a lot!
Reply With Quote
  #2 (permalink)  
Old 04-16-03, 05:14
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Try this ...

Hello,

try this ..

Create or Replace Trigger Enroll_Rule
Before Insert on Enrollment
For Each Row

DECLARE

nCount PLS_INTEGER := 0;
no_course_found EXCEPTION;

Begin

SELECT COUNT(1) INTO nCount
FROM Enrollment WHERE stdid = :new.stdid
AND CourseNumber IN (2201, 2203);

IF nCount <> 2 THEN
RAISE no_course_found;
END IF;

END;

... Hope that helps ?

Best regards
Manfred Peter
(Alligator Company GmbH)
http://www.alligatorsql.com
Reply With Quote
  #3 (permalink)  
Old 04-16-03, 13:09
klecks21 klecks21 is offline
Registered User
 
Join Date: Apr 2003
Posts: 5
that helped me out. Thanks a lot!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On