Questions tagged [database-trigger]

A database trigger is procedural code written in the current database DML, that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database.

A database trigger is procedural code written in the current database , that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database.

1659 questions
5
votes
3 answers

Modifying a MySQL Trigger

I have a MySQL trigger that I would like to be modified. The only changes are in the trigger body. Will updating the ACTION_STATEMENT Column in INFORMATION_SCHEMA.TRIGGERS suffice? Is this the right way to update a trigger? Specifically, I am…
user514946
  • 1,165
  • 3
  • 12
  • 12
5
votes
1 answer

output clause VS triggers

On our database, most tables have a dbupddate field which indicates the datetime of the last INSERT or UPDATE applied at the row. In order to avoid this field having an erroneous value, there exist triggers (sometimes AFTER, sometimes INSTEAD OF)…
George Menoutis
  • 6,894
  • 3
  • 19
  • 43
5
votes
1 answer

Should foreign key constraint checking be disabled by DISABLE TRIGGER ALL?

I am copying data from one PostgreSQL v10 table to another. The destination table has several foreign key constraints. I was surprised that I did not get any errors, even though none of the tables referred to by the foreign key constraints had any…
ROBERT RICHARDSON
  • 2,077
  • 4
  • 24
  • 57
5
votes
2 answers

PostgreSQL: Checking for NEW and OLD in a function for a trigger

I want to create a trigger which counts rows and updates a field in an other table. My current solution works for INSERT statements but failes when I DELETE a row. My current function: CREATE OR REPLACE FUNCTION update_table_count() RETURNS trigger…
FredFloete
  • 627
  • 2
  • 13
  • 33
5
votes
1 answer

ERROR: column "semester_id" is of type integer but expression is of type boolean

I created this PL/pgSQL trigger function in PostgreSQL: CREATE or replace FUNCTION public.trigger31() RETURNS trigger LANGUAGE 'plpgsql' COST 100 VOLATILE NOT LEAKPROOF AS $BODY$ begin …
5
votes
3 answers

Does an insert trigger need a commit statement

This is an simplification of actual scenario; where is see missing records on Table B. Say there are two db tables A ; B. There is an on insert trigger on Table A;which do an insert to Table B (but it doesn't have COMMIT;). If we open a db…
Don Srinath
  • 1,565
  • 1
  • 21
  • 32
5
votes
2 answers

ORACLE "before update" trigger does not fire when column is changed within another trigger

I am using ORACLE 12c. On a table I have 2 triggers, both "before update". One of the triggers fires while updating a column and within this trigger another column gets a new value. The second trigger should fire while updating this second column.…
virtualbee
  • 110
  • 7
5
votes
2 answers

How to pass arguments to an external (SQLCLR) SQL Server trigger

I have created a Trigger that calls an assembly like this: CREATE TRIGGER Testrigger ON STATION FOR INSERT AS EXTERNAL NAME assemblytest.[WriteTimeInfile.Program].Testrigger The .NET code in that assembly that does something like…
Pipo
  • 5,170
  • 7
  • 33
  • 66
5
votes
2 answers

MSSQL conditional check inside of "INSTEAD OF UPDATE " trigger

Working with MSSQL2008. I have two tables. TableResource ------------- ID [bigint] Attribute1 [int] Attribute2 [int] Attribute3 [int] VersionId [uniqueidentifier] and TableResourceHistory -------------------- ID [bigint] Attribute3History…
Simon Ordo
  • 1,517
  • 2
  • 14
  • 23
5
votes
2 answers

Check if trigger exists

I have the following query to triggers on all tables in schema public: SELECT 'CREATE TRIGGER ' || tab_name|| '_if_modified_trg INSERT OR UPDATE OR DELETE ON ' || tab_name|| ' FOR EACH ROW EXECUTE PROCEDURE audit.if_modified_func(); ' AS…
Avon Dones
  • 51
  • 1
  • 3
5
votes
1 answer

Change inserted value with trigger

I've just started to learn SQL a few weeks ago and I'm trying to make a trigger which changes the inserted value into 10 if it's smaller than 10. I searched for 4h now and I've found a lot of answers but none was good(for me). I really don't…
hepifish
  • 734
  • 1
  • 9
  • 15
5
votes
2 answers

Compute blob hash in trigger on blob's table

My environment is Oracle 11g. I have a table T_IMG whose columns are an image blob, an image identifier, and the image's hash computed as SHA256. I want the image hash to be computed and inserted into the T_IMG table every time a row is inserted or…
adim
  • 71
  • 1
  • 5
4
votes
2 answers

SQL Server : DDL trigger, controlling table creation

I'm using SQL Server 2008. I'm creating a DDL trigger like this: CREATE TRIGGER tName ON database FOR CREATE_TABLE as print 'A table has been created' Can I get that table that has been created !? Something like inserted or deleted in the…
AMTourky
  • 1,190
  • 13
  • 25
4
votes
4 answers

Oracle PL/SQL: Loop Over Trigger Columns Dynamically

Inside of a trigger I'm trying to loop over all columns on a table and compare the new values to the old values. Here is what I have so far: CREATE OR REPLACE TRIGGER "JOSH".TEST#UPD BEFORE UPDATE ON "JOSH"."TEST_TRIGGER_TABLE" REFERENCING OLD AS…
Josh Bush
  • 2,708
  • 4
  • 24
  • 25
4
votes
1 answer

How do I find the audsid, sql_id of the sql statement which has invoked a trigger, within that trigger

Some records are getting removed from a table and we want to identify sql statements which are removing records from a table, so that we can check find the program which is causing the problem. I have written the following but the sql create or…
Sam
  • 41
  • 2