避免换重房间-触发器

动态 置顶 精帖
3130
Admin
Admin Yolo3 2024-02-28 10:06:14
USE [Yolo880_Hotel]
GO
/****** Object:  Trigger [dbo].[double_room]    Script Date: 2024-01-20 09:29:26 
避免同一个房间短时间内换房多次
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create TRIGGER [dbo].[Update_Status] 
			ON [dbo].[T_RoomOrder]
			AFTER UPDATE  
			AS 
				DECLARE @old_status varchar(10), 
						@new_status varchar(10);

				SELECT @new_status=F_Status FROM inserted i;
				SELECT @old_status=F_Status FROM deleted d;
				if UPDATE(F_Status)
				BEGIN
					if @old_status = '已换房'  and @new_status ='已换房'
						BEGIN

							ROLLBACK;
						END
				END