Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a.After insert in any table, count the number of rows and display the results as follows: “After successful insertion, number of rows of this table is now 23”, where number 23 represent the number of rows in the table.
- TABLE: Committee, Audience, Band, Schedule, Registration, Stage, Interview, Magazine.
- ASSIGNED TO: Fa’iq Raihan
- -----------------------------------------------------------------------------------------------------------
- CREATE TRIGGER trg_CountRow_afterUpdate
- AFTER INSERT ON [Table] FOR EACH ROW
- DECLARE
- numofrow INT(10);
- BEGIN
- Select count(*) FROM [Table] INTO numofrow
- FROM [Table];
- dbms_output.put_line(‘After successful insertion, number of rows of this table is now ‘ || numofrow);
- END;
- b. Create a trigger that will implement a referential integrity on a primary key table and the foreign key table in a way that if a value of PK is deleted it will nullify the value in the foreign key table as well.
- TABLE:
- ASSIGNED TO: Fa’iq Raihan
- -----------------------------------------------------------------------------------------------------------
- CREATE TRIGGER trg_IntegrityCheck_onDelete
- AFTER DELETE ON [PrimaryTable] FOR EACH ROW
- BEGIN
- DELETE FROM [ForeignTable]
- WHERE ForeignTable.pid = PrimaryTable.id;
- END;
- c. Create another trigger that would update the records of the PK table to the FK table as well. A proper response should be generated once the update is successful.
- TABLE:
- ASSIGNED TO: Fa’iq Raihan
- ---------------------------------------------------------------------------------------------------------------------
- CREATE TRIGGER trg_ReferentialUpdate_afterUpdate
- AFTER UPDATE ON [PrimaryTable] FOR EACH ROW
- BEGIN
- UPDATE [ForeignTable]
- SET variable1 = (select variable1 FROM PrimaryTable WHERE ForeignTable.pid = PrimaryTable.id);
- UPDATE [ForeignTable]
- SET variable2 = (select variable2 FROM PrimaryTable WHERE ForeignTable.pid = PrimaryTable.id);
- UPDATE [ForeignTable]
- SET variable3 = (select variable3 FROM PrimaryTable WHERE ForeignTable.pid = PrimaryTable.id);
- ...........
- dbms_output.put_line(‘Data from table [ForeignTable] have been updated following changes in table [PrimaryTable]);
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement