Click here to Skip to main content
12,454,104 members (57,719 online)
Rate this:
 
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 28-Sep-12 6:31am
   
Use Trigger...........
bhargavpp 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 1-Oct-12 6:55am
   
i want like update tbl1,tbl2 set tbl1.col=test,tbl2.col2=test where condition
is this possible
_Amy 1-Oct-12 7:16am
   
Deserves +5!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
bhargavpp 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 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 1 Oct 2012
Copyright © CodeProject, 1999-2016
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