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
101
votes
7 answers

Create or replace trigger postgres

I want to "create or replace" a trigger for a postgres table. However, there is not such sql expression. I see that I can do a "DROP TRIGGER IF EXISTS" first (http://www.postgresql.org/docs/9.5/static/sql-droptrigger.html). My question are: Is…
jbarrameda
  • 1,927
  • 2
  • 16
  • 19
37
votes
2 answers

How to disable triggers in MySQL?

In my MySQL database I have some triggers ON DELETE and ON INSERT. Sometimes I need to disable some triggers, and I have to DROP e.g. DROP TRIGGER IF EXISTS hostgroup_before_insert // and reinstall. Is there any shortcut to SET triggers…
Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
36
votes
6 answers

MySQL - Trigger for updating same table after insert

Here's what I'm trying to do: When there's a new INSERT into the table ACCOUNTS, I need to update the row in ACCOUNTS where pk = NEW.edit_on by setting status='E' to denote that the particular (old) account has been edited. DELIMITER $$ DROP…
th3an0maly
  • 3,360
  • 8
  • 33
  • 54
16
votes
2 answers

Is it possible and how create a trigger with Entity Framework Core

Is it possible to create a SQL trigger with Entity Framework Core. Maybe by using instruction in protected override void OnModelCreating(DbModelBuilder dbModelBuilder) { } Or simply by executing SQL statements in Migration scripts public override…
Bastien Vandamme
  • 17,659
  • 30
  • 118
  • 200
16
votes
2 answers

How to create trigger for all table in postgresql?

I have a trigger, but I need to associate with all tables of the my postgres. Is there a command like this below? CREATE TRIGGER delete_data_alldb BEFORE DELETE ON ALL DATABASE FOR EACH ROW EXECUTE PROCEDURE delete_data();
14
votes
3 answers

How can I find all the db triggers in MySQL?

I created a trigger using SQL, how can I see the trigger using MySQL in phpMyadmin?
Tattat
  • 15,548
  • 33
  • 87
  • 138
12
votes
4 answers

MySQL trigger set values for NEW row and update another in the same table

I have a table that I keep track of fees for a specific item. These fees can change over time so I have two columns (startDate, endDate) with the current set of fees always having an endDate in the far future. I already have a trigger that I use to…
donbyte
  • 253
  • 2
  • 6
  • 13
11
votes
1 answer

PostgreSQL : NOT VALID constraint vs validation trigger

I have a table with a "currency" column. I'd like to prevent further insertion of certain currencies, without removing the existing ones. Initially I was thinking of a validation trigger. Then I discovered the NOT VALID option of ALTER TABLE ADD…
ChennyStar
  • 350
  • 1
  • 2
  • 11
11
votes
1 answer

SQL Functions cannot return type trigger

I'm using PostgreSQL with pgAdmin and I can't get a trigger function to work. However, as far as I am aware, you can return type trigger in PostgreSQL? CREATE OR REPLACE FUNCTION validate_Cat() RETURNS TRIGGER AS $BODY$ BEGIN -- CODE…
user195257
  • 3,186
  • 5
  • 36
  • 49
11
votes
2 answers

Using `BEFORE INSERT` trigger to change the datatype of incoming data to match the column datatype in PostgreSQL

I have a postgres table, with a column C which has type T. People will be using COPY to insert data into this table. However sometimes they try to insert a value for C that isn't of type T, however I have a postgres function which can convert the…
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
11
votes
1 answer

Why cannot I create triggers on objects owned by SYS?

While trying to create a trigger named ghazal_current_bef_upd_row : create trigger ghazal_current_bef_upd_row before update on ghazal_current for each row when (new.Rating < old.Rating) begin insert into ghazal_current_audit …
Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
10
votes
1 answer

Postgres: Trigger on FOREIGN TABLE

I would like to use postgres_fdw and house a FOREIGN TABLE in my database. Is it possible to define a trigger on the local server for this FOREIGN TABLE that recognizes an INSERT event on the remote server. If so, please provide an example. Data…
J Spratt
  • 1,762
  • 1
  • 11
  • 22
10
votes
4 answers

Oracle create trigger error (bad bind variable)

I at trying to create trigger with the following code. CREATE OR REPLACE TRIGGER MYTABLE_TRG BEFORE INSERT ON MYTABLE FOR EACH ROW BEGIN select MYTABLE_SEQ.nextval into :new.id from dual; END; I am getting error Error(2,52): PLS-00049: bad…
user2014963
9
votes
2 answers

Prevent Insert Trigger

How can I get this trigger to prevent the insert where the advance is not greater than 0 or less than 100? Thanks. DROP TRIGGER CheckAdvance; CREATE OR REPLACE TRIGGER CheckAdvance BEFORE INSERT OR UPDATE OF advance ON titles FOR EACH ROW WHEN…
jor2
  • 460
  • 2
  • 5
  • 21
9
votes
5 answers

Is it possible to dynamically loop through a table's columns?

I have a trigger function for a table test which has the following code snippet: IF TG_OP='UPDATE' THEN IF OLD.locked > 0 AND ( OLD.org_id <> NEW.org_id OR OLD.document_code <> NEW.document_code OR -- other columns…
MD Sayem Ahmed
  • 28,628
  • 27
  • 111
  • 178
1
2 3
99 100