1

I have two tables and I want to update both the tables with single Query

Sample query:

UPDATE T1, T2 SET T1.FirstName = T2.SecondName ,T2.SecondName = T1.FirstName
FROM Table1 T1, Table2 T2
WHERE T1.id = T2.id

Is there any mechanism for doing this in the Sql server

Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
Pankaj Kumar
  • 655
  • 3
  • 10
  • 16
  • 4
    This is not possible. See question "http://stackoverflow.com/questions/2044467/how-to-update-two-tables-in-one-statement-in-sql-server-2005" for more details. – Gibron Feb 24 '14 at 07:14
  • [link]http://blog.sqlauthority.com/2013/04/30/sql-server-update-from-select-statement-using-join-in-update-statement-multiple-tables-in-update-statement/ try this link and see for better clarification – sentil kumar Feb 24 '14 at 08:12
  • Possible duplicate of [How to update two tables in one statement in SQL Server 2005?](http://stackoverflow.com/questions/2044467/how-to-update-two-tables-in-one-statement-in-sql-server-2005) – Macfer Ann Mar 14 '17 at 07:34

1 Answers1

1

As I know you can not update two tables in one statement, but you can use transactions to create two separate update queries for both tables.

ceth
  • 44,198
  • 62
  • 180
  • 289