1

我有此代码用于更新,但如何将其更改为 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'
4

3 回答 3

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'
于 2013-03-19T13:38:25.167 回答
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')
于 2013-03-19T13:39:06.020 回答
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语句可以很容易地变成一个DELETE. 事实上,我曾经工作过的一个地方,他们的规则是这样的:

编写SELECT语句,然后如果它为您获取数据,请摆脱SELECT并将其更改为DELETE-但只有这样。

于 2013-03-19T13:38:45.797 回答