If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > What is difference between 'row' and 'statement' in trigger action

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-04-05, 02:21
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
What is difference between 'row' and 'statement' in trigger action

Hi,

What is difference between "for each row" and "for each statement" in trigger action after insert.

My system: db2 v8.1fp6 on win2000

Thanks,
Grofaty
Reply With Quote
  #2 (permalink)  
Old 03-04-05, 03:06
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
If you issue a multi-row INSERT statement, the 'each statement' trigger is invoked only once whereas a "each row" trigger is invoked for every row ..

Eg of a multi-row INSERT
insert into tab1 values(2,2),(3,3)
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 03-04-05, 03:37
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

Thanks. What about if SQL is written like this:
1. INSERT INTO schema.tab1 SELECT * FROM schema.tab2
or like this:
2. UPDATE schema.tab1 WHERE value = value (I would like to involke trigger on whole table)

My question: how many times is trigger fired out if ROW or STATEMENT is used in trigger for query 1 and query 2.

Thanks,
Grofaty
Reply With Quote
  #4 (permalink)  
Old 03-04-05, 07:42
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

I have noticed that 'for statement' works 100-times faster then 'for row'.
I am still interested in above questions.

Thanks,
Grofaty
Reply With Quote
  #5 (permalink)  
Old 03-04-05, 08:16
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Grofaty,
For statement 1, a trigger with STATEMENT will execute only once, while a trigger with ROW will execute SELECT count(*) FROM schema.tab2 times.

Similiarly for statement 2, a trigger with STATEMENT will execute only once, while one with ROW will execute select count(*) from schema.tab1 WHERE value = value

HTH

Andy
Reply With Quote
  #6 (permalink)  
Old 03-07-05, 01:29
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

arwinner: thanks a lot. 'With ROW' is 100-times slower. What is the benefit of using 'with ROW' option? When must be 'with ROW' used instread of 'with STATEMENT'.

Grofaty
Reply With Quote
  #7 (permalink)  
Old 03-07-05, 02:03
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
There is no hard and fast rule ... it depends on the business requirement rather than technical ...

For eg, consider and UPDATE trigger ... If the business requirement is to log before image of each row along with the update timestamp, then you will have to use ROW .. But, if the requirement is to just log the time when a table is updated, then use the STATEMENT

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #8 (permalink)  
Old 03-07-05, 03:49
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

Thanks to you all.

Grofaty
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On