浅巷酒香 2015-06-20 02:39 采纳率: 0%
浏览 1988

SQL SEVER触发器,在条件判断中,怎么实现更新一行,而不是一列

USE [Ticket]
GO

create Trigger [dbo].[Price]
on [dbo].[OrderList]
after insert
as
begin
declare @FlightId char(3)
declare @TicketType char(1)
select @TicketType = TicketType from inserted
select @FlightId = FlightId from inserted

declare @Flight_Id char(3)
declare @FPrice float
declare @BPrice float
declare @EPrice float
declare @Rebate float
declare @bool real
select @Flight_Id=FlightId
from Ticket
where FlightId=@FlightId
select @FPrice=FirstClassPrice
from Ticket
where FlightId=@FlightId
select @BPrice=BusinessClassPrice
from Ticket
where FlightId=@FlightId
select @EPrice=EconomyClassPrice
from Ticket
where FlightId=@FlightId
select @Rebate=Rebate
from Ticket
where FlightId=@FlightId
update OrderList
set TicketPrice = @FPrice * @Rebate
where (@Flight_Id = @FlightId and @TicketType like '1')
update OrderList
set TicketPrice = @BPrice * @Rebate
where (@Flight_Id = @FlightId and @TicketType like '2')
update OrderList
set TicketPrice = @EPrice * @Rebate
where (@Flight_Id = @FlightId and @TicketType like '3')

end

为什么一列都会更新?

  • 写回答

2条回答

  • danielinbiti 2015-06-20 04:32
    关注
     update OrderList 
    set TicketPrice = @BPrice * @Rebate
    where (@Flight_Id = @FlightId and @TicketType like '2')
    
    随便抽一句SQL,看看where条件,和当前表的字段没有任何联系,只要这几个变量符合条件,所有记录都更新。
    看看这几个变量和OrderList表的字段有没有关联吧,不然肯定全表更新
    
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面