miroslavbstoyanov

Untitled

Jun 20th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. CREATE TRIGGER tr_ItemsPurchaseRestrictions ON UserGameItems AFTER INSERT
  2. AS
  3. BEGIN
  4. DECLARE @userGameLevel int = (
  5. SELECT ug.Level
  6. FROM inserted AS ugi -- UserGameItems
  7. JOIN UsersGames AS ug ON ugi.UserGameId = ug.Id
  8. );
  9. DECLARE @itemMinLevel int = (
  10. SELECT i.MinLevel
  11. FROM inserted AS ugi -- UserGameItems
  12. JOIN Items AS i on i.Id = ugi.ItemId
  13. );
  14. IF(@itemMinLevel > @userGameLevel)
  15. BEGIN
  16. ROLLBACK;
  17. RAISERROR('Higher user game level required for item purchase', 16, 1);
  18. RETURN;
  19. END
  20. END
Advertisement
Add Comment
Please, Sign In to add comment