更新sqlserver中的表 [英] update the tables in sqlserver
本文介绍了更新sqlserver中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在单个查询中更新三个表?
可以使用任何一种电话解决方案吗?
How to update three tables in a single query?
Can any one tel solution?
推荐答案
最好的方法是将其设置为存储过程,并使用Transaction:
The best way is to set it up as a stored procedure, and use a Transaction:
USE [myDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [multiple_insert]
AS
BEGIN TRANSACTION T1
UPDATE Table1 SET Value1=1 WHERE Id=999
UPDATE Table2 SET Value2=2 WHERE Id=999
UPDATE Table3 SET Value3=3 WHERE Id=999
COMMIT TRANSACTION T1
尝试以下操作:
Try this:
Begin Transaction
Go
Update Table1 Set ... Where --your condition
Go
Update Table2 Set ... Where --your condition
Go
Update Table3 Set ... Where --your condition
Go
Commit Transaction
Go
Refer more details:
Update data by using a query[^]
你可以试试这个...
Hi
You can try this...
BEGIN TRANSACTION
UPDATE Table1
SET Table1.Column1 = 'name'
FROM Table1 T1, Table2 T2
WHERE T1.id = T2.id
and T1.id = '100'
UPDATE Table2
SET Table2.EntityName = 'watch'
FROM Table1 T1, Table2 T2
WHERE T1.id = T2.id
and T1.id = '100'
COMMIT
这篇关于更新sqlserver中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文