Database triggers

December 4, 2026 · Team EasyExamNotes · 3 min read (est.) · 0 comments

Share on WhatsApp

← RGPV CS-502 DBMS December 2024 solved question paper

← RGPV CS-502 DBMS November 2022 solved question paper

← RGPV CS-502-CBGS DBMS June 2020 solved question paper

← RGPV CS-502 DBMS November 2019 solved question paper

RGPV Previous Year Examination Question

B.Tech. V Semester | CS-502 (GS) | December 2024 | 7(b)(ii)

Question (restated): Briefly describe database triggers.

Answer

Definition

A database trigger is a stored action executed automatically when a specified event occurs. Triggers follow an event-condition-action model: an event such as INSERT, UPDATE or DELETE activates the trigger, an optional condition is checked, and the action is executed.

Types

BEFORE triggers run before the triggering operation; AFTER triggers run afterward. Row-level triggers execute for each affected row, whereas statement-level triggers execute once per statement where supported. INSTEAD OF triggers can implement operations on certain views.

Oracle example

CREATE OR REPLACE TRIGGER check_marks
BEFORE INSERT OR UPDATE ON Student
FOR EACH ROW
BEGIN
  IF :NEW.Marks < 0 OR :NEW.Marks > 100 THEN
    RAISE_APPLICATION_ERROR(-20001, 'Invalid marks');
  END IF;
END;
/

For an attempted insert with Marks=120, the trigger raises an error and the operation fails. For Marks=85, this check permits the operation. :NEW refers to the new row value; :OLD refers to the previous value where applicable. A CHECK constraint is preferable for this simple validation, but the example illustrates trigger syntax.

Triggers are useful for auditing, enforcing complex rules and maintaining derived data. Excessive triggers can make behavior difficult to trace and introduce performance overhead. Their syntax and supported events vary by DBMS.

Further reading

Silberschatz, Korth and Sudarshan, Database System Concepts; Elmasri and Navathe, Fundamentals of Database Systems.


RGPV CS-502 (GS) | November 2022 | Q8(d) | 7 marks

Question (restated): Write a short note on database triggers.

Answer

A trigger is a stored database action executed automatically in response to a specified event. DML triggers respond to INSERT, UPDATE or DELETE; other trigger types depend on the platform. BEFORE triggers can validate or modify values, while AFTER triggers can record completed changes. Row-level triggers execute for each affected row, whereas statement-level triggers execute once per statement.

Oracle example: salary audit

CREATE TABLE SalaryAudit (
  E_ID NUMBER, OldSalary NUMBER, NewSalary NUMBER,
  ChangedAt TIMESTAMP);
CREATE OR REPLACE TRIGGER trg_salary_audit
AFTER UPDATE OF Salary ON Employee
FOR EACH ROW
BEGIN
  INSERT INTO SalaryAudit VALUES
  (:OLD.E_ID,:OLD.Salary,:NEW.Salary,SYSTIMESTAMP);
END;
/

When salary changes from 5000 to 5500, the trigger inserts an audit row containing the employee ID, old and new salaries and timestamp. The audit insert participates in the same transaction unless deliberately designed otherwise. If the update rolls back, the audit insert normally rolls back too.

Triggers are useful for auditing, enforcing complex rules and maintaining derived information. They can introduce hidden side effects, performance overhead and recursive behavior. Simple integrity rules should normally use declarative constraints rather than triggers. Trigger syntax and available events vary across database platforms.

Further reading: Silberschatz, Korth and Sudarshan, Database System Concepts.


June 2020 – Q8(b)(iii)

Question: Triggers in SQL

A trigger is a stored database action automatically executed when a specified event occurs, such as INSERT, UPDATE or DELETE. Triggers may execute before or after an event, and at row or statement level depending on the DBMS. They are used for auditing, validation and derived updates. In Oracle, :OLD and :NEW refer to old and new row values in row-level triggers. Triggers should be designed carefully to avoid hidden side effects and excessive overhead.

CREATE OR REPLACE TRIGGER check_marks
BEFORE INSERT OR UPDATE ON Student
FOR EACH ROW
BEGIN
  IF :NEW.Marks < 0 OR :NEW.Marks > 100 THEN
    RAISE_APPLICATION_ERROR(-20001, 'Invalid marks');
  END IF;
END;
/

← RGPV CS-502 DBMS December 2024 solved question paper

← RGPV CS-502 DBMS November 2022 solved question paper

← RGPV CS-502-CBGS DBMS June 2020 solved question paper

← RGPV CS-502 DBMS November 2019 solved question paper

Discussion

Ask a question, share your thoughts or report an error.

Sign in to participate in the discussion.

Join the discussion