<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Why triggers are evil when they try to get fancy</title>
	<atom:link href="http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/feed/" rel="self" type="application/rss+xml" />
	<link>http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/</link>
	<description>Oracle Question and Answer</description>
	<lastBuildDate>Tue, 06 Jul 2010 14:28:12 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Eddie Awad</title>
		<link>http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/comment-page-1/#comment-148</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Tue, 28 Feb 2006 18:23:24 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/#comment-148</guid>
		<description>Thanks Tom. I have changed the title and added your warning, as well as a direct link to your comment, at the top of this post.</description>
		<content:encoded><![CDATA[<p>Thanks Tom. I have changed the title and added your warning, as well as a direct link to your comment, at the top of this post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tkyte</title>
		<link>http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/comment-page-1/#comment-147</link>
		<dc:creator>tkyte</dc:creator>
		<pubDate>Tue, 28 Feb 2006 17:16:21 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/#comment-147</guid>
		<description>&lt;B&gt;THIS TIP IS VERY DANGEROUS - DO NOT IMPLEMENT THIS IN REAL LIFE - THIS WILL DAMAGE YOUR DATA&lt;/b&gt;

The update cascade someone referenced you to on my page is horribly complex - but only because it has to be.  This is a non-trivial operation.  This trigger will damage data.

ops$tkyte@ORA10GR2&gt; create table p (x number primary key);
Table created.
 
ops$tkyte@ORA10GR2&gt; create table c (y references p deferrable initially deferred);
Table created.
 
ops$tkyte@ORA10GR2&gt; insert into p(x) values (1);
1 row created.
 
ops$tkyte@ORA10GR2&gt; insert into p(x) values (2);
1 row created.
 
ops$tkyte@ORA10GR2&gt; insert into c(y) values (1);
1 row created.
 
ops$tkyte@ORA10GR2&gt; insert into c(y) values (2);
1 row created.
 
ops$tkyte@ORA10GR2&gt; commit;
Commit complete.
 
ops$tkyte@ORA10GR2&gt; create or replace trigger upd_cascade
  2  before update on p
  3  for each row
  4  begin
  5   dbms_output.put_line( &#039;turning &#039; &#124;&#124; :old.x &#124;&#124; &#039; into &#039; &#124;&#124; :new.x );
  6   update c set y=:new.x where y=:old.x;
  7  end;
  8  /
Trigger created.
 
ops$tkyte@ORA10GR2&gt; select * from p;
 
         X
----------
         1
         2
 
ops$tkyte@ORA10GR2&gt; select * from c;
 
         Y
----------
         1
         2
 
ops$tkyte@ORA10GR2&gt; update p set x = x+1;
turning 1 into 2
turning 2 into 3
 
2 rows updated.
 
ops$tkyte@ORA10GR2&gt; select * from p;
 
         X
----------
         2
         3
 
ops$tkyte@ORA10GR2&gt; select * from c;
 
         Y
----------
         3
         3
 
ops$tkyte@ORA10GR2&gt; commit;
 
Commit complete.

&lt;B&gt;The trigger is very dependent on the order the rows in P accidently get processed in!!!! It is totally non-deterministic and corrupts data!!!  See how both Y&#039;s in C end up being 3??? Equally possible would be for the &quot;right&quot; answer to happen if the rows in P are processed differently.  And if there are more than two rows being updated - ugh - think about the implications of multi-row updates

I strongly encourage you to consider withdrawing this tip from publication - or to turn it into a tip that shows why triggers are evil when they try to get fancy&lt;/b&gt;</description>
		<content:encoded><![CDATA[<p><b>THIS TIP IS VERY DANGEROUS &#8211; DO NOT IMPLEMENT THIS IN REAL LIFE &#8211; THIS WILL DAMAGE YOUR DATA</b></p>
<p>The update cascade someone referenced you to on my page is horribly complex &#8211; but only because it has to be.  This is a non-trivial operation.  This trigger will damage data.</p>
<p>ops$tkyte@ORA10GR2&gt; create table p (x number primary key);<br />
Table created.</p>
<p>ops$tkyte@ORA10GR2&gt; create table c (y references p deferrable initially deferred);<br />
Table created.</p>
<p>ops$tkyte@ORA10GR2&gt; insert into p(x) values (1);<br />
1 row created.</p>
<p>ops$tkyte@ORA10GR2&gt; insert into p(x) values (2);<br />
1 row created.</p>
<p>ops$tkyte@ORA10GR2&gt; insert into c(y) values (1);<br />
1 row created.</p>
<p>ops$tkyte@ORA10GR2&gt; insert into c(y) values (2);<br />
1 row created.</p>
<p>ops$tkyte@ORA10GR2&gt; commit;<br />
Commit complete.</p>
<p>ops$tkyte@ORA10GR2&gt; create or replace trigger upd_cascade<br />
  2  before update on p<br />
  3  for each row<br />
  4  begin<br />
  5   dbms_output.put_line( &#8216;turning &#8216; || :old.x || &#8216; into &#8216; || :new.x );<br />
  6   update c set y=:new.x where y=:old.x;<br />
  7  end;<br />
  8  /<br />
Trigger created.</p>
<p>ops$tkyte@ORA10GR2&gt; select * from p;</p>
<p>         X<br />
&#8212;&#8212;&#8212;-<br />
         1<br />
         2</p>
<p>ops$tkyte@ORA10GR2&gt; select * from c;</p>
<p>         Y<br />
&#8212;&#8212;&#8212;-<br />
         1<br />
         2</p>
<p>ops$tkyte@ORA10GR2&gt; update p set x = x+1;<br />
turning 1 into 2<br />
turning 2 into 3</p>
<p>2 rows updated.</p>
<p>ops$tkyte@ORA10GR2&gt; select * from p;</p>
<p>         X<br />
&#8212;&#8212;&#8212;-<br />
         2<br />
         3</p>
<p>ops$tkyte@ORA10GR2&gt; select * from c;</p>
<p>         Y<br />
&#8212;&#8212;&#8212;-<br />
         3<br />
         3</p>
<p>ops$tkyte@ORA10GR2&gt; commit;</p>
<p>Commit complete.</p>
<p><b>The trigger is very dependent on the order the rows in P accidently get processed in!!!! It is totally non-deterministic and corrupts data!!!  See how both Y&#8217;s in C end up being 3??? Equally possible would be for the &#8220;right&#8221; answer to happen if the rows in P are processed differently.  And if there are more than two rows being updated &#8211; ugh &#8211; think about the implications of multi-row updates</p>
<p>I strongly encourage you to consider withdrawing this tip from publication &#8211; or to turn it into a tip that shows why triggers are evil when they try to get fancy</b></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Claudiu Ariton</title>
		<link>http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/comment-page-1/#comment-133</link>
		<dc:creator>Claudiu Ariton</dc:creator>
		<pubDate>Tue, 14 Feb 2006 07:38:43 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/#comment-133</guid>
		<description>Hello Karl, Jkstill, Austrin

 I&#039;ll keep in mind your opinion in the future.
 
 My scope was to create an example to demonstrate the deferrable constraint concept, not to create misunderstandings.

 Thank you for understanding,
 Claudiu Ariton</description>
		<content:encoded><![CDATA[<p>Hello Karl, Jkstill, Austrin</p>
<p> I&#8217;ll keep in mind your opinion in the future.</p>
<p> My scope was to create an example to demonstrate the deferrable constraint concept, not to create misunderstandings.</p>
<p> Thank you for understanding,<br />
 Claudiu Ariton</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: austrin</title>
		<link>http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/comment-page-1/#comment-131</link>
		<dc:creator>austrin</dc:creator>
		<pubDate>Tue, 14 Feb 2006 07:06:28 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/#comment-131</guid>
		<description>Hello Claudiu,
just a hint to the thoughts Tom Kyte had on this topic: &lt;a href=&quot;http://asktom.oracle.com/~tkyte/update_cascade/index.html&quot; title=&quot;link tkyte&quot; rel=&quot;nofollow&quot;&gt; http://asktom.oracle.com/~tkyte/update_cascade/index.html &lt;/a&gt;
BR,
Martin</description>
		<content:encoded><![CDATA[<p>Hello Claudiu,<br />
just a hint to the thoughts Tom Kyte had on this topic: <a href="http://asktom.oracle.com/~tkyte/update_cascade/index.html" title="link tkyte" rel="nofollow"> </a><a href="http://asktom.oracle.com/~tkyte/update_cascade/index.html" rel="nofollow">http://asktom.oracle.com/~tkyte/update_cascade/index.html</a><br />
BR,<br />
Martin</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Reitschuster</title>
		<link>http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/comment-page-1/#comment-129</link>
		<dc:creator>Karl Reitschuster</dc:creator>
		<pubDate>Tue, 14 Feb 2006 06:26:08 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/#comment-129</guid>
		<description>Hi Claudio,
if you would give a little intro to your code next time we would better understand the background you want to target. Thanks for posting!

Karl</description>
		<content:encoded><![CDATA[<p>Hi Claudio,<br />
if you would give a little intro to your code next time we would better understand the background you want to target. Thanks for posting!</p>
<p>Karl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jkstill</title>
		<link>http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/comment-page-1/#comment-127</link>
		<dc:creator>jkstill</dc:creator>
		<pubDate>Mon, 13 Feb 2006 20:05:30 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/#comment-127</guid>
		<description>We are approaching this from different perspectives.

You are approaching from the perspective of maintaining a legacy app, which sometimes requires us to do things we would rather not do.

I was thinking in terms of designing a new schema, where there is more flexibility.</description>
		<content:encoded><![CDATA[<p>We are approaching this from different perspectives.</p>
<p>You are approaching from the perspective of maintaining a legacy app, which sometimes requires us to do things we would rather not do.</p>
<p>I was thinking in terms of designing a new schema, where there is more flexibility.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Claudiu Ariton</title>
		<link>http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/comment-page-1/#comment-126</link>
		<dc:creator>Claudiu Ariton</dc:creator>
		<pubDate>Mon, 13 Feb 2006 20:01:31 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/#comment-126</guid>
		<description>I am totally agree with you.
 But what are you doing in case of an old bad third party system with wrong meaningful PK (eg: Cities table with city_name as PK).
 You can buy another system but what are the cost?
 This solution is just only a compromis and it is useful for unlucky people from support side.

 Best regards,
 Claudiu Ariton</description>
		<content:encoded><![CDATA[<p>I am totally agree with you.<br />
 But what are you doing in case of an old bad third party system with wrong meaningful PK (eg: Cities table with city_name as PK).<br />
 You can buy another system but what are the cost?<br />
 This solution is just only a compromis and it is useful for unlucky people from support side.</p>
<p> Best regards,<br />
 Claudiu Ariton</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jkstill</title>
		<link>http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/comment-page-1/#comment-125</link>
		<dc:creator>jkstill</dc:creator>
		<pubDate>Mon, 13 Feb 2006 19:32:42 +0000</pubDate>
		<guid isPermaLink="false">http://oraqa.com/2006/02/13/how-to-create-on-update-cascade-constraint/#comment-125</guid>
		<description>I&#039;m curious why you would want to do this?
Updating PK is generally considered a bad idea.

UPDATE CASCADE would have potentially large performance implications, much as DELETE CASCADE does.</description>
		<content:encoded><![CDATA[<p>I&#8217;m curious why you would want to do this?<br />
Updating PK is generally considered a bad idea.</p>
<p>UPDATE CASCADE would have potentially large performance implications, much as DELETE CASCADE does.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
