Click here to Skip to main content
11,649,522 members (76,783 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
how to update multiple tables in single statement .please not tell me multiple update query..
Posted 28-Sep-12 0:26am
bhargavpp1.5K
Comments
Abhijit Parab at 28-Sep-12 6:31am
   
Use Trigger...........
bhargavpp at 2-Oct-12 8:15am
   
i want in stored procedure but not with multiple statement
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The simplest way is to use a stored procedure: you hand it all the parameters, and it fills in the table updates. It would also be a good idea to do this within a transaction, so if any part of the update fails, the whole update can be rolled back - you can do the transaction within the procedure.

SQL stored Procedures[^]
  Permalink  
Comments
bhargavpp at 1-Oct-12 6:55am
   
i want like update tbl1,tbl2 set tbl1.col=test,tbl2.col2=test where condition
is this possible
_Amy at 1-Oct-12 7:16am
   
Deserves +5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
bhargavpp at 1-Oct-12 6:56am
   
i want like update tbl1,tbl2 set tbl1.col=test,tbl2.col2=test where condition
is this possible
snehasish nandy at 1-Oct-12 7:04am
   
check this link..hope u can do..
http://stackoverflow.com/questions/2044467/how-to-update-two-tables-in-one-statement-in-sql-server-2005[^]

the way u r asking it's better to go for stored procedure or join query..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Why do you need the complex queries rather Microsoft already given you a better option with Stored Procedure[^].

Being a developer you should think to minimize the code and maximize the performance. But you are not clearly aware about the advantages of using such things. Read SQL SERVER – Stored Procedures Advantages and Best Advantage[^].



--Amit
  Permalink  
Comments
bhargavpp at 2-Oct-12 8:14am
   
i want same thing in stored procedure but i dont want multiple execution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 354
1 F-ES Sitecore 344
2 Kornfeld Eliyahu Peter 319
3 CPallini 290
4 Maciej Los 269
0 OriginalGriff 1,577
1 Sergey Alexandrovich Kryukov 1,087
2 CPallini 1,015
3 DamithSL 996
4 jyo.net 994


Advertise | Privacy | Mobile
Web01 | 2.8.150804.4 | Last Updated 1 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100