ASP C#查询删除内连接表

时间:2013-03-19 13:36:14

标签: sql

我有这个代码用于更新,但如何将其更改为DELETE不更新。这是可能的吗?

update r set r.Status = 'Checked-in' from Reservation r 
inner join GuestInfo g on g.GuestID = r.GuestID 
where g.GuestFName = 'firstname' 
and g.GuestLName = 'lastname' 
and r.RoomNo = '103'

3 个答案:

答案 0 :(得分:2)

这样的事情应该有效:

delete r from Reservation r 
inner join GuestInfo g on g.GuestID = r.GuestID 
where g.GuestFName = 'firstname' 
and g.GuestLName = 'lastname' 
and r.RoomNo = '103'

答案 1 :(得分:2)

Delete from Reservation
where id in 
(select r.id from Reservation r 
inner join GuestInfo g on g.GuestID = r.GuestID 
where g.GuestFName = 'firstname' 
and g.GuestLName = 'lastname' 
and r.RoomNo = '103')

答案 2 :(得分:0)

绝对!您只需删除UPDATE部分,然后将关键字更改为DELETE

delete Reservation
from Reservation r 
    inner join GuestInfo g on g.GuestID = r.GuestID 
where g.GuestFName = 'firstname' 
and g.GuestLName = 'lastname' 
and r.RoomNo = '103'
事实上,这很常见。很多时候,您需要根据条件执行更复杂的DELETE,并且多次 SELECTUPDATE语句可以非常轻松地< / strong>变成DELETE。事实上,我曾经工作过一次,他们的统治就是:

  

撰写SELECT语句,然后如果它为您提供了数据,请删除SELECT并将其更改为DELETE - 但仅限于此。