Procedural code automatically executed in response to a database event.

learn more… | top users | synonyms (1)

1
vote
2answers
2k views

Updatiing a column after expiration of specific time in MySQL

I have a table where I have a column named state(int(2)) and modify_time (time_stamp on update current timestamp). I have an update trigger which changes the value of state column to 0 based on some ...
1
vote
1answer
84 views

SELECT in trigger function in two tables

My table and trigger in PostgreSQL 9.4.3 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit: CREATE TABLE measurements ( measurement_id SERIAL PRIMARY KEY NOT NULL, ...
0
votes
1answer
8 views

MySQL - using result of Procedure in Trigger to Insert in new table

I'm guessing I'm doing something that's prohibited by MySQL, but can't see what. Basically, I have a set of tables that hold lists of things (item name, item types, item groups etc.), and I need to ...
10
votes
5answers
17k views

How to detect any changes to a database (DDL and DML)

There are a lot of databases on my client's sql server. In common, these databases is under development, so developers can design, refactor, do data modifications and so on. There are some databases ...
0
votes
2answers
581 views

Error in trigger: table X is mutating, trigger/function may not see it

Having looked at the following Trigger, still getting the Row 2 error: "ORA-04091: table SUMMITTEST.APL_LOG is mutating, trigger/function may not see it" Please can anyone provide any help in ...
1
vote
2answers
20 views

Delete trigger mysql on another table

I am new on mysql and I am try to create a before delete trigger on mysql. I have a table call "persons" and I need delete a record on another table called "ldap_entries" the table "persons" have a ...
0
votes
3answers
490 views

Mysql trigger not working, syntax issues

I have this trigger CREATE TRIGGER checkcollision AFTER UPDATE ON players BEGIN SELECT RAISE(ABORT, 'collision') FROM walls WHERE NEW.x=x AND NEW.y=y; END; mysql 5.1.72-0ubuntu0.10.04.1 ...
1
vote
1answer
28 views

Why my BEFORE UPDATE trigger takes values from the NEW record? [on hold]

I'm updating data with QGis on a Postgres table. The operation consists of splitting a polygon in two parts, which means that QGis updates the original polygon (to become one of the 2 new ones) and ...
0
votes
0answers
18 views

What is the syntax to sp_recompile logon trigger?

I would like to recompile my logon trigger using sp_recompile. But I can't figure out the syntax. E.g. these don't work: sp_recompile '[Tr_Logon]' sp_recompile '[Tr_Logon]' ON ALL SERVER ;)
2
votes
0answers
28 views

Server Logon Trigger fails after deleting many records in “Logon-Table” -SQL Error 2801

We have a server logon trigger defined that logs every login with information like windows/sql user name, client and time in a table. The table doesn't have clustered index, but it does have a ...
2
votes
2answers
186 views

Java Spring application Database triggers auditing - how to provide the right user that made the change

We are developing a new web application. one of the most basic requirement is to audit all entities changes into a separate table. We would like to use DB triggers for that purpose. We use MySQL as ...
0
votes
1answer
27 views

SQL Server 2008 Triggers and Merge Replication

I am trying to have a trigger fire when the Merge agent inserts or deletes data into / from a table. It is supposed to insert data into a report table for use with SSRS. I DO NOT have the "NOT FOR ...
1
vote
1answer
19 views

Do Triggers in the Active Secondary Database of an AlwaysOn Group Execute?

If I have triggers on tables in a database that is a member of an AlwaysOn group, will they fire on the secondary? If they do fire, and they do something different on the secondary will it matter as ...
0
votes
1answer
120 views

how to use trigger to make SQL Job's step success or fail

Step 1. Call a script to trigger application process. When the application process start, it will insert a record to a specific table. And once the process ends, that record will be deleted from ...
4
votes
2answers
448 views

How do I find the next saturday in MySQL

I have trigger and a stored procedure in it (so SP runs when trigger runs). I need a function which finds the next saturday to put in SP. So lets say, it is Wednesday (2015-7-22) today. If my ...
2
votes
1answer
33 views

Using an UPDATE trigger to populate Eastings and Northings in PostgreSQL

I am wondering if it is at all possible to create trigger that populates the X and Y of a created point into 2 separate fields called 'easting' and 'northing'? It is an update trigger on a table ...
1
vote
1answer
24 views

mysql trigger / stored procedure - update another table row by row

I've already, searched and read, many answers about this issue for 3 days, but couldn't get a clear answer on how to do this. this will be a little long, be patient please. First of all, I am trying ...
3
votes
0answers
46 views

Which is the right way to fix “Error: 1205 Lock wait timeout exceeded; try restarting transaction”

I have a PHP script that sync a local DB against external datasource. Each time the script runs I perform some triggers on the DB where INSERT or UPDATE happen. These are the the triggers for that ...
1
vote
1answer
38 views

The user specified as a definer ('root'@'%') does not exist

I have a trigger defined as follow: USE `veeva_bi`; DELIMITER $$ DROP TRIGGER IF EXISTS veeva_bi.account_ai$$ USE `veeva_bi`$$ CREATE DEFINER = CURRENT_USER TRIGGER `veeva_bi`.`account_ai` AFTER ...
0
votes
1answer
441 views

Deadlock caused by INSERT trigger - thread looking for lock it already has?

Using MySQL 5.6.17. I have a table with an INSERT trigger that reads values from that table and 4 other tables, combines the results and writes that to a sixth table. Ever since I added this trigger, ...
1
vote
1answer
25 views

how to use a variable as a part of a field name in mysql trigger declaration [duplicate]

Here is what I want to do (a part of my trigger): BEGIN DECLARE updatecount INT default 0; declare number int; declare column varchar(10); declare i int default 1; declare j int default 1; while ...
1
vote
1answer
215 views

MySQL add few column exception for TRIGGER UPDATE FOR EACH ROW

How to effectively add column id, name exception for trigger: CREATE TRIGGER updated BEFORE UPDATE ON table1 FOR EACH ROW SET NEW.date=NOW() so that date=NOW() will be affected on updating any ...
1
vote
0answers
24 views

Mysteriously Updated Rows

Yo, heres the trigger causing the Problem USE [SalesDb] GO /****** Object: Trigger [dbo].[trgAfterUpdate] Script Date: 7/16/2015 6:34:01 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON ...
2
votes
1answer
21 views

MYSQL: log the query executed on certain table

I am writing a trigger that suppose to fire on inserts for a table and log the exact query used to insert. However, using below SELECT info INTO original_query FROM INFORMATION_SCHEMA.PROCESSLIST ...
2
votes
1answer
19 views

How to Choose Between VALUES and SELECT for INSERT?

This answer raised the question for me how to choose between VALUES and SELECT in such a function . Using PostgreSQL 9.4.3 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit: ...
1
vote
1answer
22 views

executing command prompt command in MySql trigger

I have one table called table1 in that there are two fields, let say field1 and field2. What i am trying to do is that, when there are records inserted into table1, the values of field1 and field2 get ...
1
vote
2answers
105 views

Execute SQL query after execute TRUNCATE in a table

I have a table called fos_user_user where I have a default record "always". Since I'm testing all the time and sometimes I need to clean that table I'm asking if there is any way to run the following ...
2
votes
1answer
85 views

Prevent row from being inserted with a trigger

I'm trying to prevent a row being inserted if a certain condition is met using a trigger. I'm using a user defined exception to do this, however the row is still being inserted, despite the exception ...
4
votes
1answer
26 views

Update columns values using select from external database and table in MariaDB trigger

I have two databases pdone and veevan. pdone is a kind of master and veevan keep on continue sync against an external sources. I need to perform a internal sync between veevan and pdone so I am using ...
1
vote
1answer
36 views

How to update row values with values from SELECT into another DB in a trigger

I have been working in a trigger for INSERT|UPDATE values for a given record based on same PK. What trigger basically should do it is, foreach row when some INSERT happens on veeva_new.account: ...
4
votes
1answer
2k views

MySQL possibility to create global routines (stored procedures and/or functions)

Is it possible to somehow define globally available routines? It seems like every routine must be created in a scope of the database. When I tried to create a routine from console (without prior ...
8
votes
1answer
13k views

Trigger to UPDATE after UPDATE?

I want to make a trigger to record the time of any update as CREATE TRIGGER col_update AFTER UPDATE ON col FOR EACH ROW BEGIN UPDATE col SET updated=NOW() WHERE id=NEW.id; // or OLD.id END The ...
0
votes
1answer
123 views

alternative to trigger. Cascade

I have 2 tables: table_a: id int, user_id int, job_id int and table_b: id int, user_id int, job_id int I would like achieve something like when I delete a row from table_a it also delete a row ...
0
votes
1answer
273 views

Trigger function check if all NEW.* fields exist in another table

In PostgreSQL I need to code a trigger function that checks if all the fields in NEW.* exist in another table that has the exact same name as the table that fired the trigger but appended with "_hv". ...
1
vote
1answer
179 views

SQL Server: update trigger fires before insert trigger

I have an application with a SQL Server-hosted database. I do not have access to the application code, but I do have full access to the database. I have added my own custom auditing to a table to ...
0
votes
1answer
28 views

DB2 Trigger Error : An unexpected token “OR INSERT” was found following SQLCODE=-104, SQLSTATE=42601, DRIVER=3.68.61

I am getting an error while executing the following queries. As per the DB2 documentation, we can have both update and insert event in the same trigger, but when I am trying to do so I am getting an ...
1
vote
1answer
23 views

Update reps table with right values in a trigger after insert on userterritory

I two DBs veeva and pdone as shown below in the pics As you can see veeva is simple and hasn't no constraints which relies on duplicate and wrong values. The problem happen exactly on ...
2
votes
2answers
32 views

Trigger Gives an Error on Multiple Rows SQL SERVER

I have a problem when I create a trigger which is giving me this error: Msg 512, Level 16, State 1 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, ...
5
votes
3answers
3k views

Using MySQL triggers or transactions?

I want to ask your opinion in using MySQL triggers or transactions in a website. Actually I have a history payment table with - UserId | OperationId | Comment | Credits | Sign (debit or credit). So ...
0
votes
1answer
130 views

Triggering a shell script from MySQL without any 3rd party libraries

Is it possible to call a bash script file in linux using a trigger in MySQL? I've been searching for the answer online and I ran into this articles: ...
1
vote
1answer
220 views

Mysql - Select To XML

I'm Building Audit Trail with Trigger, and want to convert the inserted / updated / deleted value into XML and store it into another table. my trigger look like this: DELIMITER $$ CREATE ...
0
votes
2answers
43 views

how to create trigger in SQL server using two tables to find stock quantity

I have two table sales and purchase. I want to create a trigger which stores final quantity in stock table by subtracting sales table sold quantity from purchase table. There is kikkat as a name n ...
4
votes
3answers
57 views

Use trigger to synchronize columns with fields in json column on insert or update

I'm a bit of a database/postgres beginner,so bear with me. If I have a table, something like this. CREATE TABLE testy ( id INTEGER REFERENCES other_table, name varchar(128) PRIMARY KEY, ...
1
vote
2answers
35 views

Postgresql: Insert trigger function fails on partial insert statement

We have some big tables in our database and the boss thought that partitioning would be a good improvement to our system. I was charged to investigate it and develop all the needed scripts in a test ...
1
vote
1answer
19 views

Trigger is failing with no errors at all, why?

I need to UPDATE territory_id column at pdone.reps table by using and filtering results from veeva_new.userterritory so based on the answer I got here I am trying to build my own and this is how it ...
1
vote
0answers
15 views

How Columns_update() Function Works in Trigger To Find Updated Columns Name

I am in confuse about trigger function Columns_Update(). i Have Basic Idea about this function that it returns a varbinary and it is use to get updated Columns in Trigger even i have Find The code ...
3
votes
1answer
80 views

MySQL trigger after insert with insert and delete instructions does not work properly

I have the following trigger created in phpMyAdmin: Table: tb_agenda Time: AFTER Event: INSERT BEGIN INSERT INTO tb_realizacao (dt_agenda, titulo, ...
2
votes
0answers
41 views

Trigger/Event that fires when a Transaction finishes

I have a query that pulls from about 15 different tables. I am looking to materialize this into a table that stores it in xml/json. (To improve performance.) The problem I have is that these tables ...
0
votes
0answers
32 views

CALL Procedure(Function) = Trigger?

I have discovered some strange behavior in Oracle 11g, and I'm wondering if anyone has an explanation for it. The gist is that when I use a function that contains a commit/rollback/savepoint within a ...
2
votes
1answer
36 views

MySQL stored procedure updates twice

I have this stored procedure: DELIMITER $$ CREATE PROCEDURE updateTrendContentStats(IN mongoid VARCHAR(255),IN numericid INT,IN points INT,IN ctype INT,IN activity INT,IN created INT) BEGIN DECLARE ...