---
title: "How to create Triggers in SQL"
description: "The triggers in DB2 is really a complex task for many SQL developers. The example SQL helps you to start your journey."
url: https://srinimf.com/2011/01/02/db2-triggers/
date: 2011-01-02
modified: 2026-10-10
author: "Srini"
categories: ["DB2"]
tags: ["DB2 Triggers"]
type: post
lang: en
---

# How to create Triggers in SQL

## **How to write Triggers? **

The following code shows the creation [in DB2](https://srinimf.com/2014/10/19/truncate-and-delete-in-db2/):

```
CREATE TRIGGER SALARY_UPDATE 
       BEFORE UPDATE OF SALARAY ON EMP_TABLE  
       FOR EACH ROW MODE DB2SQL  
WHEN (NEW.SALARY > (OLD.SALARY * 1.5))  
BEGIN AUTOMIC  
SIGNAL SQLSTATE '75001' ('RAISE EXCEEDS 50%');  
END
```

### SALARY_UPDATE:  Trigger Name

The trigger will fire before actual update. It applies to all update rows. Begin and End are the actual Trigger statements.

New value exceeds 50% of [old salary](https://srinimf.com/2025/02/13/databricks-time-travel-how-to-compare-with-previous-versions/). An error will raise. Triggers will be stored in [Trigger package](https://srinimf.com/2014/12/17/cobol-db2-trigger-package/). Trigger packages also stored in SYSPACKAGE.

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2011%2F01%2F02%2Fdb2-triggers%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2026%2F02%2Fcropped-logo.png%3Ffit%3D96%252C96%26ssl%3D1&description=How%20to%20create%20Triggers%20in%20SQL)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2011/01/02/db2-triggers/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2011/01/02/db2-triggers/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2011/01/02/db2-triggers/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2011/01/02/db2-triggers/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20create%20Triggers%20in%20SQL&body=https%3A%2F%2Fsrinimf.com%2F2011%2F01%2F02%2Fdb2-triggers%2F&share=email)
-

### Like this:

Like Loading…