on 2018 Oct 16 1:10 PM
Hi,
Can I get information about the connection that fired the trigger ? Especially the connection name.
On an after update trigger can I get the name of the column(s) that are updated ?
Thanks in advence.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for you reply.
I try your method to know witch culomn is updated but it seems that the "If UPDATE(col) Then" works only if we pass the column name and not a variable with the column name.
I try that but it dont pass inside the IF :
FOR lpp AS ColCurs CURSOR FOR SELECT cname FROM sys.SYSCOLUMNS WHERE Creator = 'DBA' AND tname = 'CLI' DO SET wCol = cname; IF UPDATE(wCol) THEN SET wValAv = 'AV'; SET wValAp = 'Ap'; END IF; END FOR;
Hm, in my tests with 17.0.9.4857, I could avoid the syntax error but within a cursor loop, the UPDATE search condition does not seem to work properly.
Here's my attempt with a trigger on the sample database's Products table, with several debug messages within:
create or replace trigger TU_Products after update on GROUPO.Products referencing old as o new as n for each row begin message 'Trigger "TU_Products" fired' to log; for lpp as crs cursor for select column_name as @ColName from SYS.SYSTABCOL SC key join SYS.SYSTAB where creator = user_id('GROUPO') and table_name = 'Products' order by column_id for read only do message 'Trigger "TU_Products" checks whether column "' || @ColName || '" was modified.' to log; if update(@ColName) then message 'Trigger "TU_Products": Column "' || @ColName || '" was modified.' to log; end if; end for; if update(Quantity) then message 'Trigger "TU_Products": Column "' || 'Quantity' || '" was modified.' to log; end if; message 'Trigger "TU_Products" finished' to log; end; -- Update one row update Products set Quantity = Quantity - 1, UnitPrice = UnitPrice + 0.50 where ID = 300; -- display the last 11 log messages select msg_text from sa_server_messages(null, -11) order by msg_id;
The test shows the following output:
Trigger "TU_Products" fired Trigger "TU_Products" checks whether column "ID" was modified. Trigger "TU_Products" checks whether column "Name" was modified. Trigger "TU_Products" checks whether column "Description" was modified. Trigger "TU_Products" checks whether column "Size" was modified. Trigger "TU_Products" checks whether column "Color" was modified. Trigger "TU_Products" checks whether column "Quantity" was modified. Trigger "TU_Products" checks whether column "UnitPrice" was modified. Trigger "TU_Products" checks whether column "Photo" was modified. Trigger "TU_Products": Column "Quantity" was modified. Trigger "TU_Products" finished
Apparently, the "if update(@ColName)" test did not succeed for the "Quantity" column whereas the test via "if update(Quantity)" does - as does the test via the alternate syntax with "if updating('Quantity')".
User | Count |
---|---|
73 | |
10 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.