473,500 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

i want 2 create a trigger.Plz help as soon as possible

1 New Member
I have 2 tables namely COURSE and STUDENT with fields and constraints as follws

course

course_id number(4) PRIMARY KEY
course_name varchar2(50) NOT NULL
course_duration number(3)


student

roll_no number(4) PRIMARY KEY
name varchar2(50) NOT NULL
marks number(3)
grade char(1)
course_id number(4) FOREIGN KEY


Now i want to create a trigger on student table so that when i insert or update marks field the grade field should automatcally get updated or filled.

marks>80
grade =A
marks 80-70
grade = B
marks 70-60
grade =C
marks 60- 50
grade = D
marks 50-40
grade = E
marks<=40
grade = F
Mar 30 '07 #1
1 1286
sathishbk
1 New Member
CREATE TABLE STUDENT
(
roll_no number(4) PRIMARY KEY,
name varchar2(50) NOT NULL,
marks number(3),
grade char(1),
course_id number(4)
)
/


CREATE TRIGGER TR_GRADE
BEFORE UPDATE OR INSERT ON STUDENT
FOR EACH ROW
BEGIN
IF :NEW.MARKS>80 THEN
:NEW.GRADE:='A';
ELSIF :NEW.MARKS>70 AND :NEW.MARKS<80 THEN
:NEW.GRADE:='B';
ELSIF :NEW.MARKS>60 AND :NEW.MARKS<70 THEN
:NEW.GRADE:='C';
ELSIF :NEW.MARKS>50 AND :NEW.MARKS<60 THEN
:NEW.GRADE:='D';
ELSIF :NEW.MARKS>40 AND :NEW.MARKS<50 THEN
:NEW.GRADE:='E';
ELSIF :NEW.MARKS<=40 THEN
:NEW.GRADE:='F';
END IF;
END TR_GRADE;
/

insert into student VALUES (1,'SATHISH',3,NULL,123);
SELECT * FROM STUDENT;
ROLL_NO NAME MARKS G COURSE_ID
---------- -------------------------------------------------- ---------- - ----------
1 SATHISH 3 F 123
Mar 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4561
by: Darren | last post by:
Hello, I have some 'CREATE TRIGGER' definitions that work when cut/pasted into SQL*Plus worksheet and execute separately but fail with a 'trigger created with compilation errors' when executed...
1
2551
by: Ling Xiaoyu | last post by:
Hello there. Can anybody help me with Postgresql triggers? what I need is a trigger which update value of field "tables_rows.total_rows" to rows count of table "zzz" if I insert new row in table...
1
4433
by: Barbara Lindsey | last post by:
I am a postgres newbie. I am trying to create a trigger that will put a copy of a record into a backup table before update or delete. As I understand it, in order to do this I must have a...
0
2019
by: Yogesh | last post by:
Hello Everyone I have to create Oracle tables in my application on the fly, which have an Autonumber field. So, everytime I create a table, I have to create a corresponding sequence and trigger...
182
7353
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
11
36993
by: serge | last post by:
When i debug a trigger is it possible to add a WATCH on the INSERTED or DELETED? I think not, at least I couldn't figure out a way to do so. Does someone have a suggestion on how I can see the...
37
3243
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
4
1826
by: LyzH | last post by:
Someone else had a question on how to emulate a mouse click. I tried posting in that thread but I have something of a twist on this problem and I'm really in trouble here! If I don't get help...
2
1522
by: jb | last post by:
Hi! I whould like to lanunch an async postback trigger from an updated panel when a user presses the key return with the cursor in a textbox, is that possible? Thanks, Xus
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.