Friday, August 14, 2026
Home Academic Trigger in SQL

Trigger in SQL

An automatic execution of a defined block of SQL code known as a trigger occurs in reaction to specific events, such as the addition, modification, or deletion of a record in a table. Among other things, triggers are employed to uphold data integrity or to enforce business standards.

The SQL syntax for building a trigger is as follows:

CREATE TRIGGER trigger_name
AFTER/BEFORE INSERT/UPDATE/DELETE
ON table_name
FOR EACH ROW
BEGIN
-- trigger code goes here
END;

For instance, you could use the following sentence to build a trigger called “update_salary_history” that updates the “salary_history” table anytime an employee’s salary is updated in the “employees” table:

CREATE TRIGGER update_salary_history
AFTER UPDATE OF salary
ON employees
FOR EACH ROW
BEGIN
INSERT INTO salary_history (employee_id, salary, update_date)
VALUES (OLD.employee_id, OLD.salary, CURRENT_TIMESTAMP);
END;

To drop a trigger, you can use the following statement:

DROP TRIGGER trigger_name;

Triggers can be helpful for automating specific processes or maintaining data integrity, but they can also be difficult to build and manage, so they should only be used in limited circumstances. In general, it is a good practice to utilize triggers sparingly and to substitute other methods, including foreign keys and stored procedures, whenever possible.

datasagarhttp://www.DataSagar.com
Sagar is multidisciplinary technologist, educator, and entrepreneur based in Nepal. As the founder of Illionso Technologies and Kashi Garden Resort, he operates at the intersection of web architecture, data intelligence, innovation, and digital transformation. From building digital solutions to scaling real-world concepts, his mission is to share knowledge alongside merge emerging as well as disruptive technologies with transformative offline experiences.
RELATED ARTICLES

Why Linux Won the Infrastructure War? Lessons from Linus Torvalds

In 1991, 21-year-old Linus Torvalds announced a "hobby" operating system. Today, Linux powers supercomputers, cloud servers, and Android. Explore his journey, the open-source economy, and the lessons for modern developers.

What Is Vibe Coding? A Complete Beginner’s Guide to Building Software and Web Pages With AI

A few years ago, building a website meant sitting down with a programming book, picking a language, and slowly working through syntax...

What is Answer Engine Optimization (AEO)? Getting Ready for AI Powered Search and Agentic Era Digital Marketing

Search is changing faster than it has in the last two decades. For years, businesses focused on ranking their websites on search...

Most Popular

Why Linux Won the Infrastructure War? Lessons from Linus Torvalds

In 1991, 21-year-old Linus Torvalds announced a "hobby" operating system. Today, Linux powers supercomputers, cloud servers, and Android. Explore his journey, the open-source economy, and the lessons for modern developers.

What Is Vibe Coding? A Complete Beginner’s Guide to Building Software and Web Pages With AI

A few years ago, building a website meant sitting down with a programming book, picking a language, and slowly working through syntax...

What is Answer Engine Optimization (AEO)? Getting Ready for AI Powered Search and Agentic Era Digital Marketing

Search is changing faster than it has in the last two decades. For years, businesses focused on ranking their websites on search...

The Plain Text Web: Why llms.txt Is Becoming the New Site Standard

The web built today is heavy. Between client-side JavaScript, cookie banners, tracker scripts, and responsive CSS grids, a typical webpage carries megabytes...