Procedural code automatically executed in response to a database event.

learn more… | top users | synonyms (1)

2
votes
2answers
168 views

Validation of availability for a new order

I have a management application of sales, stock and payment on a warehouse whole saler from a web interface. In particular, when a order is effectuated it must create a line corresponding to each ...
1
vote
1answer
806 views

SQL Server sp_send_dbmail Query Error

EXEC msdb.dbo.sp_send_dbmail @recipients= 'test@test.com', @copy_recipients = 'test@test.com', @query = 'SELECT * FROM INSERTED', @attach_query_result_as_file = 1, @subject = 'Auto-Generated Deleted ...
1
vote
1answer
202 views

Randomly generated password for mysql admin over time?

I have this idea of making my database's Admin account secured by creating the following: Trigger is activated every hour in mysql this trigger activates a stored procedure Stored procedure ...
2
votes
2answers
882 views

How to specify trigger execution order under PostgreSQL?

I'm using "classic" time-based partitioning using triggers. I have found a need for a separate trigger, which runs on the original table. CREATE TABLE twitter_interactions(...); CREATE OR REPLACE ...
0
votes
1answer
89 views

Checking for ApplicationName in a transaction through a Before Trigger

I would like to be able to build a trigger that checks the ApplicationName coming across on a transaction, and if the ApplicationName is of a certain value, then I want to throw an error, saying the ...
2
votes
2answers
5k views

In a trigger, how to check if no fields have changed?

If we receive an update statement that does not check if the value has changed in the where clause, what are the different ways to ignore that update inside a trigger? I know we can do a comparison ...
3
votes
3answers
4k views

Disable trigger for just one table

Is it possible to disable a trigger momentarily but for just one table. For example I have table, TableA with an on insert, update and delete trigger. I also have a table B with the same triggers but ...
4
votes
4answers
20k views

Call a stored procedure from a trigger

I have created a stored procedure in mysql using the following syntax. DROP PROCEDURE IF EXISTS `sp-set_comment_count`; DELIMITER $$ CREATE PROCEDURE `sp_set-comment_count` (IN _id INT) BEGIN -- ...
2
votes
1answer
333 views

MySQL Trigger problem with the email address (cause contains the @ sign)

I'm trying to set a trigger in a table (users) to "copy" the email address of a new row to another table (prova). Here is the trigger: CREATE TRIGGER inserisciemail AFTER INSERT ON users FOR EACH ROW ...
5
votes
2answers
5k views

Database logon trigger

To block a particular user and IP combination on an Oracle Database , I created the following trigger, and compiled without errors. Create or replace trigger you_may_not_login after logon on database ...
2
votes
1answer
296 views

Has anyone ran into this replication breaking bug before?

I've been having this issue where replication was breaking on colliding primary keys. The annoying thing was these were auto increment generated. I think my issues been tracked down to ...
2
votes
1answer
2k views

Does MS Access have anything equivalent to triggers?

I'm developing some code that will eventually talk to an Oracle 10g database. While doing this, I am also redesigning the relevant database tables. I'm not a database pro, and I don't have sufficient ...
4
votes
2answers
1k views

Is there a way to ensure that a SQL Server trigger will be executed?

My supervisor is hesitant to use a trigger in a process because if there is a network interruption at just the right time, the process would not complete. Does SQL Server include the trigger in the ...
5
votes
1answer
492 views

If an 'after' DDL trigger causes an error, is the DDL rolled back?

It has been suggested that DDL is logically performed something like this: begin COMMIT; perform any appropriate pre-DDL trigger code; do the ddl; perform any appropriate post-DDL ...
1
vote
1answer
1k views

How to set up triggers in MySQL for copying a field

I have an in-house application that I've put together, and I'm VERY new to SQL in general. I have a table that contains most of our data. Let's pretend it looks like this. Matrix |Name | ...
1
vote
1answer
201 views

Create a trigger that compares a field, with a field in other table

I have 3 databases, (One principal, one Mirror and a witness) and I'm trying to make this system the most fault tolerant as possible. So I was thinking in doing some extra codding to protect me ...
3
votes
1answer
219 views

Accessing ORA_ROWSCN in the triggers body

Is it possible to access ORA_ROWSCN pseudo-column in the body of BEFORE triggers? I'm thinking about storing this value in the table itself to emulate SQLServer rowversion behaviour.
3
votes
1answer
7k views

Why TRY CATCH does not suppress exception in trigger

I have a trigger on a table (source) that data should be copied to the other one (target) in other database. I am trying to implement custom synchronization process for data: I want that target ...
3
votes
2answers
2k views

MySQL trigger: Compare value in another table

I have the following trigger (generated using PHP via mysqli)... DROP TRIGGER IF EXISTS post_queue_insert; CREATE TRIGGER post_queue_insert AFTER INSERT ON posts FOR EACH ROW BEGIN IF ...
5
votes
4answers
847 views

Making a column immutable in MySQL

I want to make a column in a relation unmodifyable for consistency reasons. The backstory is that I have a n:n relationship where the "connecting" relation has additional values. I don't want that ...
4
votes
2answers
2k views

Can a trigger access the query string?

I'm thinking about using triggers as a logging mechanism in MySQL (v. 5.1) and therefore I'd like my trigger to get the query string in order to store it in another tabe. I couldn't find anything ...
4
votes
1answer
2k views

Why doesn't INSERT AFTER Trigger add all results?

I'm working on the exercises for db-class.org where we have to write a trigger that makes new students named 'Friendly' automatically like everyone else in their grade. That is, after the trigger ...
8
votes
4answers
313 views

How can I know which store procedure or trigger is using a table on SQL Server 2008 R2?

This is the case that in the DB I'm checking, there is an archive table which keeps the user history, and there is a trigger or store procedure that after some time delete rows from this table, in ...
3
votes
1answer
632 views

PostgreSQL pl/perl trigger, differentiate null vs empty

I've been trying to speed up a generic auditing trigger that I had written in pl/pgsql some time back. On update, it generates a list of columns in the table being updated and inserts rows in the ...
2
votes
2answers
789 views

Is it possible for me to be notified if an 'after insert or update trigger' stops working?

Last week, I found my after insert or update trigger wasn't working. After I disabled and enabled it, it started working again. I do not yet know why it stopped working. Is there any way to deal with ...
12
votes
3answers
2k views

Slow deletion of records when a trigger is enabled

Thought this was solved with the link below - the work around works - but the patch doesn't. Working with Microsoft support to resolve. http://support.microsoft.com/kb/2606883 Ok so I have an ...
1
vote
1answer
1k views

ADMINISTER DATABASE TRIGGER privilege

What does ADMINISTER DATABASE TRIGGER privilege actually mean? I have the following case: I have 2 databases: DB1 and DB2 On DB1 I have a trigger which arises after logon on database and checks if ...
3
votes
3answers
1k views

Trigger shouldn't block insert

I have a trigger on insert but if the trigger fails the insert fails too. is there a way to let the insert proceed even if the trigger fails? EDIT: I use a trigger to send a email when a new record ...
3
votes
1answer
5k views

Can mysqldump dump triggers and procedures?

Is there any way of making a mysqldump which will save all the triggers and procedures from a specified db? Some time ago I read that mysqldump will also save my triggers, but it doesn't look like ...
7
votes
2answers
4k views

Performance of a Trigger vs Stored Procedure in MySQL

A post here on DBA.StackExchange (What are the best practices for triggers to maintain a revision number on records?) has spawned an interesting question (at least, interesting to me) regarding ...
2
votes
3answers
2k views

What are the best practices for triggers to maintain a revision number on records?

I have an audit trail implemented on an application database that captures old value, new value, modification time, and user inserting it into another table. I'm now wanting to add a revision number ...
5
votes
7answers
436 views

Policies RE database triggers in well-designed applications?

I've heard all kinds of horror stories around gremlins living in database triggers, and--worse--systems being brought down by the addition of a trigger that caused a chain of cascading ones. I'm ...
1
vote
2answers
638 views

Are there any MySQL Triggers or Events that my program can wait for?

Say I want a live feed of emails on a web based email system. Emails are inserted into MySQL tables. Let's say I want my program to know immediately when the table is updated so it can check for new ...
7
votes
3answers
3k views

Wise to use trigger to update another table?

I have an Object table which is populated from an Integrated service (which I can change if needed) from another database. At certain points we need to manually add posts in another table ...
3
votes
3answers
410 views

How to determinate in a trigger direct inserts and inserts via stored procedure

TableX can be modified in two ways: client does "direct" inserts client uses stored procedure to inserts records How to determinate the way of client's call (direct or stored proc) in a trigger of ...
6
votes
2answers
2k views

Is it possible to get execution call stack in a trigger?

I have 10 stored procedures and each of them does INSERTs into one tableX. Is it possible in a trigger body of tableX to get what object causes modification of tableX (stored proc1 or sp2 or....) ? ...
2
votes
1answer
417 views

SQL Server Logon Trigger causing problems with the Distributed Transaction Coordinator

I've created the following simple logon trigger on my SQL Server 2005: CREATE TRIGGER LOGON_RESTRICTION ON ALL SERVER FOR LOGON AS BEGIN PRINT 'Hello World' END GO Which seems to be working fine ...
1
vote
1answer
6k views

store result set in temporary table, variable or separate variables within a trigger

I'm in the process of creating some triggers to store the the average rating for a given product on the product table. I've also been asked to store the total number of reviews for the product. So - I ...
3
votes
2answers
3k views

Using MySQL triggers or transactions?

I want to ask your opinion in using MySQL triggers or transactions in a website. Actually I have a history payment table with - UserId | OperationId | Comment | Credits | Sign (debit or credit). So ...
0
votes
1answer
136 views

Derived value not calculating as expected using combination of FK and Triggers (MySQL)

I'm having trouble with calculating a derived value using a combination of triggers and foreign key constraints. There are 3 tables involved in this arrangement responses ------------------------ ...
2
votes
2answers
2k views

DB2 Trigger: only update current row

I've created following trigger : CREATE TRIGGER probeer2 AFTER INSERT ON libtn01leb.kofax_release FOR EACH ROW UPDATE libtn01leb.kofax_release SET RRNR='bleh' This trigger will update EVERY ...
10
votes
2answers
3k views

Trigger: move deleted rows to archive table

I have a small (~10 rows) table called restrictions in my PostgreSQL database, where values are deleted and inserted on a daily basis. I would like to have a table called restrictions_deleted, where ...
4
votes
2answers
2k views

Trigger in MySQL

Please help me for few question in SQL.. I want to create the trigger which prevents insertion in the reservation table of flights (numflights), which does not exist. Tables ...
5
votes
1answer
179 views

In a Trigger, can I determine if a column was explicitly set to a values or not mentioned in update statement?

Given a Table with a column col1 like this: create table MyTest ( col1 int NULL, col2 decimal(7, 2) NULL ); insert into MyTest values ( 1, 1.1); Is there a way for a trigger for update to ...
7
votes
1answer
426 views

How can I rewrite for SQL Server a trigger that writing for Oracle?

How can I rewrite for SQL Server a trigger that was originally written for Oracle ? Here is my Oracle trigger code: CREATE OR REPLACE TRIGGER P000KUL_TEST BEFORE INSERT ON P000KUL REFERENCING NEW AS ...
5
votes
3answers
1k views

Alternatives to an INSERT Trigger

Looking for an example code in Oracle to do the same. i.e. Remove an insert trigger on table T1 whose job is to create a row in T2 based on the derived data. How would this PL-SQL api look like? ...
9
votes
4answers
11k views

How to detect any changes to a database (DDL and DML)

There are a lot of databases on my client's sql server. In common, these databases is under development, so developers can design, refactor, do data modifications and so on. There are some databases ...
9
votes
3answers
2k views

How to change the firing order of Triggers?

Realy I rarely use triggers. So I met a problem at first time. I have a lot of tables with triggers (2 or more for every table). I would like to know and change the order of firing triggers for every ...
7
votes
3answers
1k views

How to log data changes in Access at the table level?

I support an Access database for a non-profit organization. We have some issues with data mysteriously changing, and there been some, um, friendly debate over whether this is caused by users who are ...
19
votes
1answer
2k views

Is there a good way to run a trigger for each record in a postgres table?

I have a system where I can't control the design of some tables (replicated via Slony-I), and so I have a series of what we refer to as 'shadow tables', where I extract some information out of the ...