﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / Data Corruption  / UPDATE statement that creates duplicate records / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 18 Jun 2013 16:46:47 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: UPDATE statement that creates duplicate records</title><link>http://www.sqlservercentral.com/Forums/Topic523395-266-1.aspx</link><description>I actually verified that there were duplicates. The row count was unexpected. So I followd up with a query checking for duplicates - you know - with a GROUP BY clause on the key and a HAVING COUNT(*) &amp;gt; 1 clause.</description><pubDate>Fri, 27 Jun 2008 06:03:43 GMT</pubDate><dc:creator>Bill Nicolich</dc:creator></item><item><title>RE: UPDATE statement that creates duplicate records</title><link>http://www.sqlservercentral.com/Forums/Topic523395-266-1.aspx</link><description>No triggers on table B.</description><pubDate>Fri, 27 Jun 2008 06:01:24 GMT</pubDate><dc:creator>Bill Nicolich</dc:creator></item><item><title>RE: UPDATE statement that creates duplicate records</title><link>http://www.sqlservercentral.com/Forums/Topic523395-266-1.aspx</link><description>Have you got any triggers on Table B?</description><pubDate>Fri, 27 Jun 2008 01:16:20 GMT</pubDate><dc:creator>Ian Scarlett</dc:creator></item><item><title>RE: UPDATE statement that creates duplicate records</title><link>http://www.sqlservercentral.com/Forums/Topic523395-266-1.aspx</link><description>I think I see a dual triangular join between Deleted and Inserted and that might give you a funky rowcount... but I don't see anything in that code that would even come close to insert rows...What makes you thing the rows in TableB where duplicated?  Did you do a before and after dupe check or are you just looking at row counts?</description><pubDate>Thu, 26 Jun 2008 21:40:33 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: UPDATE statement that creates duplicate records</title><link>http://www.sqlservercentral.com/Forums/Topic523395-266-1.aspx</link><description> Trigger Code (object names changed for anonymity):CREATE   TRIGGER u_PartInformation ON PartInformation FOR UPDATE AS-- Propagate updates to description fields.IF UPDATE(part_num) OR UPDATE(headline_id) OR UPDATE(epd) OR UPDATE(catalog) OR UPDATE(color) OR UPDATE(application) OR UPDATE(short_desc) OR UPDATE(additional_info)BEGIN                UPDATE [search].dbo.[ProductSearch]                SET [search].dbo.[ProductSearch].[description] =                 ISNULL(ltrim(rtrim(i.part_num)),'') + ' ' +                SUBSTRING(LTRIM(RTRIM(ISNULL(i.catalog,''))),3,LEN(LTRIM(RTRIM(ISNULL(i.catalog,''))))-2) + ' ' +                SUBSTRING(LTRIM(RTRIM(ISNULL(b.[main_section],''))),4,46) + ' ' +                SUBSTRING(LTRIM(RTRIM(ISNULL(c.[sub_section],''))),4,46) + ' ' +                LTRIM(RTRIM(ISNULL(d.headline,''))) + ' ' +                 LTRIM(RTRIM(ISNULL(i.color,''))) + ' ' +                LTRIM(RTRIM(ISNULL(i.application,''))) + ' ' +                LTRIM(RTRIM(ISNULL(i.short_desc,''))) + ' ' +                LTRIM(RTRIM(ISNULL(e.long_desc,''))) + ' ' +                LTRIM(RTRIM(ISNULL(i.additional_info,''))),                [search].dbo.[ProductSearch].[part_num] = i.part_num,                [search].dbo.[ProductSearch].[headline_id] = i.headline_id,                [search].dbo.[ProductSearch].[edp] = i.epd                FROM                 deleted, inserted i                LEFT OUTER JOIN main_section b                 ON LTRIM(RTRIM(i.[main_section_id])) = LTRIM(RTRIM(b.[main_section_id]))                LEFT OUTER JOIN [sub_section] c                ON LTRIM(RTRIM(i.[sub_section_id])) = LTRIM(RTRIM(c.[sub_section_id]))                LEFT OUTER JOIN [headline] d                ON LTRIM(RTRIM(i.[headline_id]))= LTRIM(RTRIM(d.[headline_id]))                LEFT OUTER JOIN [long_description] e                ON LTRIM(RTRIM(i.[long_desc_id])) = LTRIM(RTRIM(CAST(e.[long_desc_id] AS VARCHAR(8))))                WHERE                 [search].dbo.[ProductSearch].part_num = i.part_num and [search].dbo.[ProductSearch].edp = i.epd                AND (                deleted.[catalog] &amp;lt;&amp;gt; i.[catalog]                OR deleted.[color] &amp;lt;&amp;gt; i.[color]                OR deleted.[application] &amp;lt;&amp;gt; i.[application]                OR deleted.[short_desc] &amp;lt;&amp;gt; i.[short_desc]                OR deleted.[additional_info] &amp;lt;&amp;gt; i.[additional_info]                OR deleted.[part_num] &amp;lt;&amp;gt; i.[part_num]                OR deleted.[headline_id] &amp;lt;&amp;gt; i.[headline_id]                OR deleted.[epd] &amp;lt;&amp;gt; i.[epd]                )END </description><pubDate>Thu, 26 Jun 2008 08:43:01 GMT</pubDate><dc:creator>Bill Nicolich</dc:creator></item><item><title>RE: UPDATE statement that creates duplicate records</title><link>http://www.sqlservercentral.com/Forums/Topic523395-266-1.aspx</link><description>[font="Verdana"]Hi Bill,Can you provide the trigger code here?[/font]</description><pubDate>Wed, 25 Jun 2008 23:43:18 GMT</pubDate><dc:creator>vidhya sagar</dc:creator></item><item><title>UPDATE statement that creates duplicate records</title><link>http://www.sqlservercentral.com/Forums/Topic523395-266-1.aspx</link><description>Help! An UPDATE query seems to have inserted records into the target table in SQL Server 2000. Has anyone seen this before? I thought UPDATE statements only change current records – not add records.I set up a trigger on the UPDATE operation for a table A. Within the trigger, I issue an UPDATE statement so that any updates on certain fields will propagate to another related table B. The trigger fired upon the UPDATE operation on table A. The related table B got all of its records duplicated.I’m wondering if anyone has some useful information based on this general description. If more detail is needed, I can add that.</description><pubDate>Wed, 25 Jun 2008 08:17:21 GMT</pubDate><dc:creator>Bill Nicolich</dc:creator></item></channel></rss>