Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [trigger]

Procedural code automatically executed in response to a database event.

2
votes
1answer
31 views

Logon Trigger Unexpected Result

I have only server logon trigger and it is being used to prevent logins coming from an application/server combination. It works appropriately for that application/server combination and gives the ...
0
votes
1answer
14 views

MySql - filter bad words in multiple tables using triggers

I have for example two tables blog_posts and image and each record in these tables have a text field, that may contain a bad word in it. so the idea is, I want to check these records and change these ...
1
vote
0answers
11 views

Only allowing selected values of different linked tables be selected. MySQL Trigger

I have 3 tables. I have an instructors table and facilities table. They are linked by facility.facility_id=instructors.facility_id (i.e. A facility can have many instructors but an instructor can ...
0
votes
0answers
15 views

one to many relation how to create a new row with mysql trigger

i'm really new to mysql triggers so...i have 3 tables: a,b and c. table a is related with table b with a one to many relaion and table c is the table that get the triggered infromation from the 2 ...
0
votes
0answers
17 views

mysql trigger before insert

How can i make this trigger update my table DATA if there is no row to update. Until i insert data in other table lets called ABC, this table uses a after insert trigger to insert information into ...
1
vote
1answer
48 views

Trigger to update only if value is in lookup table

I only want to update the comment if a description for the event is found in the TagDescLookup Table. If the Tag isn’t in the Lookup table then don’t change the existing Value for the comment column. ...
0
votes
0answers
26 views

Postgres TRIGGERS to create csv file after insert on Foreign Table

I have a foreign table called vw_asset_register with over 5000 rows in there which I'm calling from MSSQL database. SELECT * FROM vw_asset_register. I always use this to create CSV file into my ...
0
votes
0answers
30 views

init_connect not executing

From this question I was able to make my init_connect = "CALL mydb.Warnings()", but a user login in does not triggers the SP. the SP is like: CREATE DEFINER=`root`@`localhost` PROCEDURE `Warnings`...
0
votes
1answer
21 views

Syntax Error on Create Trigger

CREATE TRIGGER new_trx_tmp_on_transaction_update AFTER UPDATE ON transaction FOR EACH ROW BEGIN IF NEW.trx_status = 1 AND ( NEW.cat_id = 'CASHBACK' || NEW.cat_id = 'REFUND') THEN INSERT ...
0
votes
0answers
21 views

help to monitor and trigger script which then send mail [closed]

I need some help to run query which monitor a db account (SSMS), and once account is on a certain value, it must send me an email. I have my SELECT script I have already set up the : EXEC msdb....
1
vote
1answer
42 views

MySQL Triggers not working from PHP page but work for manual DB updates via phpMyAdmin

I have the following two Triggers in my MySQL DB that fire BEFORE/UPDATE and AFTER/UPDATE on the house_report_details table. The first deletes all records in my scratch table tmp_house_rpt_details and ...
1
vote
2answers
38 views

If count >= row then insert row (substitute for variables and else/if)

I do 99% php/javascript work so getting my head around SQL is always a struggle, sorry if I seem dense. So I've got a table that looks something like this: post_id | meta_key | ...
0
votes
1answer
23 views

FUNCTION BEFORE TRIGGER INEXISTENT OPERATOR date > = double precision

In the 'pubblicazione' table I want to insert some fields of the tuple contained in the 'legge_approvata' table, but to do this the promulgation date must be in the same month and year as the date of ...
1
vote
2answers
58 views

Can a trigger create a TABLE when inserting data?

I have a trigger that keeps track of history of table dev by inserting a row in table dev_hist: CREATE OR REPLACE FUNCTION process_dev_hist() RETURNS TRIGGER AS $dev_hist$ DECLARE action_name ...
0
votes
2answers
20 views

Sorting ranking by trigger

I create a game in which players will gain levels. The basic information is in the table "char" (nickname, lvl, exp, money ...). I want to make a ranking that will be updated on a regular basis and ...
0
votes
1answer
36 views

In BEFORE UPDATE TRIGGER, how do I prevent changing nothing but timestamp?

I'm working on a trigger, and part of its functionality is to prevent UPDATE if the only field being updated is the timestamp field. My current solution is like this: CREATE OR REPLACE FUNCTION ...
0
votes
0answers
28 views

MYSQL trigger syntax for CONCAT

I am creating a trigger which should be really easy, but I cannot get past the set @code line? What am I doing wrong? There is an ID column in the wp_users table. CREATE TRIGGER affiliate_insert ...
0
votes
1answer
24 views

What is a practical use of FOR STATEMENT triggers?

I understand very well the idea behind triggers, how and when to use them. I also see the practical use of a FOR EACH ROW trigger. But I lack to find a concrete example of when I would use a FOR ...
4
votes
1answer
51 views

Can a non-owner of a table be allowed to disable the table's triggers?

I would like for one user who is not a table owner, give the permissions to turn off and turn on the triggers. Can it be done?
1
vote
1answer
15 views

Open encrypted trigger of table in database (MS SQL Server Management Studio)

Microsoft SQL Server Question for Trigger in database-tables. Is there a possibility to view Code behind a encrypted trigger of a database table? I only see a key inside the Icon and rightclick "...
0
votes
0answers
12 views

SQL Server update trigger populate a variable using a select clause on another table

Hope you guys can point me in the right direction here! Using SQL Server I need to run an update trigger on a column in a table which increments or decrements a counter value in another table. ...
0
votes
1answer
17 views

mysql trigger not allowing to select from another table

I have the following snippet in a trigger on a table named bugs: SELECT uat_reopened_stats.release_name (uat_reopened_stats.rate_bugs + qa_reopened_stats.rate_bugs + ...
0
votes
1answer
23 views

Pass parameter to trigger dynamically

I have a table on a mysql 5.7 db, containing say athletes with their mean, max, avg times in a specific sport. I have another table that lists some calculated statistics based on those values. I ...
0
votes
0answers
19 views

SSMA Selecting Specific Trigger

We are beginning work on migrating an Oracle Database to SQL Server and I have installed the appropriate SQL Server Migration Assistant. While I am not planning to use this to build the actual ...
0
votes
0answers
14 views

trigger to only execute once after multple rows inserted

I need to use a trigger to copy data that is inserted into table A to table B each time an insert occurs. The problem with the approach below is that when multiple rows are inserted at once, the ...
0
votes
0answers
10 views

trying to create trigger, create never executes

I am trying to define a trigger in MySQL and the language to create it never executes. I have already defined and inserted data into the database with no problem. This is the start of my trigger. As ...
2
votes
1answer
29 views

How to modify values on INSERT based on referenced table, even if foreign key doesn't exist yet?

Summary I want to add rows to a (projected) very huge table, but switch 2 values for references in other tables. The catch is that the referenced tables should be updated automatically when new ...
0
votes
1answer
44 views

Why is a trigger preventing update?

I have a script that runs weekly. It updates multiple tables in my database. It turns out one statement attempts to update 150,000 rows on a table that contains 250,000 rows. That failed this week ...
0
votes
1answer
42 views

A AFTER INSERT trigger error for security context

A trigger has stopped working since we have changed our SQL Server to a new server. Trigger is now being corrected to point to the new location of the table on the new server. When updating fields on ...
1
vote
1answer
107 views

Use NEW in FROM clause in Postgres trigger?

I am trying to write a Postgres trigger to unnest an array field before inserting or updating a new row. E.g. SELECT unnest(something) FROM NEW However, this seems to lead to an error: relation '...
0
votes
1answer
33 views

Trigger to log Users Assigned to website

Is it possible to create a trigger so that works with the following scenarios: User types valid login info to the web application A trigger is activated and login name is inserted to the audit ...
0
votes
0answers
22 views

DDLTrigger_Audit error “The user does not have permission to perform this action”

I have a DDLTrigger_Audit enabled in my database when I try executing a stored procedure having Drop and Create index statement in it fails with the below error. database "XXX" failed on Jan 17 2019 ...
-2
votes
1answer
43 views

Can I INSERT the result from a query INTO a new table with a TRIGGER?

I have a table named Stadistics which contains the data shown below: date hour num_prodcuts -------------------------------- 2019-01-16 12:42 3.2 2019-01-17 13:40 ...
1
vote
1answer
16 views

Synonym being recreated randomly - possible to create some kind of trigger/log?

We have a couple of databases with synonyms to link each other, one of the synonyms is randomly being recreate incorrectly with an additional set of square brackets in the database name. I've checked ...
0
votes
1answer
51 views

Ensuring unique value for group of rows in table with trigger and concurrent transactions

I've seen similar variations of this question asked, but nothing that tackles this particular implementation and I was wondering if it was possible to do with sql/plpgsql. Take this as more of a ...
-1
votes
2answers
35 views

mysql trigger data from a many to many relation

I am new to triggers, so I want to know how I could select attributes from 3 different tables to insert them into a new table. I have 3 tables with a many to many relationship: table users wich has ...
0
votes
1answer
40 views

How can i Update the status of field with a trigger?

This is my example code: create trigger MyTrigger on myTable after update as begin set nocount on; update talleres set status='active' where FirstDate=getdate() end go create trigger MyTrigge2 ...
0
votes
1answer
54 views

A trigger making a timestamp of when another column was changed

I've beeen trying to create a trigger, that'll make a timestamp, of when our account was "deleted" which we do by setting deleted = 1. Below code creates a trigger for that purporse, however it has ...
2
votes
2answers
46 views

SQL Server 2016 Trigger issue

I need a little help with a trigger. Where I'm in wrong: CREATE TRIGGER [dbo].[tr_ins_MyTriggerName] ON [dbo].MyTableName FOR INSERT AS DECLARE @Number nvarchar(20) , @Date datetime , ...
0
votes
0answers
33 views

SQL Server 2014 Triggers and Merge Replication

I am trying to have a trigger fire when the Merge agent\user insert\delete\update data. The trigger inserts data into a log table. I don't want to use NFR (Not For Replication) because I need that the ...
1
vote
1answer
23 views

Trigger error in MySQL

I'm using Toad for MySQL, and I have to make a trigger so that: When the rent of a car is <=15 and >= 25, I insert a letter "A" in the field category When the rent is > 25 and <= 35, insert the ...
1
vote
0answers
23 views

Azure Database for PostgreSQL and Event Triggers

I am using Microsoft Azure Database for PostgreSQL with PostgreSQL 10 installed. As I'm trying to work on future tables together with other users I want to enable the other users to alter my tables as ...
1
vote
1answer
36 views

Triggers corrupt merge replication

I have merge replication (SQL server 2014) and a table that have 3 triggers that monitor delete, insert and update. All of the triggers are after trigger not instead of. I'm updating the value on one ...
1
vote
0answers
65 views

Trigger for add discount on total price calculated from other table - oracle 11g

I have the following schema: CREATE TABLE ORDER( OrderId NUMBER PRIMARY KEY, Value NUMBER); CREATE TABLE ORDERITEM( OrderItemId NUMBER PRIMARY KEY, OrderId NUMBER, ...
2
votes
1answer
153 views

SQL Server : delete row trigger

I have these 3 tables: ConstructorEmployee EID (employee ID) as primary key and other key. Project PID as primary key and other keys. ProjectConstructorEmployee PID and EID as foreign keys to ...
0
votes
1answer
65 views

Accidental deletes at SQL Server Subscriber

Unfortunately, this happened twice in 2 weeks on our most critical db server; just before Christmas! Instead of running a delete script at the publisher, the script was run at the subscriber, which ...
2
votes
1answer
29 views

Postgres triggers for group_id

I have a table that looks like this: CREATE TABLE transactions( id SERIAL NOT NULL PRIMARY KEY, value NUMERIC(10,3), note TEXT, group_id INTEGER); I'd like to update the group ID automatically with ...
3
votes
1answer
57 views

Database-wide trigger

I'm new to DBA and I'm attempting to create a trigger that will update the a specified column in one table whenever an insert is made into every table across the database. I understand it is possible ...
0
votes
1answer
54 views

Stored Procedure infinite looping after index updates

I have inherited a very old and poorly written stored procedure with nested fetch statements. This code processes a large amount of data by copying from one database into another. This process was ...
0
votes
1answer
67 views

How to make a trigger for create_view [closed]

I need to make a trigger about who and when created a view. I have some groundwork about it.. So, when some user is running a script for create view, trigger is crushing because this user doesn't have ...