本文介绍了使用SQL更新两个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我创建了2个表:
table1栏:名称varchar(50),地址varchar(50),电子邮件地址varchar(50)
table2栏:移动bigint,EmailAddress varchar(50)
在这里,我想一次通过单个更新查询来更新两个表
请回复我
Dear All,
I created 2 tables:
table1 columns: name varchar(50), Address varchar(50), emailaddress varchar(50)
table2 columns: mobile bigint, EmailAddress varchar(50)
and here i want update both tables at a time in single update query
please reply me
推荐答案
CREATE PROCEDURE [dbo].[spMyInsertData]
(@name nvarchar(50), @address nvarchar(max), @emailAddress nvarchar(max), @mobile bigint )
as
declare @insertQuery nvarchar(max)
Begin
Begin Try
set @insertQuery = ''INSERT INTO table1(name,address,emailaddress)
values(''+@name+'',''+@address+'',''+@emailAddress+'')''
set @insertQuery = @insertQuery+'' INSERT INTO table2(mobile,EmailAddress)
values(''+@mobile+'',''+@emailAddress+'')''
print @insertQuery;
exec sp_executeSql @insertQuery;
End Try
Begin Catch
print @@error
End Catch
End
这篇关于使用SQL更新两个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!