Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 21: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, 06: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, 14: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

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