MariaDB backend (but could be SQL Server too)
Given this trigger: UPDATE MyTable SET cItemID = new.cID WHERE cItemID = old.cID
My question: will this trigger fire even if the old.cID = new.cID? Or do I need to add to the WHERE clause something like "....and old.cID <> new.cID"
???
tia, --Mike
To me this is a trigger that will update a date column with the current datetime. Your example could see the where clause below that finds the row that is either just created or just updated. You can't be changing the column that is a part of the where clause.
CREATE TRIGGER dbo.MyTable_UpdatedON dbo.Table1FOR INSERT, UPDATE /* Fire this trigger when a row is INSERTed or UPDATEd */AS BEGIN UPDATE dbo.Table1 SET dbo.Table1.LastUpdated = GETDATE() FROM INSERTED WHERE inserted.id=Table1.idEND
On Tue, Aug 15, 2017 at 10:06 PM, < mbsoftwaresolutions@mbsoftwaresolutions.com> wrote:
MariaDB backend (but could be SQL Server too)
Given this trigger: UPDATE MyTable SET cItemID = new.cID WHERE cItemID = old.cID
My question: will this trigger fire even if the old.cID = new.cID? Or do I need to add to the WHERE clause something like "....and old.cID <> new.cID"
???
tia, --Mike
[excessive quoting removed by server]
On 2017-08-15 23:06, mbsoftwaresolutions@mbsoftwaresolutions.com wrote:
MariaDB backend (but could be SQL Server too)
Given this trigger: UPDATE MyTable SET cItemID = new.cID WHERE cItemID = old.cID
My question: will this trigger fire even if the old.cID = new.cID? Or do I need to add to the WHERE clause something like "....and old.cID <> new.cID"
My testing seems to indicate that I need to add the extra condition. Makes total sense on re-thought. These triggers fire on just the action, regardless of true change.
Mike, You are correct in your assumption and you DO need to add the where clause.
Dave
-----Original Message----- From: ProFox [mailto:profox-bounces@leafe.com] On Behalf Of mbsoftwaresolutions@mbsoftwaresolutions.com Sent: 16 August 2017 04:07 To: ProFox profox@leafe.com Subject: [NF] Trigger question
MariaDB backend (but could be SQL Server too)
Given this trigger: UPDATE MyTable SET cItemID = new.cID WHERE cItemID = old.cID
My question: will this trigger fire even if the old.cID = new.cID? Or do I need to add to the WHERE clause something like "....and old.cID <> new.cID"
???
tia, --Mike
[excessive quoting removed by server]