Questions tagged [triggers]

Triggers are rules that perform actions or invoke functions in response to events such as matching conditions or database changes. Use with an applicable database, platform, product, or service tag where possible. Always use with corresponding language tag.

About

Triggers are rules that perform one or more actions upon matching a condition. They can be defined at various levels of applications and processes (such as database triggers to change data, UI triggers to change properties or fire events, and function triggers to invoke functions).


Database Triggers

A Database Trigger, in general, are stored procedures that are automatically invoked upon events occurring in a database.

Use with

Useful Resources

  1. MySQL
  2. HSQLDB
  3. SQLite
  4. PostgreSQL
  5. Firebird

WPF triggers

Windows Presentation Framework (WPF) Trigger - the properties changed by triggers are automatically reset to their previous value when the condition is no longer satisfied.

Use with and or where applicable


DML Triggers

Data Manipulation Language (DML) triggers are stored procedures that fire upon DML events like INSERT, DELETE, or UPDATE occurring on the table or view.

DML Triggers can work on different levels:

  • Row Level (executed for each row affected)
  • Statement Level (executed once no matter how many rows are affected)

The trigger is mostly used for maintaining the integrity of the information on the database.

Usage Guidance

Use with relevant database tag:

Useful Resources

  1. SQL Server and Azure SQL DML triggers
  2. PostgreSQL event triggers
  3. Row and Statement triggers for Oracle DB

System Triggers

System triggers execute in response to certain actions occurring in the database such as user logging on or off (LOGON & LOGOFF), startup or shutdown (STARTUP & SHUTDOWN), server error (SERVERERROR) events, or data definition language (DDL) statements are run.

Useful Resources

  1. Creating triggers Oracle guide
  2. Using triggers Oracle guide

Function Triggers

Azure function triggers

Triggers define how and when Azure Functions run, provide input data to them or connect other resources via input/output bindings. Triggers and bindings for them are defined in function.json file.

Usage Guidance

Always use with . Use with and appropriate language tag (where applicable).

Useful Resources

  1. Triggers and bindings in Azure guide
  2. HTTP triggers and bindings reference

Google Apps Script triggers

Triggers in Google Apps Script automatically run a function on a certain event firing. There are 2 types of them:

Simple triggers that respond to events such as onOpen or onChange in container-bound scripts.

Installable triggers can call services that have to be authorized by the user, can be scheduled (in case of time-driven triggers), and programmatically managed.

Usage guidance

Use for questions about Google Apps Script triggers both simple and installable.

Always use together with tag.

For G Suite application triggers use with product-specific tags:

For Web Apps doGet/doPost triggers use with tag.

For onInstall triggers use with tag.

Useful Resources

  1. Simple triggers guide
  2. Installable triggers guide
  3. Trigger samples repo on GitHub
  4. Event object structures reference

Google Cloud Triggers

Cloud triggers run either Cloud Functions in response to an HTTP request or Background Functions on an event from Cloud Storage, Cloud Firestore, or Pub/Sub message.

Usage guidance

Always use with and with appropriate language tag where applicable. When asking about Background functions use an appropriate trigger tag:

for Cloud Pub/Sub
for Cloud Storage
for cloud Firestore

Useful Resources

  1. Cloud Functions reference
  2. Writing a Background Function guide
  3. Public issue tracker
19684 questions
673
votes
19 answers

How to trigger event in JavaScript?

I have attached an event to a text box using addEventListener. It works fine. My problem arose when I wanted to trigger the event programmatically from another function. How can I do it?
KoolKabin
  • 17,157
  • 35
  • 107
  • 145
397
votes
11 answers

val() doesn't trigger change() in jQuery

I'm trying to trigger the change event on a text box when I change its value with a button, but it doesn't work. Check this fiddle. If you type something in the text boxes and click somewhere else, change is triggered. However, if you click the…
Ergec
  • 11,608
  • 7
  • 52
  • 62
306
votes
12 answers

How to trigger a click on a link using jQuery

I have a link: and I am trying to trigger it by using: $(document).ready(function() { $('#titleee').find('a').trigger('click'); }); But it…
Patrioticcow
  • 26,422
  • 75
  • 217
  • 337
281
votes
10 answers

Definitive way to trigger keypress events with jQuery

I've read all the answers on to this questions and none of the solutions seem to work. Also, I am getting the vibe that triggering keypress with special characters does not work at all. Can someone verify who has done this?
mkoryak
  • 57,086
  • 61
  • 201
  • 257
276
votes
20 answers

Need to list all triggers in SQL Server database with table name and table's schema

I need to list all triggers in SQL Server database with table name and table's schema. I'm almost there with this: SELECT trigger_name = name, trigger_owner = USER_NAME(uid),table_schema = , table_name = OBJECT_NAME(parent_obj), isupdate =…
Ronnie Overby
  • 45,287
  • 73
  • 267
  • 346
224
votes
16 answers

jQuery - Trigger event when an element is removed from the DOM

I'm trying to figure out how to execute some js code when an element is removed from the page: jQuery('#some-element').remove(); // remove some element from the page /* need to figure out how to independently detect the above happened */ is there…
sa125
  • 28,121
  • 38
  • 111
  • 153
212
votes
7 answers

How do I temporarily disable triggers in PostgreSQL?

I'm bulk loading data and can re-calculate all trigger modifications much more cheaply after the fact than on a row-by-row basis. How can I temporarily disable all triggers in PostgreSQL?
David Schmitt
  • 58,259
  • 26
  • 121
  • 165
210
votes
20 answers

Are database triggers necessary?

In my experience, they are not a good idea because they can result in surprising side effects, and are difficult to debug (especially when one trigger fires another). Often developers do not even think of looking if there is a trigger. On the other…
WW.
  • 23,793
  • 13
  • 94
  • 121
200
votes
23 answers

Insert Update trigger how to determine if insert or update

I need to write an Insert, Update Trigger on table A which will delete all rows from table B whose one column (say Desc) has values like the value inserted/updated in the table A's column (say Col1). How would I go around writing it so that I can…
MSIL
  • 2,671
  • 5
  • 24
  • 25
194
votes
7 answers

Throw an error preventing a table update in a MySQL trigger

If I have a trigger before the update on a table, how can I throw an error that prevents the update on that table?
Matt MacLean
  • 19,410
  • 7
  • 50
  • 53
189
votes
14 answers

How to find a text inside SQL Server procedures / triggers?

I have a linkedserver that will change. Some procedures call the linked server like this: [10.10.100.50].dbo.SPROCEDURE_EXAMPLE. We have triggers also doing this kind of work. We need to find all places that uses [10.10.100.50] to change it. In SQL…
Victor Rodrigues
  • 11,353
  • 23
  • 75
  • 107
167
votes
13 answers

How to debug Google Apps Script (aka where does Logger.log log to?)

In Google Sheets, you can add some scripting functionality. I'm adding something for the onEdit event, but I can't tell if it's working. As far as I can tell, you can't debug a live event from Google Sheets, so you have to do it from the debugger,…
d0c_s4vage
  • 3,947
  • 6
  • 23
  • 32
162
votes
11 answers

How to get JQuery.trigger('click'); to initiate a mouse click

I'm having a hard time understand how to simulate a mouse click using JQuery. Can someone please inform me as to what i'm doing wrong. HTML: Don't click me! Click…
lickmycode
  • 2,069
  • 2
  • 19
  • 20
147
votes
11 answers

Disable Enable Trigger SQL server for a table

I want to create one proc like below but it has error on syntax. Could anyone pointing out the problem? Create PROCEDURE [dbo].[my_proc] AS BEGIN DISABLE TRIGGER dbo.tr_name ON dbo.table_name -- some update statement ENABLE TRIGGER dbo.tr_name …
pang
  • 3,964
  • 8
  • 36
  • 42