Introduction:
Here I will explain SQL query to update multiple tables in SQL Server using inner joins or update multiple tables in SQL Server with joins.
Here I will explain SQL query to update multiple tables in SQL Server using inner joins or update multiple tables in SQL Server with joins.
Description:
In
previous posts I explained difference between LEN and DATALENGTH functions in SQL Server,
Convert rows to columns without pivot tables in sql server,
SQL query to get data between dates and many articles
relating to SQL Server. Now I will explain how to write update query
with multiple tables in SQL
Server.
Generally
we don’t have an option to update multiple tables in single statement because
of that we need to update tables separately like as shown below
Syntax to update multiple tables
UPDATE t1
SET t1.Name = 'suresh'
FROM Table1 t1, Table2 t2
WHERE t1.id = t2.id
and t1.id = 10
UPDATE t2
SET t2.username = 'dasari'
FROM Table1 t1, Table2 t2
WHERE t1.id = t2.id
and t1.id = 10
|
Syntax to update multiple tables with
inner join
UPDATE t1
SET t1.Name = 'suresh'
FROM Table1 t1 INNER JOIN Table2
t2
and t1.id = 10
UPDATE t2
SET t2.username = 'dasari'
FROM Table1 t1 INNER JOIN Table2
t2
ON t1.id = t2.id
and t1.id = 10
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
4 comments :
Hi surresh,
Your posts are really helpfull for me.Could you please post an article on 'Online bank transactions using payment gateways' with asp .net?
Hi Suresh,
It seems inner join keyword is missed. Other wise we will get invalid syntax near ON.
UPDATE t1
SET t1.Name = 'suresh'
FROM Table1 t1 inner join Table2 t2
ON t1.id = t2.id
and t1.id = 1
hai suresh sir, can we inner join two image feilds from two tables and display it in a repeater
please give me some codes
Hey dude ,
I m having one doubt, hope will get response from your end.
Q: In Database A I m hvng table1 with 100 records. Now I m deleting the Database A and again creating freshly with same name. Now my requirement is I want to save (re insert the) 100 records data before deleting the database and restore (re insert into) after creating fresh database.
Note: Only a member of this blog may post a comment.