Stack Exchange Network

Stack Exchange network consists of 174 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

Procedural code automatically executed in response to a database event.

0
votes
0answers
14 views

MySQL trigger/check on INSERT based on multiple factors (location, date and time)

I have a shift schedule planner for various warehouses. I'm trying to add multiple checks at DB level. If I'm using a composite key (by removing shift_id) to match staff, location,date time it's works ...
0
votes
0answers
26 views

Trigger Resource Consumption

I made a trigger that activates every time an insert, update or delete has been made on a certain table. I have already implemented it into the tables in one of our servers. I now need to know if ...
1
vote
2answers
29 views

SQL Server 2008 R2 - How does the SQL Trigger actually work in this case?

I have a table named _Test which has the following values stored in it. Primary Key : Id I also have designed a trigger on that table ALTER Trigger [dbo].[_Test_Data_Save] On [dbo].[_Test] For ...
0
votes
0answers
36 views

SQL - TRIGGER AFTER INSERT [closed]

I have a table Client. There are two columns Name and FathersName. Now I need to check these two fields at the time of insert, the combination of these two fields shouldn't be repeated. The possible ...
0
votes
0answers
17 views

How to skip a transaction if some condition is true? [closed]

I want to skip a transaction if the data on the field CODE is MXN. The user send to our system the data and, using triggers, we handle the data received before insert into the table (BEFORE INSERT ...
0
votes
1answer
18 views

MySQL 8.0 Triggers Current_User not working

I have this trigger that inserts a row to a table CREATE DEFINER=`root`@`localhost` TRIGGER `user_log_AFTER_INSERT` AFTER INSERT ON `user_log` FOR EACH ROW BEGIN INSERT INTO ...
0
votes
0answers
24 views

Trigger Name Blank in sys.dm_exec_trigger_stats

I'm trying to see the triggers that are in my server, I use the query below. It's able to get me the list of triggers I have in the database, but the "trigger name" somehow ends up with column somehow ...
1
vote
1answer
41 views

How to create an INSERT/UPDATE/DELETE trigger

My knowledge with triggers is very poor. I want to create an INSERT/UPDATE/DELETE trigger on a tableA with column names (A1,A2,A3,A4,A5,A6). After the triggers fires, I want to put that data in ...
1
vote
3answers
71 views

How can a trigger be bypassed?

Assuming I have the following table: Create Table [dbo].[Test_IP] ( [IP] varchar(40), [IPType] varchar(6) ) There are more triggers on this table, but all of them are AFTER triggers, and it is ...
1
vote
1answer
47 views

Insert Trigger to a Linked Server error

I created an insert trigger in a table that will fire when an insert/update/delete is made. The trigger is supposed to send information about the query that fired it, but every time it fires, the ...
1
vote
0answers
27 views

SQL DB Trigger - mutiple column changes

I need to trigger off 17 different columns and email the change from what it was to what it is changed to. The trigger below works but I feel like this is not the correct way to achieve this. Also, ...
0
votes
0answers
29 views

Why this trigger is not inserting records?

Here are my 3 tables. Passenger(Passengerid,insuranceid) Passenger_service(passengerid,serviceid) service(serviceid,hotel_insurance_id) Whenever there is a record inserted in passenger table along ...
1
vote
1answer
21 views

oracle: deny naked sql statements

I'm looking for a solution in oracle 12c to deny INSERT, UPDATE and DELETE statements on tables. I would only provide SELECT privileges and exec rights to execute procedures which INSERT, UPDATE or ...
0
votes
2answers
32 views

DELETE inside INSERT Trigger

I wanted to make rotation inside my logs table to store last 100 rows only, and decided to use triggers, as in create trigger rotate_log after insert on logs for each row begin declare cnt int; ...
1
vote
2answers
291 views

How do I rewrite the below Oracle trigger so it will work on SQL Server?

I am migrating from Oracle to SQL Server using SSMA and I get thrown an unparsed SQL error on the below code. Can anyone help me convert this to T-SQL? Thanks in advance. CREATE OR REPLACE TRIGGER "...
0
votes
1answer
19 views

Trigger after insert, insert new row into another table [closed]

I'm developing a Wordpress site. I'm trying to insert a new row into a table when new row with specific value in usermeta table is added. This is what I got for now: DELIMITER | CREATE TRIGGER ...
0
votes
2answers
25 views

PostgreSQL - how to recognize if function was called by delete or update trigger?

I have function, which should be called after update and delete on one table. At the end of function I have to return "old" if function was called after delete or "new" if procedure was called after ...
1
vote
1answer
117 views

Trigger with a Variable Select and Order by

Is there a way to a set trigger that will activate once a new table is created and will get the new tables name? I was able to come up with the query below but it only gets the first query by ...
1
vote
1answer
27 views

How do I use “OLD” or “NEW” in a dynamic SQL statement in an on-update trigger?

Assuming I have the following function being executed on a row-update: CREATE OR REPLACE FUNCTION versioned_update() RETURNS TRIGGER AS $$ DECLARE sql TEXT; BEGIN sql := 'INSERT INTO ...
2
votes
1answer
31 views

How can I write an “on-update” trigger which takes a table-name as argument?

NOTE: The following example is a strongly simplified code, but it illustrates the task in a reproducible example. Looking at this example may make you think "why do it like this"? In reality, the full ...
1
vote
2answers
42 views

Trigger - If time between?

I wish to use a mysql trigger that will update a column called peak to 0 or 1 based on if the CURTIME() is between 08:01 & 11:59. Can anyone help with this trigger?
2
votes
1answer
62 views

Monitor source SQL code of inserts into table

I have a table with rows which should not be there, means the data is wrong according to business logic. And there is a lot of possible sources the insert statement of the "bad" row is coming from. I'...
0
votes
1answer
22 views

Is it possible to execute an “update” trigger if all columns except one have changed?

Assume I have the following table: CREATE TABLE data ( key TEXT primary key, some_interesting_value TEXT, inserted TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), updated TIMESTAMP ...
0
votes
2answers
31 views

How to use variable into SQL in MySQL trigger

I'm trying to write trigger. I have encountered an one problem. My Code is like. DELIMITER // CREATE TRIGGER upd_check BEFORE UPDATE ON user FOR EACH ROW BEGIN DECLARE tempVar text; IF(OLD.name ...
0
votes
0answers
23 views

Trigger insert date auto

My Trigger BEGIN INSERT INTO PaletCDetay (PaletKod, Barkod, Urun, Kalibre, Kilo, Uretici) SELECT PaletKod, Barkod, Urun, Kalibre, Kilo, Uretici FROM UrunPaketDetay WHERE PaletKod =New.PaletKod; ...
1
vote
1answer
25 views

Automating Redshift data dump to a PostgreSQL DB every hour

GIS analyst with minimal experience of this back-end stuff but a big task at hand. I have a redshift database that changes multiple times a day. I want to use this "live" data to make web maps and I ...
0
votes
0answers
14 views

Get the syntax that fired an insert trigger [duplicate]

Is there a way for an insert trigger to get the line that caused it to activate?
0
votes
2answers
51 views

creating a trigger after update exclude a column?

I want to create a trigger that set a column to to_sync true if the other columns has been changed. CREATE TRIGGER [dbo].[product_trig] ON dbo.product AFTER UPDATE SET NOCOUNT ON; IF NOT ...
0
votes
1answer
81 views

Trigger to check if a column is updated and another one has a specific value

I'm writing a trigger for a SQL Server database. What I want is, when a table is updated, check if a specific column is updated or not and if another column has a value = 'W' or not. If it is so, the ...
0
votes
0answers
39 views

Creating a trigger on a column either deleting row or updating row on update, Oracle

I haven't had any experience with triggers, however I'm trying to make a trigger, but i'm making a change in our database setup so that we will follow GDBR regulations. For this I'm required to make ...
0
votes
2answers
38 views

Mysql Trigger Insert row Another Table using by Barcode

I Have 3 Tables: 1) CREATE TABLE `UrunPaketDetay`( `UrunPaketDetay` int NOT NULL AUTO_INCREMENT, `UrunPaketNo` int NULL, `Tarih` date NULL, `Barkod` varchar(14) NOT NULL, `...
3
votes
2answers
424 views

“If not exists” using OBJECT_ID() doesn't work for views and triggers. why?

For tables I can implement "if not exists" and "if exists" as folows: --if table exists - drop If OBJECT_ID('A','U') is not null Drop Table [A] --if table not exists - Create If OBJECT_ID('A','U') is ...
1
vote
1answer
26 views

Creating a Trigger to Update Matching Records in Another Table

Morning, All - I'm currently working on some SQL logic, and wanted to get some input on it. What I'm trying to accomplish is the following (Psuedo-code): When a record is inserted into Table A - IF ...
2
votes
2answers
40 views

Deadlocks With Trigger Based Replication

A table ORIGINAL exists with the following structure: ID VARCHAR Length 10 (key) VALUE VARCHAR Length 10 (non-key) A table REPLICATION exists with the following structure: ID ...
2
votes
2answers
37 views

Do MySQL (5.6) triggers support 4 byte emojis?

I'm using MySQL 5.6.34 with the following settings: "character_set_client","utf8mb4" "character_set_connection","utf8mb4" "character_set_database","utf8mb4" "character_set_filesystem","utf8mb4" "...
10
votes
1answer
865 views

Trigger firing despite no rows being affected

This is more of a general question but the motivation for this question was a problem I faced while using SQL Server. I have this trigger attached to an Insert event on a table that contains some ...
2
votes
1answer
31 views

PostgreSQL insert record by trigger [closed]

create table tab1(id int,name text); create table tab2(id int,name text); create or replace function t_tab() returns trigger as $$ begin insert into tab2 values (new.id, new.name) return new; ...
1
vote
3answers
43 views

How to get the definition of a database trigger?

when I run the following script in one of my databases: SELECT * FROM SYS.triggers when I try to find out about sys.triggers Contains a row for each object that is a trigger, with a type of TR ...
7
votes
1answer
355 views

T-SQL trigger to update columns

I've been working with SQL queries for a couple of weeks and I'm trying to learn and understand from my mistakes. I have a table with two columns IsInvisible (bit) and ShortName (string) and when one ...
0
votes
1answer
35 views

Trigger on 2 tables : issue with INSERT and UPDATE

This is related to my previous question: Trigger to cascade updates to a second table. In my Postgres 9.6 DB, I had 2 triggers on emprise (formerly table1), supposed to insert or update some fields ...
1
vote
1answer
32 views

Trigger to cascade updates to a second table

In my PostgreSQL 9.6 database, I am trying to update 2 fields in table2 with a trigger when table1 is modified. Function: CREATE OR REPLACE FUNCTION schema.maj_tbl2() RETURNS trigger AS $BODY$ ...
-1
votes
1answer
35 views

Trigger to copy deleted rows to another identical table with Cascade Delete On

I have two tables. Sale and SaleProducts SaleProducts contains all the products that have a Sale. 1 sale, many products. (1 to many) SaleProducts has a relation to Sale with On Delete set to ...
1
vote
0answers
21 views

How to aggregate transactions to form a stateful view which can be updated efficiently?

How to aggregate transactions to form a stateful view which can be updated efficiently? For example how to turn the following transactions: CREATE TABLE txns_combined(from_party,to_party,price,qty,...
0
votes
1answer
38 views

Can't create triggers in MySQL, no errors but no triggers either [closed]

I'm trying to create triggers without much success I'm not getting any error but the triggers don't show up either... So what's wrong with this? USE `wa3`; CREATE TABLE `transactions` ( `id` ...
-2
votes
1answer
44 views

Simple Trigger Is Not Created in Mysql

I'm creating a trigger in mysql, but even with the correct syntax and the query being accepted the trigger is not created. If anyone can help. The following is the sql: DELIMITER $ CREATE TRIGGER ...
1
vote
1answer
45 views

How to create `instead of` trigger on a table in postgres?

I want to create a trigger for a table in postgresql. My table contains data about events and includes room number, start time and event duration. Upon new insertion to the table I want to check if ...
2
votes
0answers
43 views

Is there a setting in SQL Server to keep triggers from firing SELECT @@IDENTITY

This is a SQL Server 2014 Server and we have application code the does a Select @@Scope_Identity after an insert into a table. Recently other developers added triggers to this table and ever since, ...
4
votes
3answers
288 views

Will this trigger significantly degrade performance?

I have this trigger to (do my best) to prevent brute forcing logins. It has two seperate functions: If a failed login has been attempted more than 4 times (so read that exactly 5 times) from the same ...
1
vote
1answer
35 views

How to check with update trigger if only one column was updated postgresql

I have a table with many columns and one special column that indicates if is synchronized or not. When an update occurs in the other columns I processed and update a 'log' table, this updates comes ...
7
votes
1answer
56 views

What can be the purpose of this trigger?

I stumble on this trigger when trying to analyze some DB: Create trigger [tbl_Details_Trigger] on [tbl_Details] Instead of Insert As Insert into [tbl_Details] Select * from ...