触发器小练

ALTER Trigger [dbo].[triVehicle] On [dbo].[OP_VehicleInfo]
for insert
As
DECLARE @order int;
DECLARE @outorder int;
set @order = (select max(InSideSort)+1 from OP_VechileState) ;
set @outorder = (select max(OutsideSort)+1 from OP_VechileState) ;
INSERT into OP_VechileState select inserted.vehicleid,@order ,@outorder,‘1‘,null from inserted

 

 

、、、、、

ALTER Trigger [dbo].[trdVehicle] On [dbo].[OP_VehicleInfo]
for Delete
As
Delete dbo.OP_VechileState From dbo.OP_VechileState br , deleted d Where br.VehicleID=d.VehicleID
Delete dbo.OP_Clean From dbo.OP_Clean br , deleted d Where br.VehicleID=d.VehicleID
Delete dbo.OP_DutyInfo From dbo.OP_DutyInfo br , deleted d Where br.VehicleID=d.VehicleID
Delete dbo.OP_Vacation From dbo.OP_Vacation br , deleted d Where br.VehicleID=d.VehicleID
Delete dbo.OP_Maintain From dbo.OP_Maintain br , deleted d Where br.VehicleID=d.VehicleID
Delete dbo.OP_VehicleBusinessInner From dbo.OP_VehicleBusinessInner br , deleted d Where br.VehicleID=d.VehicleID
Delete dbo.OP_VehicleBusinessOuter From dbo.OP_VehicleBusinessOuter br , deleted d Where br.VehicleID=d.VehicleID

 

 

 

、、、、、

ALTER Trigger [dbo].[triVehiclestate] On [dbo].[OP_VechileState]
for update
As
if update([state])
begin
update OP_VechileState set preState =d.state from OP_VechileState vs , deleted d where vs.VehicleId = d.VehicleId
end

触发器小练

上一篇:空白块多出几像素(IE6)


下一篇:云桌面问题