日期:2014-05-17 浏览次数:20509 次
CREATE PROCEDURE BorrowStatusSetProc
@discno int,
@who nvarchar(50),
@whichtimego datetime,
@whichtimeback datetime,
@borrowstatus bit,
@insertOrupdate bit
---以上为InfoOfBorrow表的字段
AS
--开始事务
BEGIN TRAN updateStatus
IF @insertOrupdate=1---标示该操作动作为插入数据
INSERT INTO
InfoOfBorrow
Values(@discno,@who,@whichtimego,@whichtimeback,@borrowstatus)
Else ---更新数据
UPDATE
InfoOfBorrow
Set
BorrowStatuus=1
where
DiscNO=@discno AND Who=@who
---以下为InfoOfVideo联动更新
CREATE TRIGGER updateVideoTrg
ON InfoOfBorrow
After
Insert,Delete,Update
AS
IF (Exists(select * from inserted))
Begin
Update InfoOfVideo
Set BorrowStatus=0
where DiscNO=@discno ---这里不能引用@discno
End
IF @@ERROR<>0
COMMIT TRAN updateStatus
ELSE
ROLLBACK TRAN updateStatus
GO