title: SQL Server : trigger how to read value for Insert, Update, Delete
body: <p>I have the trigger in one table and would like to read <code>UserId</code> value when a row is inserted, updated or deleted. How to do that? The code below does not work, I get error on <code>UPDATED</code>  </p>
  
  <pre><code>ALTER TRIGGER [dbo].[UpdateUserCreditsLeft] 
     ON  [dbo].[Order]
     AFTER INSERT,UPDATE,DELETE
  AS 
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
  
      DECLARE 
      @UserId INT,
  
      SELECT @UserId = INSERTED.UserId FROM INSERTED, DELETED
  
      UPDATE dbo.[User] SET CreditsLeft = CreditsLeft - 1 WHERE Id = @UserId
  END
  </code></pre>