Questions tagged [trigger]

Procedural code automatically executed in response to a database event.

Filter by
Sorted by
Tagged with
0 votes
0 answers
27 views

Postgresql alternative for trigger in multiple-row insert

I have a table where the values of different variables are stored. Basically, it is a table of the form data_table (timestamp, variable, value). One of the variables represents a state value. Certain ...
  • 103
-2 votes
0 answers
15 views

Only last EntryDate required [closed]

= OleDb.DataSource("provider=SQLOLEDB.1;initial catalog=SysproCompanyR;data source=10.10.35.15", [Query="with PalletQty as (#(lf)#(lf)SELECT distinct#(lf)#(tab)dbo.InvMovements.Bin as '...
2 votes
1 answer
67 views

script SQL equivalent

I have this SQLite script: CREATE TRIGGER ACCOUNT_UPDATE_DELETE_SESSION_ID_NULL AFTER UPDATE OF DELETE_SESSION_ID ON ACCOUNT FOR EACH ROW WHEN OLD.DELETE_SESSION_ID IS NOT NULL AND NEW....
-1 votes
0 answers
36 views

SELECT failed because the following SET options have incorrect settings: 'CONCAT_NULL_YIELDS_NULL, ANSI_WARNINGS, ANSI_PADDING' [duplicate]

I created a logon trigger to block specific IPs from a list on the master database. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TRIGGER trgBlockIP ON ALL SERVER FOR LOGON AS BEGIN ...
0 votes
0 answers
57 views

How to get around 'Can't update table in stored function/trigger because it is already used by statement which invoked'

In MariaDB/MySQL I am looking to create a trigger that automatically changes a boolean to true when 4 Users are a part of it. The issue is I am running a running a query on the table that is being ...
2 votes
3 answers
54 views

MySQL: How to make Trigger to insert row in another table?

Please read everything, included the notes and edits at the end Problem I have a MySQL DB with 3 different table: To save users mysql> describe users; +-------------+-----------------------------...
1 vote
0 answers
26 views

update trigger after insert on same table

So, I'm supposed to make a trigger that applies md5 to a row after an INSERT was made on it. Here is what I came up with: delimiter $$\ create trigger pd_encrip before insert on usuario\ for each row\ ...
0 votes
0 answers
23 views

PostgreSQL trigger for statement explanation

PostgreSQL 14 I try to understand the behaviour of trigger for each statement. Here is an example : AFTER INSERT OR DELETE OR UPDATE ON mytbl FOR EACH STATEMENT EXECUTE FUNCTION ...
  • 197
0 votes
0 answers
19 views

Fastest Mechanism: Monitor new record being added to MySQL DB, and push info via WebSocket/SSE?

I have a MySQL DB on MaridDB. There's a table that gets new records inserted at inconsistent intervals. sometimes every seconds, sometimes every few minutes. I have a web page and instead of having ...
0 votes
0 answers
15 views

Write trigger function to update only one row

I have 2 tables: table_1 and table_2 CREATE TABLE IF NOT EXISTS public.table_1 ( id integer NOT NULL DEFAULT nextval('table_1_id_seq'::regclass), dt time without time zone, value numeric, ...
1 vote
1 answer
64 views

how to prevent out of shared memory error when refreshing materialized views

Postgresql14, Windows server 2012 I get an out of shared memory related to a insufficient max_locks_per_transaction. I have two tables: tbl1 has insert/update every night. These actions trigger a ...
  • 197
-2 votes
1 answer
38 views

Trigger For Alter Role (SQL Server) [duplicate]

I want to create a trigger to catch ALTER ROLE/ADD MEMBER statements. Is there a way to do this, I couldn't find online.
1 vote
1 answer
44 views

How to run a trigger on existing rows

I have a process that inserts records into a table. The table is defined with a trigger like this ... CREATE TRIGGER myTrig AFTER INSERT ON myTable FOR EACH ROW EXECUTE PROCEDURE myProcedure(); The ...
0 votes
1 answer
20 views

Mysql Trigger - Update status_id if the value exist in other Table

Currently, I have two Tables: ocok_country status country_id 1 1 1 2 0 3 0 4 ** country_id 3 and 4 not updated with the trigger ** ocok_zone_to_geo_zone name country_id ABC 1 DEF 2 new-...
1 vote
2 answers
60 views

PL/pgSQL select statement inside trigger returns null using where NEW

I'm creating a trigger that triggers ON INSERT to a table, and I wish to log the structure of tables inserted so I wrote this function: CREATE OR REPLACE FUNCTION update_table_log_received() RETURNS ...
-1 votes
1 answer
19 views

Postgres trigger has no effect despite running [closed]

I have a trigger that updates a count in table rssfeeds whenever an insert occurs on table articles. Here is what the function looks like: UPDATE rssfeeds SET total_articles = total_articles + 1 ...
0 votes
0 answers
15 views

Enforce dynamic value correctly

I am working on quiz builder app with advanced features such as enforcing constraints on quizzes and/or quiz items. Here is the snippet of the ERD: violated_on represents the timestamp when this ...
  • 1
0 votes
2 answers
64 views

Postgresql: Trigger is not working at times

I have a PostgreSQL trigger that is not firing sometimes, even though the status is always shown as "enabled". My trigger code is as follows: CREATE OR REPLACE FUNCTION audit_src_exhibit() ...
  • 1
0 votes
1 answer
34 views

Postgresql: Trigger is not working at times

I have a PostgreSQL trigger that is not firing sometimes, even though the status is always shown as "enabled". My trigger code is as follows: CREATE OR REPLACE FUNCTION audit_src_exhibit() ...
  • 1
0 votes
0 answers
22 views

problem with writing a sql trigger

I'm writing a SQL trigger to whenever update the (engage_step_user_response) table (response_json) column after updated. I need to increase no of retakes that I included same table as a column. This ...
1 vote
1 answer
93 views

ORA-04091 table is mutating trigger/function may not see it when cascading, works otherwise

I have the following two tables: CREATE TABLE entries ( id NUMBER(20, 0) NOT NULL PRIMARY KEY, first_name VARCHAR2(512) DEFAULT NULL ...
0 votes
0 answers
26 views

Does enabling or disabling a trigger cause table statistics to go out of date (SQL Server)?

Whenever I modify a table (adding an index or adding or dropping a new column), I always run a sp_recompile on the table to make sure the statistics are updated. When a trigger is enabled or disable ...
1 vote
1 answer
65 views

help with mariadb after update trigger

I have a table that is shared among 7 other tables and I want to synchronize a new part is added to the parts table. new rows are created in each of the 7 other tables, using the part_id from the ...
0 votes
0 answers
84 views

PostgreSQL lower case or remove double quotes on every table name before select query

We are migrating from OracleDB to PostgreSQL and all the tables name in database are lower case while the script from application is mixed with double quotes. For example the code in application like ...
0 votes
1 answer
43 views

Extended Events for Enable Disable Trigger

We have a table that has a trigger defined on it Sometimes, some application runs disable trigger command, then does something, then runs enable trigger to enable it back Scanning the GIT, developers ...
1 vote
1 answer
107 views

Create postgres trigger that will populate additional table column on insert

Problem (Note: I have added potential solution to the bottom of the post) I don't know what's wrong with the approach that I currently have, but when I try to run it dbeaver just instantly quits. I ...
  • 226
-2 votes
1 answer
55 views

TRIGGER THAT UPDATES A COLUMN FROM INSERTED ROW (ORACLE)

Basically I need a trigger that updates a column of the inserted row, where it takes a value from another table by comparing the foreign key. Something like this: Thanks in advance.
0 votes
1 answer
48 views

Is it possible to write a generic trigger for all tables in Postgres?

I want to listen to every transaction that is recorded in the database And I noticed that there is a concept in Postgres under the title LISTEN and NOTIFY (Of course, I am not sure that this is the ...
0 votes
1 answer
23 views

How I can make a single trigger for both create and update at sqlite3?

I made the following table: CREATE table IF NOT EXISTS redirect ( id INTEGER PRIMARY KEY AUTOINCREMENT, url_from TEXT not null, url_to TEXT not null, ...
0 votes
2 answers
39 views

What I make wrong and Cannot inset a value at sqlite3 using custom trigger?

I am making the follwing table at SQLITE3: CREATE table IF NOT EXISTS redirect ( id INTEGER PRIMARY KEY AUTOINCREMENT, url_from TEXT not null, url_to TEXT not null, ...
0 votes
0 answers
23 views

trigger for consistency check - only one foreign key is allowed

I have a contacts table that contains a column named id. This id is the primary key of contacts. I also have two tables called persons and organizations that have a primary key called id, but they are ...
  • 11
1 vote
1 answer
51 views

update current row doesn't trigger attached function

To update a column in PostgreSQL using the function which is invoked by a trigger on each row add/update- Steps I followed: First, let's add the field "line_updated_dt_tm" to the table of ...
0 votes
1 answer
46 views

Recursive trigger into function

I have problems with recursive trigger: the table that fires the trigger and give a specific error for that; the trigger inserts a record, that fires the trigger, that fires on the table, that fires ...
3 votes
1 answer
535 views

check if value exist in another table before insert SQL

I have table: " daysoff " and table: " rdv " the rdv table looks like this : temps_rdv etat_rdv ID_RDV 12-10-2022 reservee 2 the daysoff table looks like this : ID DATE_OFF ...
  • 41
0 votes
0 answers
57 views

Update Trigger my SQL for other table value

I am new to SQL. I have a table Order_Detail with a column Quantity_Ordered. I have a table stock with columns Stock_Location. Using Stock location 20 Below code works when I increment stock out ...
6 votes
2 answers
282 views

Make two columns unique both ways

I'm creating a database which stores football matches. Each round, any given football club may only play once (home or away). For example, after the insert of INSERT INTO Match (Round, Home, Away) ...
  • 63
0 votes
0 answers
32 views

MySql Trigger Deadlock

I'm having issues with a trigger sometimes causing a deadlock. Only happens when the db is getting hit pretty hard but happens enough to be annoying. May it's just bad practice to use this trigger the ...
  • 161
0 votes
1 answer
68 views

Running a sequential trigger

I have my own triggers in my database. But my customer wants customizations. I need to give a trigger order according to the priorities he wants. I'm aware that I can do all of them with 1 trigger, ...
  • 91
0 votes
1 answer
36 views

If checking while deleting the record meets the requirements, I do want to delete it

I have a table. I have a field in my table that says "islocked" record is locked. This number of fields can be more than one. isApproved, isAccepted etc. There are various triggers (after ...
  • 91
0 votes
1 answer
59 views

getting the name of the function which caused trigger to activate in postgresql

Is there a way to get name of the function/procedure, which contains query, which caused a TRIGGER to activate? For example I have function update_user_whatever and it updates user data and I want to ...
0 votes
1 answer
443 views

After Insert Trigger not working in Sql Server

I have created the 2 After Insert Trigger on same Table. 1st Trigger executed successfully. But 2nd Trigger is not executing and giving the exception from c# code 'Database operation expected to ...
0 votes
0 answers
312 views

Foreign key cascade & triggers

I have a question on how to elaborate a schema in PostgreSQL which involves: A trigger function used to keep a certain consistency calculation in a table; A foreign key whose value in the original ...
  • 101
1 vote
0 answers
62 views

How do I test the estimated query plan of a portion of a trigger that uses inserted/deleted?

I'm performance tuning a SQL Server trigger that has several statements using the "inserted" and "deleted" tables. How can I break out those individual queries from the trigger ...
  • 301
0 votes
0 answers
57 views

How to prevent user to delete more than 2 rows at the same time

QGIS 3.22 & PostgreSQL 14. Many colleagues insert features in a Postgres/PostGIS database using QGIS and import/export to PostgreSQL database plugin. Among many parameters, there is add to or ...
  • 197
0 votes
1 answer
149 views

how to run trigger on table on postgresql except one column

I'm using postgresql 13/14. lets say I have a table with column A,B,C,D,E I have created a trigger for the table that would run every insert/update/delete. (but in this problem, I only need it for ...
  • 1
0 votes
0 answers
32 views

How should the procedure structure using Transaction be?

I want to make both error checks and insert and update in a single procedure. There are triggers in the tables that I insert and update in the procedure, and other procedures work in these triggers. ...
  • 91
0 votes
2 answers
42 views

Determine new/changed data(rows) on a table during a table clone operation

I'm trying to alter some heavy data tables tables, this operation may cause some impact on our production service, so to minimize outages the plan is: create a copy table that inherits table ...
0 votes
0 answers
47 views

MSSQL Server Database Trigger Permissions - issue after migrating from 2008 to 2017 Server

I have some triggers set up on a database (Dynamics NAV) across various tables for Insert, Update, Delete. The triggers write to a separate database to log the DB, Table, RowId and date/time. The ...
1 vote
2 answers
194 views

Disable all triggers in a database

How do I disable all triggers in a database from another database which are currently enabled .And then enable it back only the ones I disabled .
0 votes
0 answers
174 views

MySQL IF NULL of a variable is not working as expected in a trigger

We have the following trigger to ensure that a version field is updated in a related table, normally the trigger contains only the UPDATE statement, the INSERTs are added for debugging and to explain ...

1
2 3 4 5
29