Professional Documents
Culture Documents
triggers (1)
triggers (1)
1)To write a trigger to ensure that department table does not contain duplicate of null values in deptno column.
Trigger created.
Table created.
Trigger created.
3) Write a set of triggers to illustrate cascading of trigger
SQL> create table sports(
2 sportcode varchar(30));
Table created.
1 row created.
SQL> CREATE OR REPLACE TRIGGER Sportcode_Upd_Cas
2 BEFORE UPDATE OF Sportcode ON sports
3 FOR EACH ROW
4 BEGIN
5 UPDATE sports
6 SET Sportcode =:new.Sportcode
7 WHERE Sportcode =:old.Sportcode;
8 DBMS_OUTPUT.PUT_LINE(‘Corresponding Sportcode in the Sports table has also been
9 updated’);
10 END;
11 /
Trigger created.
4)Write a database trigger BEFORE DELETE FOR EACH ROW now allowing
deletions and give appropriate message on the instructor a table
Trigger created.
5).Write a database trigger AFTER DELETE FOR EACH ROW now allowing
deletions and give appropriate message on the instructor a table
Trigger created.
6)Write a database trigger BEFORE INSERT/UPDATE/DELETE FOR EACH ROW
now allowing any of these operations on the student table during the month of
August/September
Table created.
1 row created.
1 row created.
1 row created.
Trigger created.
7)Create a row level trigger for the customers table that would fire for INSERT or UPDATE or DELETE operations
performed on the CUSTOMERS table. This trigger will display the salary difference between the old values and new
values:
Table created.
1 row created.
SQL> insert into customers values(2,'bob',27,'kadappa',3000);
1 row created.
1 row created.
SQL> insert into customers values(4,'dena',28,'hyderabad',5000);
1 row created.
1 row created.
Trigger created.
8) Convert employee name into uppercase whenever an employee record is inserted or updated. Trigger to fire before
the insert or update.
Table created.
SQL> CREATE OR REPLACE TRIGGER employee_insert_update
2 BEFORE INSERT OR UPDATE ON employee1
3 FOR EACH ROW
4 DECLARE
5 modified_first_name VARCHAR2(100);
6 BEGIN
7 modified_first_name := UPPER(:new.first_name);
8 :new.first_name := modified_first_name;
9 END;
10 /
Trigger created.