Advertisement
Guest User

Untitled

a guest
Feb 12th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.64 KB | None | 0 0
  1. CREATE TRIGGER tr_levelRestriction ON UserGameItems
  2. FOR INSERT
  3. AS
  4.      DECLARE @UserLevel INT=
  5.      (
  6.          SELECT ug.[Level]
  7.          FROM inserted AS ugi
  8.               JOIN UsersGames AS ug ON ugi.UserGameId = ug.Id
  9.      );
  10.      DECLARE @ItemLevel INT=
  11.      (
  12.          SELECT i.MinLevel
  13.          FROM inserted AS ugi
  14.               JOIN Items AS i ON ugi.ItemId = i.Id
  15.      );
  16.      IF @UserLevel < @ItemLevel
  17.          BEGIN
  18.              ROLLBACK;
  19.              RAISERROR('User level is too low for this item!', 16, 1);
  20.              RETURN;
  21.      END;
  22.  
  23.      INSERT INTO UserGameItems
  24.             SELECT *
  25.             FROM inserted;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement