<?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"
	>
<channel>
	<title>Comments on: To Insert or To&#160;Update</title>
	<atom:link href="http://particletree.com/notebook/to-insert-or-to-update/feed/" rel="self" type="application/rss+xml" />
	<link>http://particletree.com/notebook/to-insert-or-to-update/</link>
	<description>Everyone needs a hug.</description>
	<pubDate>Wed, 08 Oct 2008 06:08:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: JayantB</title>
		<link>http://particletree.com/notebook/to-insert-or-to-update/#comment-24248</link>
		<dc:creator>JayantB</dc:creator>
		<pubDate>Sat, 13 Oct 2007 19:04:05 +0000</pubDate>
		<guid isPermaLink="false">http://particletree.com/notebook/to-insert-or-to-update/#comment-24248</guid>
		<description>&lt;p&gt;I have following table&lt;/p&gt;

&lt;p&gt;Product&lt;/p&gt;

&lt;p&gt;ProductID   ProductRangeID  ProductName Desc    StatusFlag&lt;/p&gt;

&lt;p&gt;1   1       Metal       abc I&lt;/p&gt;

&lt;p&gt;2   2       Wood                    xyz I&lt;/p&gt;

&lt;p&gt;3   3       JDB     pqr I&lt;/p&gt;

&lt;p&gt;4              1                              OM                            XXX          I&lt;/p&gt;

&lt;p&gt;5              2                              Shiv                           KKK           I&lt;/p&gt;

&lt;p&gt;I need to check Duplicate ProductName against same ProductRangeID before Inserting and Updating the values
I want to Insert and update values in single procedure&lt;/p&gt;

&lt;p&gt;How I can Do it???
please help??&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I have following table</p>

<p>Product</p>

<p>ProductID   ProductRangeID  ProductName Desc    StatusFlag</p>

<p>1   1       Metal       abc I</p>

<p>2   2       Wood                    xyz I</p>

<p>3   3       JDB     pqr I</p>

<p>4              1                              OM                            XXX          I</p>

<p>5              2                              Shiv                           KKK           I</p>

<p>I need to check Duplicate ProductName against same ProductRangeID before Inserting and Updating the values
I want to Insert and update values in single procedure</p>

<p>How I can Do it???
please help??</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Greg Jorgensen</title>
		<link>http://particletree.com/notebook/to-insert-or-to-update/#comment-24204</link>
		<dc:creator>Greg Jorgensen</dc:creator>
		<pubDate>Mon, 08 Oct 2007 06:09:29 +0000</pubDate>
		<guid isPermaLink="false">http://particletree.com/notebook/to-insert-or-to-update/#comment-24204</guid>
		<description>&lt;p&gt;MySQL has the non-standard ON DUPLICATE KEY and the (dangerous) REPLACE statement. If you are using some other RDBMS, or you want to steer clear of MySQL quirks, just try whatever is least likely to fail (INSERT or UPDATE) and if it fails do the other. Whether you do a SELECT first, try to INSERT a duplicate primary key, or try to UPDATE a non-existent row the RDBMS does exactly the same amount of work: it scans the primary key index to see if the key you are looking for is in the index.&lt;/p&gt;

&lt;p&gt;If you have a table that is frequently updated, just do the UPDATE, then check the number of affected rows. If zero rows were updated do the INSERT. Likewise if the rows in your table are usually not updated after they are inserted do the INSERT, and if it fails (check the number of rows again) do an UPDATE.&lt;/p&gt;

&lt;p&gt;You can also just DELETE before INSERTING if your UPDATE will affect all columns anyway. The DELETE won't do anything if there's no matching row. Remember to put the DELETE and INSERT inside a transaction.&lt;/p&gt;

&lt;p&gt;SQL operations don't blow up or corrupt the database if they fail, and they don't crash your application or throw and exception. Just look at the number of affected rows to see if your INSERT, UPDATE, or DELETE did anything or not.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>MySQL has the non-standard ON DUPLICATE KEY and the (dangerous) REPLACE statement. If you are using some other RDBMS, or you want to steer clear of MySQL quirks, just try whatever is least likely to fail (INSERT or UPDATE) and if it fails do the other. Whether you do a SELECT first, try to INSERT a duplicate primary key, or try to UPDATE a non-existent row the RDBMS does exactly the same amount of work: it scans the primary key index to see if the key you are looking for is in the index.</p>

<p>If you have a table that is frequently updated, just do the UPDATE, then check the number of affected rows. If zero rows were updated do the INSERT. Likewise if the rows in your table are usually not updated after they are inserted do the INSERT, and if it fails (check the number of rows again) do an UPDATE.</p>

<p>You can also just DELETE before INSERTING if your UPDATE will affect all columns anyway. The DELETE won&#8217;t do anything if there&#8217;s no matching row. Remember to put the DELETE and INSERT inside a transaction.</p>

<p>SQL operations don&#8217;t blow up or corrupt the database if they fail, and they don&#8217;t crash your application or throw and exception. Just look at the number of affected rows to see if your INSERT, UPDATE, or DELETE did anything or not.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Blomus</title>
		<link>http://particletree.com/notebook/to-insert-or-to-update/#comment-24124</link>
		<dc:creator>Blomus</dc:creator>
		<pubDate>Mon, 01 Oct 2007 05:07:34 +0000</pubDate>
		<guid isPermaLink="false">http://particletree.com/notebook/to-insert-or-to-update/#comment-24124</guid>
		<description>&lt;p&gt;It is very useful.
Thank you for posting Ryan&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>It is very useful.
Thank you for posting Ryan</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Sridhar</title>
		<link>http://particletree.com/notebook/to-insert-or-to-update/#comment-24119</link>
		<dc:creator>Sridhar</dc:creator>
		<pubDate>Sun, 30 Sep 2007 06:20:31 +0000</pubDate>
		<guid isPermaLink="false">http://particletree.com/notebook/to-insert-or-to-update/#comment-24119</guid>
		<description>&lt;p&gt;i second Alan Wallace's comment. Thanks for posting Ryan.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>i second Alan Wallace&#8217;s comment. Thanks for posting Ryan.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Murtaza</title>
		<link>http://particletree.com/notebook/to-insert-or-to-update/#comment-24110</link>
		<dc:creator>Murtaza</dc:creator>
		<pubDate>Sat, 29 Sep 2007 09:58:26 +0000</pubDate>
		<guid isPermaLink="false">http://particletree.com/notebook/to-insert-or-to-update/#comment-24110</guid>
		<description>&lt;p&gt;A very helpful indeed. Thanks for posting Ryan&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>A very helpful indeed. Thanks for posting Ryan</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Aron</title>
		<link>http://particletree.com/notebook/to-insert-or-to-update/#comment-24086</link>
		<dc:creator>Aron</dc:creator>
		<pubDate>Fri, 28 Sep 2007 10:13:07 +0000</pubDate>
		<guid isPermaLink="false">http://particletree.com/notebook/to-insert-or-to-update/#comment-24086</guid>
		<description>&lt;p&gt;For as far as I know, REPLACE INTO deletes the existing record and inserts a new one, when a duplicate key is found.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>For as far as I know, REPLACE INTO deletes the existing record and inserts a new one, when a duplicate key is found.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Harmen Janssen</title>
		<link>http://particletree.com/notebook/to-insert-or-to-update/#comment-24085</link>
		<dc:creator>Harmen Janssen</dc:creator>
		<pubDate>Fri, 28 Sep 2007 09:40:36 +0000</pubDate>
		<guid isPermaLink="false">http://particletree.com/notebook/to-insert-or-to-update/#comment-24085</guid>
		<description>&lt;p&gt;A very helpful post, thanks for this little gem.
This'll certainly unclutter some of my code.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>A very helpful post, thanks for this little gem.
This&#8217;ll certainly unclutter some of my code.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Rahul</title>
		<link>http://particletree.com/notebook/to-insert-or-to-update/#comment-24079</link>
		<dc:creator>Rahul</dc:creator>
		<pubDate>Thu, 27 Sep 2007 19:48:39 +0000</pubDate>
		<guid isPermaLink="false">http://particletree.com/notebook/to-insert-or-to-update/#comment-24079</guid>
		<description>&lt;p&gt;Ever heard of REPLACE INTO?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Ever heard of REPLACE INTO?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Alan Wallace</title>
		<link>http://particletree.com/notebook/to-insert-or-to-update/#comment-24078</link>
		<dc:creator>Alan Wallace</dc:creator>
		<pubDate>Thu, 27 Sep 2007 19:31:12 +0000</pubDate>
		<guid isPermaLink="false">http://particletree.com/notebook/to-insert-or-to-update/#comment-24078</guid>
		<description>&lt;p&gt;Love these short helpful posts. I've been doing this in the way of the first example, will be glad to remove some more cludge from my code.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Love these short helpful posts. I&#8217;ve been doing this in the way of the first example, will be glad to remove some more cludge from my code.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Campbell</title>
		<link>http://particletree.com/notebook/to-insert-or-to-update/#comment-24076</link>
		<dc:creator>Ryan Campbell</dc:creator>
		<pubDate>Thu, 27 Sep 2007 18:39:16 +0000</pubDate>
		<guid isPermaLink="false">http://particletree.com/notebook/to-insert-or-to-update/#comment-24076</guid>
		<description>&lt;p&gt;I believe that has been fixed. The last comment says it has, but I have also read a few blog posts where people claim that they have noticed a speed increase with replication using this technique. I haven't tested myself though, so I can't confirm.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I believe that has been fixed. The last comment says it has, but I have also read a few blog posts where people claim that they have noticed a speed increase with replication using this technique. I haven&#8217;t tested myself though, so I can&#8217;t confirm.</p>]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.322 seconds -->
