triggers

PL/SQL Trigger - Dynamically reference :NEW or :OLD

Is it possible to dynamically reference the :NEW/OLD pseudo records, or copy them? I'm doing a audit trigger for a very wide table, so would like to avoid having separate triggers for insert/delete/update. When updating/inserting I want to record the :NEW values in the audit table, when deleting I want to record the :OLD values. ...

MSSQL: What happens when an error occurs during trigger execution?

Regarding Update and Insert triggers for MS SQL Server, is there a way to make them atomic? In other words, if an error occurs during the trigger, is it possible to automatically roll back the original insert or update? ...

How can you tell if a trigger is enabled in PostgreSQL?

My googling-fu is failing me. How to know if a PostgreSQL trigger is disabled or not? ...

MySQL trigger : is it possible to delete rows if table become too large ?

Hi, When inserting a new row in a table T, I would like to check if the table is larger than a certain threshold, and if it is the case delete the oldest record (creating some kind of FIFO in the end). I thought I could simply make a trigger, but apparently MySQL doesn't allow the modification of the table on which we are actually inse...

Help with sql server trigger

Hi, I want to create a trigger that will update the column LastActivityDate to the current date when the Description column is updated, the problem is that all the rows are being updated, and I don't know how to make the where clause inside the trigger... I need to make a trigger like this for other tables as well, like the Votes table....

SQL Server 2005 - Trigger Loop?

I am using triggers for the first time. If I update a field in a table by an update trigger on the same table, with this spark a loop? Does sql server guard against this recursive behavior? Thanks ...

Is it true I can't edit a MySQL trigger, I have to drop it and create a new one?

Is it true I can't edit a MySQL trigger, I have to drop it and create a new one? Also, being a relative newcomer to triggers, it feels like they seem liable to causing 'erroneous' data. For example I might want a trigger to be fired (inserting data into another table) after one particular type of update query, but not others. Any tips ...

AFTER INSERT Trigger for SQL Server to create unique random 8 character code?

I started with some stored procedure code by Raymond Lewallen for a password generator. I would like to create a trigger that will create a unique 8 character ID each time a new row (a customer) is inserted. What I have so far: CREATE procedure dbo.AllAccessIDgenerator (
   @showID varchar(40) @accessID varchar(100) O...

Trigger to capture schema changes in the Server

Is it possible to implement something like the following trigger CREATE TRIGGER [tr_AU_ddl_All_Server] ON DATABASE WITH EXECUTE AS self FOR DDL_DATABASE_LEVEL_EVENTS AS DECLARE @data XML , @rc INT SET @data = EVENTDATA() EXEC @rc = __AU.dbo.AU_DDLLog @data GO BUT on the whole server. My idea is to cap...

Sql Trigger - which table does it belong to?

Is there a way within a Sql Server 2005 Trigger to get the name and schema of the table that the trigger is attached to during execution? ...

ListItem Mouse Enter Message Box

Hi, I am using event triggers in my XAML, I have the following style set on a ListItem. What I want is to display the contents of the ListItem in a message box when the mouse enters a list item. <Style.Triggers> <EventTrigger RoutedEvent="Mouse.MouseEnter"> </EventTrigger> </Style.Triggers> I ...

Mouse trigger not properly happening if html created through JQuery

Hi there, for this code: <div id="header">top of page</div> <div class="message">hello, how are you</div> <div class="message">I am fine</div> $(document).ready(function() { $("#header").append('<div class="message">appended DIV</div>'); $('div.message').hover( function() { alert('hi'); }, function() { alert('bye...

Getting trigger to fire conditionally (MySQL / PHP)

I want a trigger to fire only when UPDATEs are user-initiated (not me running updates from the MySQL command line). What's the 'industry standard' for achieving this? I have been trying unsuccessfully to detect a variable passed in with the query (i.e. @user_update=true), but without success. A colleague of mine suggested a way to do i...

maintain history in a database

I am designing this database that must maintain a history of employee salary and the movements within the organization. Basically, my design has 3 tables (I mean, there more tables but for this question I'll mention 3, so bear with me). Employee table (containing the most current salary, position data, etc), SalaryHistory table (salary, ...

Getting trigger to insert changed column values only in audit table

I'm using a trigger to store changes in an audit table, I only want to store the values from columns that have been changed. BEGIN IF NEW.history_of_repair_trigger_fired = 1 THEN INSERT INTO history_of_repair SET edit_date_time=NEW.last_edited_date_time, edited_by=NEW.edited_by, repair_id=NEW.repair_id, tenant_name=NEW.tenant_name, prop...

Insert Update trigger how to determine if insert or update

I need to write an Insert, Update Trigger on table A which will delete all rows from table B whose one column (say Desc) has values like the value inserted/updated in the table A's column (say Col1). How would I go around writing it so that I can handle both Update and Insert cases. How would I determine if the trigger is executed for an...

Trigger based history

What I am trying to do is find out which fields were updated and record the change to a different table. DECLARE @BillNo int, @column_name varchar(500) SELECT @BillNo = BillNo FROM INSERTED DECLARE HistoryMonitorLoop CURSOR FOR SELECT column_name FROM information_schema.columns WHERE ...

What is the best way to handle this constraint in SQL Server 2005?

I have SMS based survey application which takes in a survey domain, and a answer. I've gotten requests for detailed DDL, so.... The database looks like this SurveyAnswer.Answer must be unique within all active Surveys for that SurveyDomain. In SQL terms, this should always return 0..1 rows: select * from survey s, surveyanswer sa wh...

T-SQL - Select records into concatenated text?

I'm trying to investigate when & why certain rows are getting deleted in a SQL 2005 database. I've started building a trigger to log some information when a row is deleted. My trigger is activated when row(s) are deleted from a certain table. I have it set up to log a timestamp in another logging table when the delete occurs. I'd also l...

Most compatible way to listen for database changes?

I have a process that reads raw data and writes this to a database every few seconds. What is the best way to tell if the database has been written to? I know that Oracle and MS-SQL can use triggers or something to communicate with other services, but I was hoping there would be a technique that would work with more types of SQL databas...