Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USE [DataBaseExam2019]
- GO
- /****** Object: Trigger [dbo].[trg_Prevent_deletion_CreditCard] Script Date: 22/01/2020 12:34:32 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- ALTER TRIGGER [dbo].[trg_Prevent_deletion_CreditCard]
- ON [dbo].[TCreditCard]
- FOR DELETE
- AS
- BEGIN
- DECLARE @Totalpurchase money;
- Declare @UserId int = (Select nUserId from deleted)
- Declare @CreditCardCount int = (Select Count(*) from TCreditCard Where nUserId = @UserId)
- SELECT @Totalpurchase = nTotalPurchase FROM deleted;
- Print(@UserId)
- Print(@CreditCardCount)
- IF(@Totalpurchase != 0)
- Begin
- RAISERROR('Records can not be deleted, as user have purchased Item', 10,1)
- ROLLBACK TRAN
- End
- IF(@CreditCardCount = 0)
- Begin
- RAISERROR('Records can not be deleted, as user only have 1 Credit Card', 10,1)
- ROLLBACK TRAN
- End
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement