Questions tagged [database-trigger]

A database trigger is procedural code written in the current database DML, that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database.

A database trigger is procedural code written in the current database , that is automatically executed in response to certain events on a particular table or view in a database. The trigger is mostly used for maintaining the integrity of the information on the database.

1659 questions
3
votes
1 answer

Can you prevent an insert in an after trigger in pgsql?

In postgres, I have an after-insert trigger on a partitionned table that checks if the record is unique or not. Currently, if the record is not unique, the trigger raises an exception. This is not what I want because I just want to ignore this case…
MMacphail
  • 541
  • 3
  • 19
3
votes
1 answer

PL SQL Loop Table after insert and update

I'm trying loop through a table called broker after an insert to a different table called appointment and update a value on the broker table this what i have. When i try to create the trigger it comes up with an error saying "Trigger created with…
Vavako9914
  • 33
  • 4
3
votes
1 answer

Unique constraint violation in PostgreSQL Trigger

I have below two tables. I wrote after insert trigger on employees table. If i insert the record in employees table it will insert the record in employee_audits table. Both table have primary key column (id). suppose if you try to insert record ID…
Ram
  • 727
  • 2
  • 16
  • 33
3
votes
1 answer

How can I create a trigger in PL/SQL that can create a restriction so that they can only put 1 character?

CREATE OR REPLACE TRIGGER sexo_A Before update or insert of sexo on ator for each row when ( if (new.sexo = 'F') then return 1; elseif (new.sexo = 'M') then return 1; else then return 0; end…
Filipe Mota
  • 137
  • 8
3
votes
2 answers

Trigger raising: "ERROR: stack depth limit exceeded"

I am trying to make a trigger where after I insert a painting, then I want to insert it to either the In_Gallery table or the On_Loan table but not both. When I tried to make a trigger function, I keep getting the error: ERROR: stack depth limit…
Drakus
  • 75
  • 8
3
votes
1 answer

Counting Children in a firebase Cloud Functions

i'm learing to use firebase and i need some help. I need to take the number of children of a specific node in a Firebase Function but i can't. This is my node: I would like to write a trigger that after a new user is created in watingRoom,…
3
votes
1 answer

Accessing transaction context in a Postgres trigger

I have a Postgres 11.3 database that has lots of triggers on it. These triggers are automatically generated through some metaprogramming via SQLAlchemy, and essentially wrap every CREATE/UPDATE/DELETE action on every record, storing a "version" of…
Jamie S
  • 760
  • 3
  • 9
  • 19
3
votes
2 answers

How can i create duplicate records based the value in another table

I have two tables in my database, Work_Order table which is the source table where work order information's stored i also have Work_Schedule table which contains work schedules which tell peoples in the production floor what to build, when and how…
Kinfe
  • 305
  • 1
  • 3
  • 14
3
votes
0 answers

How to use mysqli_sqlstate() to display trigger error message?

I have Before Insert trigger under certain condition, If condition: false Error occurs. I should display that error message which occurs in database trigger to HTML web page to notify user! CREATE TRIGGER check_trigger BEFORE INSERT ON…
3
votes
1 answer

how to use if condition in mysql with status = 2

create trigger with status with passed with status = 2 and I need to create a tigger after update row second time when del_status = 2 CREATE TRIGGER `exchange_log_update` AFTER UPDATE ON `exchange` FOR EACH ROW INSERT IF NEW.del_status = 2 INTO …
Param
  • 49
  • 3
3
votes
0 answers

Creating database triggers via Fluent API

I am using ef-core 2.2 in connection with sqlite. In order to prevent/catch concurrency exceptions, I am creating a concurrency token in the according table. The token is a timestamp which I am configuring in my DbContext class via Fluent…
indexoutofbounds
  • 793
  • 12
  • 32
3
votes
2 answers

postgres - creating trigger functions with arguments

I was wondering if it was possible to create a trigger function with arguments, since the function's logic is the same, but may just insert into different tables and column names. Here's the function: CREATE OR REPLACE FUNCTION …
A. L
  • 11,695
  • 23
  • 85
  • 163
3
votes
1 answer

MySQL trigger not checking variable correctly

I am new to MySQL triggers and would like to prevent entries from being stored in the database if they are invalid. In this case, I would like to check if the module year is greater than the number of years in a course. Here is my procedure (This is…
iProgram
  • 6,057
  • 9
  • 39
  • 80
3
votes
1 answer

Enforcing that all columns have different values

A particular val# should be in no more than one column. Multiple columns can be empty though. (I don't want to use NULL instead of empty.) CREATE TYPE vals AS ENUM ('val1', 'val2', 'val3', 'val4', 'val5', ... 'empty'); CREATE TABLE some_table ( ... …
tom
  • 2,137
  • 2
  • 27
  • 51
3
votes
3 answers

Call external API on change to Azure SQL database table

We have a table called Guest in an Azure SQL database. We also have a campaign management tool sitting behind an API on the providers cloud. When a record is created, updated or deleted in the Guest table, we would like to call the API in order to…