Questions tagged [trigger]

Procedural code automatically executed in response to a database event.

Filter by
Sorted by
Tagged with
0
votes
2answers
18 views

What is the difference between tsvector_update_trigger and ts_vector generated column?

Newbie to full text search, I have a feed_items table as follows feed_items (...title varchar, summary varchar, fullarticle varchar,...) I want to create a ts_vector column to search query from ...
-1
votes
0answers
14 views

Trigger implementation help

COMPORDER(CodA,CodO,quantity,price) /it describes the details of the order ,the quantity and price/ STORE(CodA,description,allocation,quantity ) ORDER(CodO,OrderDate,CodCustomer,SentDate,complete) ...
0
votes
0answers
15 views

Trigger implementation , did i do it properly?

FOLDER(CodFO,name,path,dim,ContainerFolder) FILE(CodFI,name,CodFO,path,dateC,dateE,dim) After a file is inserted into the FILE class , its path field gets updated after the instert in a way that it ...
1
vote
1answer
24 views

How to make mysql trigger to access another table's entry?

Say there is a DB with 3 tables Books table - contain book_id and its title Inventory - A list of book_ids in the inventory Logs - A list of log strings. Every time I add a new book_id to the ...
-4
votes
0answers
27 views

SQL Trigger Runs in Debug Mode but Not in Production

I created a SQL Trigger (SQL Server 2012) for "After Update". Very basic taking values from the "deleted" table and inserting some of them to an archiving table. When I debug it in ...
1
vote
2answers
77 views

What are the Cons of using triggers in place of count(*) for counting related entities?

What are the cons of using the below approach? What steps can be taken to prevent someone from incorrectly updating the count? Is the below approach an anti-pattern? If yes, what better approaches ...
0
votes
0answers
13 views

Actualizar en Trigger de delete en Mysql8

tengo una tabla en MySQL8 y una situación similar a esta: Tengo solucionado el trigger de insert, pero al querer hacer el trigger de delete (por ejemplo) me dice que no puedo modificar la tabla ya ...
0
votes
1answer
45 views

Trigger created with compilation errors

SQL> create table master(pno number(5) primary key,pname varchar2(20),price number(10,2),stock number(5)); Table created. SQL> create table trans(p_no number(5),no_pro_sold number(5)); Table ...
0
votes
1answer
33 views

Its possible create a trigger after every transact in all DB? (SQL SERVER)

I have 100+ databases in my instace of SQL SERVER and mostly is a legacy DB but i dont have a control of what is new and what is old. My idea is create a Trigger in all server for every transact and ...
0
votes
1answer
20 views

insert and update triggers do not fire on replicated table

I have created a publication and a subscription on two servers with wal_level = logical in my postgresql.conf. Replication is functioning normally. My problem is to track changes in the replicated ...
0
votes
1answer
41 views

Oracle 12c - Logon Trigger According To Machine Information

I want to create a logon trigger. Trigger will do the following: It will block access to the database based on certain users and certain machine information. Then it will give an information message ...
0
votes
1answer
33 views

create a trigger to update status on parent table based on values of child table

Table order columns - id status 1 confirmed Table trays columns - id,orderid(fk),status 1 1 done 2 1 processing I have to update the status of ...
1
vote
1answer
33 views

Column name as an argument of the function called in the trigger (PostgreSQL)

I looked at all similar questions, but it seems I didn't have enough knowledge to apply them to my issue. Take a look at the following code. The bottom line is that I have a function that updates the ...
0
votes
0answers
59 views

Unable to get FileStream Length with After Insert trigger

I asked this question on StackOverlow, but it mostly received comments about the use of variables and no answer. I program mainly in VB.Net, so my T-SQL knowledge is limited. The reason I'm populating ...
0
votes
0answers
19 views

How to run both "before" and "after" update in trigger

I need to calculate prior values in a table before the column values are updated. Basically, I have to calculate the difference between the before the update and after update values. If there is any ...
0
votes
0answers
8 views

After insert trigger is not working on Aurora Writer instance

I have an After insert trigger on aurora writer instance and it is not inserting any records into the audit log table after the record is inserted in the table. This is my AFTER INSERT trigger ...
0
votes
1answer
275 views

ERROR: syntax error at or near "END" [closed]

I am trying to play around with trigger and found some samples online which I pretty much copied before except changed table name and row counts. But somehow I kept on getting syntax error and ...
0
votes
1answer
46 views

Use trigger on DELETE to retrieve original SQL command and user who did it

I'm trying to create an audit log to store all delete commands on some tables, on MSSQL 2012. What I need is the username that executed it and the command executed, then I can insert them on a log ...
0
votes
1answer
31 views

Postgresql - Is calling a stored procedure in a trigger possible?

I would like to call a stored procedure using a trigger in Postgresql. Is it possible? Here is an example: create table foo(n int primary key, n1 int); create or replace procedure ...
1
vote
1answer
31 views

Is it possible an AFTER DELETE per-row trigger is not run?

I've created a function which inserts in an audit table some data about the row that just has been deleted, and created an AFTER DELETE per-row trigger on the table I want to audit. This is working ...
0
votes
1answer
22 views

Postgres preventing update on "events" table but insert "warning" event

I'm facing a bit of a problem on some restrictions I'm trying to implement on my postgresql database. My dilemma is as follows: I have an event table that logs basically everything that happens on my ...
1
vote
1answer
20 views

Calling a boolean function for Trigger WHEN conditions

The following, CREATE TRIGGER _trigger_insert_form_metadata AFTER INSERT ON my_table FOR EACH ROW WHEN _conditions_form_metadata(NEW) EXECUTE PROCEDURE _trigger_insert_form_metadata_function(); It ...
1
vote
2answers
102 views

Error: Dynamic SQL is not allowed in stored function or trigger

Im trying to convert multivalued column in Table A into rows of Table B(The data type of the column is varchar). For ex: Table A id value ae [1,2,4,5] ac [1,6] Table B id value ae 1 ae 2 ae ...
0
votes
0answers
18 views

Postgres: Triggers Not Created for New Partitions

I have a table that is partitioned into a hierarchy of partitions as follows A -> A_x -> A_x_y -> A_x_y_z Where x is the project id, y is the instance id and z is the month. I've created an ...
1
vote
1answer
105 views

Column constraint based on values in another column

I have a PostgreSQL table phase_steps, with the following example rows: phase_step_id|step_type|step_status| -------------+---------+-----------+ 1| RESEARCH| | 2| ...
0
votes
0answers
53 views

Postgres: Event trigger for logging all dbs changes to one table

I am trying to create an generic event trigger, which I set up in every future databases, I create. This trigger should update the main db's table every time one of the other databases have add or ...
0
votes
1answer
30 views

Postgres per-statement update trigger relationship between old and new transition tables

Is there anyway to associate rows between the old transition table and new transition table for a per-statement update trigger in Postgres? docs My use-case is that I have a "shadow" table ...
0
votes
1answer
78 views

Oracle: "table is mutating, trigger/function may not see it"

(Yes, this is one of those question again...) I need to support Oracle database in my software and am now facing the same problem than with MS SQL Server. I have a table I1 (called t_link in my ...
-1
votes
3answers
77 views

after insert trigger not firing after inserting with bcp

content of csv file TEST_1|sl2sysxbar301.dv.local|{'message_type': 2, 'super_evt_non_error': {'a0': 0, 'a1': 0, 'a2': 0, 'a3': 0, 'event': 5528, 'event_string': 'ENERGY_CTRL_RIGHT_PROX_DOWN', '...
0
votes
1answer
29 views

Trigger updatedAt=NOW() for hunded-thousand rows will not actual [duplicate]

I am using SQL Trigger to update updatedAt column if there is a new data inserted/updated in PG 9.6. Here is the function that will be called by trigger CREATE FUNCTION sp_updatedatstamp() RETURNS ...
3
votes
1answer
286 views

Disabling triggers makes DELETE fast, but the table has no triggers?

I am deleting 130k out of 750k rows from a PostgreSQL table. The first time, it took 8 hours to complete the delete query. Second time, I added an index to the table, and rebuilt that index. Now it ...
0
votes
0answers
106 views

Database users are lost after restore - how to fix

We had many facilities that operate in areas where there is poor/no internet connection; the facility staff sent us monthly a backup of the facility database for us to restore it on our data center. ...
2
votes
2answers
126 views

Enforce that every company has at least one CEO

I've a requirement to ensure that every company has at least one CEO. Example database model with requirements db<>fiddle. Basically, a CEO can't be removed from a company without naming another ...
5
votes
3answers
176 views

Enforce uniqueness across a one-to-many-to-many bridged relationship when constraining to one-to-many

We have defined a series of configurations, where, driven by a RESTful API, end-users can build up new revisions. Some of the components of the configuration can have more than one value; a revision ...
1
vote
0answers
18 views

Update a PostgreSQL row with last user and timestamp

I would like to track who is the last user who updated the rows of a PostgreSQL table (v9) and when. This webpage explains how to do it with a trigger regarding the timestamp (I did not try it yet), I ...
-1
votes
1answer
44 views

how to get the email address from inserted data as the recipient in sp_send_dbmail

I would like to use the email address that is inserted in a column as the @recipient in sp_send_dbmail. This code is a trigger that I've been trying to achieve this with and is for test purposes only: ...
1
vote
1answer
426 views

Create a Hangfire job via SQL stored procedure

I know how to create Hangfire jobs via .NET C# code, but there are a few occasions where I'd like for a database trigger to execute a Hangfire job. I searched the web but found nothing so I attempted ...
2
votes
1answer
139 views

SQL Server DML auditing - Triggers vs SQL Server Audit Feature (vs temporal tables vs change data capture)

I am looking to implement an auditing process on an instance I have on SQL Server 2017. However, I am not finding a complete conclusion on which auditing feature would be best to use for a DB with a ...
0
votes
1answer
116 views

Stored procedure to change string to datetime in MySQL

This is a follow up to this question. Turns out the driver that I am using (can't change it) is not compatible with timestamp values. Lets say it is set in stone that I have to load the data into my ...
-1
votes
1answer
30 views

Why PG 13 does not allow deferring statement trigger constraints?

I noticed in PG 13 docs that only row constraint triggers can be deferrable. Why not statement constraint triggers?
0
votes
0answers
35 views

How can I link together auditing of the sql and before and after values for row updates in Oracle

I had a number of triggers that used to work in Oracle 8i, that worked to capture both the before, and after values of a row, as well as the sql used to do the update. (I realize there would be cases ...
0
votes
1answer
38 views

Insert into table if column <> "Text" for each project

I have created two triggers to insert into fact table if a new row is inserted into dim table. One checks if Project exists already and if not, then query will be triggered and adds 12 new rows per ...
0
votes
1answer
51 views

Using Trigger creates duplicates

I have created a trigger to inert into table2 if a new row is inserted into table1 (at least I thought). The queries is like this: CREATE TRIGGER project_insert ON TABLE1 AFTER INSERT AS BEGIN Insert ...
-1
votes
2answers
60 views

Insert new rows when item is added to another table SQL [closed]

I have to tables. One dimension table with projects and one fact table with projects, value and a period(month). Looking to add 12 new rows pr project ID into my fact table, when a new project is ...
0
votes
1answer
38 views

Cascading PostgreSQL triggers between three tables

I have a ‘test’ PostgreSQL 12 schema, defined with initial tables: begin; drop schema if exists test cascade; create schema test; set search_path = test,public; create table jobs ( job_id serial ...
0
votes
1answer
35 views

MS SQL Creating Tables and Adding Values by a Trigger

Table_A is an existing table which has 3 columns Id (PK), Name, Stock. I would like to create a trigger to create a table. For example, Table_A has an item, Id (PK) = 3, Name = Apple, Stock = 10. By ...
1
vote
1answer
48 views

Thousands of After Insert and Update Triggers Causing Performance Issues

We have a After Insert and Update trigger on one of our tables. The trigger basically makes a json payload and enqueues it in a RabbitMQ system. Today a large insert script was run on the table (over ...
0
votes
3answers
98 views

Replicating contained SQL databases to customer in near real-time

We host a number of customer SQL Server databases that we need to replicate to external customer sites in near real-time. The main constraint we have is that, for security reasons, our databases are ...
1
vote
1answer
34 views

Junction table Trigger after update in another table

I'm just trying to create a trigger that performs an update in a junction table. In principle, I have three tables with Many-to-Many relationship. Table a: a_id, a_is_active Table b: b_id, b_is_active ...
0
votes
1answer
27 views

How to trigger an event when row column crosses now()?

Is it somehow possible in postgres 12 to trigger an event when a table with an tsrange column crosses now(), or someone insert something that where the tsrange is prior to now()? Triggers, as far i ...

1
2 3 4 5
28