Search for question
Question

2. PLSQL & Triggers

A database was created with the following sql:

CREATE TABLE student (

SID integer primary key,

sLastName varchar(20),

sFirstName varchar(20),

SAddress varchar(20),

wage number(7,2));

INSERT INTO student VALUES (1, 'Baker', 'Jane', 'Chicago, IL', 0.

INSERT INTO student VALUES (2, 'Julia', 'Mike', 'Chicago IL', 0.0

INSERT INTO student VALUES (3, 'Wu', 'Mark', 'Chicago IL', 10.

CREATE TABLE student_log (operation Date Date,

userName varchar(20),

action varchar(20));

a. Write a trigger that will run the following query AFTER a user attempts to update th student table:

INSERT INTO student_log (operation Date, userName, action)

VALUES (Sysdate, User, 'Table Update');

b. With your trigger in question (2.a), if a user run the following update sql, the

row will be inserted into student_log table:

UPDATE student SET wage=15.0 WHERE SID<3;

Select the right answer:

A. 0 row

B. 1 rows

C. 2 rows

D. 3 row

c. With your trigger in question (2.a), if a user run the following delete row will be inserted into student_log table:

DELETE FROM student WHERE SID <4;

Select the right answer:

A. 0 row

B. 1 rows

C. 2 rows

D. d. 3 row

d. Given the following PLSQL code:

CREATE OR REPLACE PROCEDURE AddStudent

(sID IN Number, SFN IN varchar(20), SLN IN varchar(20), SAD IN varchar(20))

AS

BEGIN

INSERT INTO student VALUES(SID, SFN, SLN, SAD);

INSERT INTO student_log VALUES(SYSDATE, User, "Table Insert");

END;

BEGIN

AddStudent(4, 'Carrey', 'John', 'Chicago, IL', 15.0);

END;

What happens if a user runs above PLSQL code, select the right answer:

A.

Add a new row to student table

B.

Add a new row to student_log table

C.

Code doesn't work.

D.

Add a new row to student and student_log