Questions tagged [trigger]

Procedural code automatically executed in response to a database event.

A database trigger is procedural code that runs automatically in response to an event on occurring on the database. Triggers are commonly used for events on tables and views where they typically help maintain data integrity.

Table events that can fire triggers include:

  • Insert (Before, After) (Statement, Row)
  • Update (Before, After) (Statement, Row)
  • Delete (Before, After) (Statement, Row)

Some platforms include other events such as:

  • DDL Triggers (SQL Server, Oracle - Can be schema specific)
  • DB Level Triggers (Firebird, Oracle)
  • Compound Triggers (Oracle)
  • Instead Of Triggers (Oracle)
  • System Triggers such as Startup, Shutdown, and Server Error (Oracle)
  • Allowances for CREATE TABLE within Standard Events (PostgreSQL)
1510 questions
2
votes
3 answers

How to trigger an action without using triggers

I just want to ask. We have a calendar table, let's call it CAL1 in one database, lets call it DB1. CAL1 is manually populated. Now in another database, DB2, there is another calendar table CAL2. What I need to do is to populate CAL2 based on the…
Arwen
  • 21
  • 1
2
votes
1 answer

What is a practical use of FOR STATEMENT triggers?

I understand very well the idea behind triggers, how and when to use them. I also see the practical use of a FOR EACH ROW trigger. But I lack to find a concrete example of when I would use a FOR STATEMENT trigger. What could I do with it? Can anyone…
SteeveDroz
  • 123
  • 1
  • 5
2
votes
3 answers

Enforce functional dependencies by using triggers in SQL99

The question is as below: For R(A, B, C, D, E), write a trigger to enforce AB->C on insert. This is my solution: CREATE TRIGGER fdEnforceInsert BEFORE INSERT ON R REFERENCING NEW ROW AS N FOR EACH ROW DECLARE counter INT BEGIN SELECT COUNT(*)…
1
vote
2 answers

Triggers After Insert and After Update - Good Practice

It is a good practice to have a separate trigger for After Insert and another one for After Update or there is no problem in having both in the same logic? Also from a perspective of performance it will be better to have them isolated?
1
vote
0 answers

How do you add data to a table dynamically from a trigger in T-SQL

I have a Uni assignment due, part of it requires this: "Create a database trigger called “TRG_PREVENT_VIEW_DROP” that will prevent the dropping of any view The trigger must log the action in a separate table called event logs and include the…
Matt
  • 11
  • 2
0
votes
1 answer

MySQL trigger doesn't response, WHY?

I am new to SQL and I don't know where to get help. I faced a problem while using the trigger, but it doesn't response. This is my code here: DELIMITER $$ CREATE TRIGGER payments_after_insert …