Can I do a select in a trigger?

Can I do a select in a trigger?

The trigger event that initiates the trigger action can be an INSERT, DELETE, UPDATE, or a SELECT statement. The MERGE statement can also be the triggering event for an UPDATE, DELETE, or INSERT trigger. The event definition must specify the table or view on which the trigger is defined.

How do I select a trigger in PostgreSQL?

Columns

  1. table_schema – name of the table schema.
  2. table_name – name of the trigger table.
  3. trigger_schema – name of the trigger schema.
  4. trigger_name – name of the trigger.
  5. event – specific SQL operation: Insert, Update or Delete.
  6. activation – trigger activation time: After, Instead of or BEFORE.

Can a trigger be written for SELECT query?

Nope – you can’t trigger on SELECT – you’ll have to create a stored procedure (or any other type of logging facility – like a log file or what ever) that you implicitly call on any query statement – easier if you create a wrapper that calls your query, calls the logging and returns query results.

How to create trigger that runs on two tables?

CREATE OR REPLACE TRIGGER checkDuration BEFORE INSERT OR UPDATE ON (course c JOIN offering o ON c.courseId = o.courseId) FOR EACH ROW BEGIN IF ( (to_char (:new.startDate, ‘fmMONTH’) = ‘DECEMBER’) AND duration = 5) THEN raise_application_error (-20001, ‘Courses of five days duration cannot be run in December’); END IF; END;

How to create multiple trigger statements in PostgreSQL?

However, if all your triggers use the same procedure, you can easily generate a nice text output with all the CREATE TRIGGER statements. The only thing to do is to collect the desired table names and then prepend and appent the necessary parts to those. instead of p.tablename then you are ready. Copy the output and run it.

How to create a trigger in Oracle SQL?

Whether it’s a trigger,a statement in a standard procedure, or just a standalone query to employ a JOIN it must follow the form Select [into …] from table1 JOIN table2 on join_condition Where a trigger and procedural statement requires the INTO phrase.