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.

1679 questions
70
votes
5 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,587
  • 1
  • 14
  • 19
31
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
  • 2,865
  • 7
  • 27
  • 49
27
votes
1 answer

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
  • 52,958
  • 19
  • 127
  • 190
13
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
  • 14,290
  • 32
  • 84
  • 135
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
  • 243
  • 1
  • 6
  • 13
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
  • 2,592
  • 5
  • 32
  • 47
11
votes
1 answer

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();
10
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
  • 19,563
  • 57
  • 170
  • 298
9
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
8
votes
2 answers

Is it possible to display trigger error message to Webpage?

I have 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 your_table FOR EACH…
8
votes
1 answer

Postgres plpgsql with PERFORM CTE queries

I tried to simulate my problem in the code example below. In the code below, I am doing a select * from test in a procedure. As we know, we must use the perform keyword for this. This works great: perform * from test; However, if I try to rewrite…
8
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…
Annihil8
  • 322
  • 1
  • 2
  • 16
8
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…
Rory
  • 48,706
  • 67
  • 174
  • 234
7
votes
2 answers

Timestamp for row creation and last modification

I need to keep track of the time a row was inserted into the database, and the time it was last modified. I tried to create two separate columns, and use CURRENT_TIMESTAMP: create table def ( id int, creation timestamp default…
Matt Fenwick
  • 44,546
  • 19
  • 115
  • 184
7
votes
0 answers

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,052
  • 7
  • 18
1
2 3
99 100