How do I write a query to update my rows ‘S’. I would like to update the current Primary key to change the number of it. I am not sure if I need a sub-query.
Would updating score, use the same method to update “S”?
“S” indicates student number, “C” indicates course number.
My tried but failed query is
update grades set s = 114 where s = 100;
The ‘set s’ is what I want to update into and the ‘where s’ is looking for the row with that set ‘s’ number. Right?
Here is my query, trigger, and select * from grades looks like.
create table grades (
S varchar2(12),
C varchar2(10),
Score number(3,0),
Letter_Grade char(1),
Constraint pk_grades primary key (S),
Constraint CK_grades check (score between 0 and 100)
constraint lg_grades check (letter_grade in ('A','B','C','D','F'))
);
SET SERVEROUTPUT ON
CREATE OR REPLACE TRIGGER MARK_BU
BEFORE UPDATE OF score ON grades
FOR EACH ROW
DECLARE
BEGIN
:NEW.letter_grade :=
CASE
WHEN :NEW.score >= 80 THEN 'A'
WHEN :NEW.score >= 70 THEN 'B'
WHEN :NEW.score >= 60 THEN 'C'
WHEN :NEW.score >= 50 THEN 'D'
ELSE 'F'
END ;
DBMS_OUTPUT.PUT_LINE ('Numeric_grade was updated to: ' || :NEW.score);
DBMS_OUTPUT.PUT_LINE ('Letter_grade was calculated to be:' || :NEW.letter_grade);
END;
S C SCORE L
------------ ---------- ---------- -
100 CST8255 49 F
101 CST8255 59 D
102 CST8255 69 C
103 CST8255 79 B
104 CST8255 89 A
Is correct it will work.