使用左连接查询运行UPDATE和DELETE SQL语句 [英] Running UPDATE And DELETE SQL Statements with left join query

查看:1513
本文介绍了使用左连接查询运行UPDATE和DELETE SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们是否可以使用UPDATE和DELETE SQL语句与左连接查询?

解决方案

是的可能...



请查看以下内容





更新Table_1 
set columnTable_1 = @ parameter_1
来自 Table_1 t1
内部 join 表_2 t2
在t1.columnTable_1 = t2.columnTable_2
其中 t2.columnTable_1 = @参数_2 b
$ b删除来自 Table_1
来自 Table_1 t1
inner join 表_2 t2
on t1.columnTable_1 = t2.columnTable_2
其中 t2.columnTable_2 = @ parameter_1









示例代码...... ...



 创建 类型 abcd  as   table  

id int
salary int

create 输入 nameAbcd as table

id int
name varchar 3


go
- drop type nameAbcd

声明 @ p abcd
插入 进入 @ p 1 100
insert into @ p 2 5000
声明 @ q nameAbcd
insert into @ q values 1 ' abc'
插入 进入 @ q 2 ' xyz'


选择 * 来自 @ p a 内部 join @ q b on a.id = b.id

update @ p
set salary = 59
from @ p a
inner join @ q b
on a.id = b.id
其中 b.name = ' xyz'


选择 * 来自 @ p a inner join @ q b on a.id = b.id

delete 来自 @ p
来自 @p a
内部 join @q b
a.id = b.id
其中 b.name = ' abc'


选择 * 来自 @ p a < span class =code-keyword> inner join @ q b > a.id = bi d


是......

同时删除 [ ^ ]和更新 [ ^ ]可能有 FROM [ ^ ]子句,任何FROM子句都可以有JOIN - 答案是肯定的...

要获得更明确的答案,你应该多询问一下细节...

is it possible that we can use UPDATE And DELETE SQL Statements with left join query ?

解决方案

Yes it is possible...

Please check the below


update Table_1
set columnTable_1 = @parameter_1
from Table_1 t1
inner join Table_2 t2
on t1.columnTable_1 = t2.columnTable_2
where t2.columnTable_1 = @parameter_2 

delete from Table_1
from Table_1 t1
inner join Table_2 t2
on t1.columnTable_1 = t2.columnTable_2
where t2.columnTable_2 = @parameter_1





Sample code......

create type abcd as table
(
	id int,
	salary int
)
create type nameAbcd as table
(
	id int,
	name varchar(3)
)

go
--drop type nameAbcd

declare @p abcd
insert into @p values(1, 100)
insert into @p values(2, 5000)
declare @q nameAbcd
insert into @q values(1, 'abc')
insert into @q values(2, 'xyz')


select * from @p a inner join @q b on a.id = b.id

update @p
set salary = 59
from @p a
inner join @q b
on a.id = b.id
where b.name = 'xyz'


select * from @p a inner join @q b on a.id = b.id

delete from @p
from @p a
inner join @q b
on a.id = b.id
where b.name = 'abc'


select * from @p a inner join @q b on a.id = b.id


Yes...
As both DELETE[^] and UPDATE[^] may have a FROM[^] clause, and any FROM clause can have JOIN in it - the answer is yes...
To get more defined answer, you should ask with more details...


这篇关于使用左连接查询运行UPDATE和DELETE SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆