﻿<?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 / T-SQL (SS2K5)  / Update statement / 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, 21 May 2013 19:39:59 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Update statement</title><link>http://www.sqlservercentral.com/Forums/Topic559432-338-1.aspx</link><description>I would appreciate any suggestions. Thanks!</description><pubDate>Thu, 28 Aug 2008 23:32:36 GMT</pubDate><dc:creator>rajankjohn</dc:creator></item><item><title>RE: Update statement</title><link>http://www.sqlservercentral.com/Forums/Topic559432-338-1.aspx</link><description>Say, I had a wide Users table with 150+ columns. I split that to Users1 and Users2. If I have to update the name column in Users1 with a condition on UserType on Usrs2 table, what I will be doing is as follows -update U1 set U1.Name = 'Sam'from Usrs1 U1 join Usrs2 U2on U1.UserId = U2.UserIdand U2.Type = 'Regular'amd U1.UserId = '101'Is there a way that is better on a performance front?</description><pubDate>Wed, 27 Aug 2008 08:15:38 GMT</pubDate><dc:creator>rajankjohn</dc:creator></item><item><title>RE: Update statement</title><link>http://www.sqlservercentral.com/Forums/Topic559432-338-1.aspx</link><description>[quote][b]Rajan John (8/27/2008)[/b][hr]For such scenarios, I also do the updates with a join only. I would be interested to see whether this approach has any performance implications, and what are other recommended ways?[/quote]While the TSQL update statement can be useful it has the potential problem of not thowing an error if there are multiple results when you were expecting a single result. In this case an employee could have multiple passports so, as there is no guarantee that the last passport will be returned last, the employee row could have the passportcode of an expired passport. Someone should at least ask the question of whether this matters before the TSQL JOIN sysntax is used. If you are expecting Passport.EmployeeId to be unique it could be argued that an UNIQUE constraint on Passport.EmployeeId would solve the problem but can you really rely on that constraint not being removed sometime? In this case I would be inclined to use the ANSI update syntax so that an error would be thrown if the data was not as expected. The performance may be worse than the TSQL JOIN syntax. eg:[code][color="blue"]UPDATE[/color] Employee[color="blue"]SET[/color] passportcocde =[color="gray"]([/color]&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp[color="blue"]SELECT[/color] P.passportcode&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp[color="blue"]FROM[/color] Passport P&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp[color="blue"]WHERE[/color] P.EmployeeId = Employee.EmployeeId[color="gray"])[/color][color="blue"]WHERE[/color] [color="gray"]EXISTS[/color][color="gray"]([/color]&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp[color="blue"]SELECT[/color] *&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp[color="blue"]FROM[/color] Passport P1&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp[color="blue"]WHERE[/color] P1.EmployeeId = Employee.EmployeeId[color="gray"])[/color][/code]</description><pubDate>Wed, 27 Aug 2008 05:36:23 GMT</pubDate><dc:creator>Ken McKelvey</dc:creator></item><item><title>RE: Update statement</title><link>http://www.sqlservercentral.com/Forums/Topic559432-338-1.aspx</link><description>Hi Guys Thanks A lot</description><pubDate>Wed, 27 Aug 2008 04:32:02 GMT</pubDate><dc:creator>kumar99ms</dc:creator></item><item><title>RE: Update statement</title><link>http://www.sqlservercentral.com/Forums/Topic559432-338-1.aspx</link><description>For such scenarios, I also do the updates with a join only. I would be interested to see whether this approach has any performance implications, and what are other recommended ways?</description><pubDate>Wed, 27 Aug 2008 03:26:42 GMT</pubDate><dc:creator>rajankjohn</dc:creator></item><item><title>RE: Update statement</title><link>http://www.sqlservercentral.com/Forums/Topic559432-338-1.aspx</link><description>TRy this.[code]UPDATE eSET e.passportcode = p.passportcodeFROM Employee e	INNER JOIN Passport p ON p.EmployeeId = e.EmployeeId  [/code]</description><pubDate>Wed, 27 Aug 2008 03:08:05 GMT</pubDate><dc:creator>Christopher Stobbs</dc:creator></item><item><title>RE: Update statement</title><link>http://www.sqlservercentral.com/Forums/Topic559432-338-1.aspx</link><description>update employeetable set passportcode A employeetable, B Passport tablewhere a.employeeID=b.Employeeid could any give me the correct query the above query is giveing error it will not updated.</description><pubDate>Wed, 27 Aug 2008 03:04:25 GMT</pubDate><dc:creator>kumar99ms</dc:creator></item><item><title>RE: Update statement</title><link>http://www.sqlservercentral.com/Forums/Topic559432-338-1.aspx</link><description>Is this homework?If you let us know what you have tried so far then we can guide you in the correct direction :-)</description><pubDate>Wed, 27 Aug 2008 02:58:42 GMT</pubDate><dc:creator>Christopher Stobbs</dc:creator></item><item><title>Update statement</title><link>http://www.sqlservercentral.com/Forums/Topic559432-338-1.aspx</link><description>Employee tableEmployeeID  Employeename Employeecode  Passportcode1                   aaaa              0878782                    bbbb             067678Passport tableEmployeeId         passport code1                            023442                            02343How can i update this passport code in the employee tableusing update statement any body plz help me. </description><pubDate>Wed, 27 Aug 2008 02:52:01 GMT</pubDate><dc:creator>kumar99ms</dc:creator></item></channel></rss>