title: is there anyway to cache data that can be used in a SQL server db trigger
body: <p>i have an orders table that has a userID column</p>
  
  <p>i have a user table that has id, name,</p>
  
  <p>i would like to have a database trigger that shows the insert, update or delete by name.</p>
  
  <p>so i wind up having to do this join between these two tables on every single db trigger.  I would think it would be better if i can one query upfront to map users to Ids and then reuse that "lookup " on my triggers . . is this possible?</p>
  
  <pre><code>DECLARE @oldId int
  DECLARE @newId int
  DECLARE @oldName VARCHAR(100)
  DECLARE @newName VARCHAR(100)
  
  SELECT @oldId = (SELECT user_id FROM Deleted)
  SELECT @newId = (SELECT user_id FROM Inserted)
  
  SELECT @oldName = (SELECT name FROM users where id = @oldId)
  SELECT @newName = (SELECT name FROM users where id = @newId)
  
    INSERT INTO History(id,  . . . 
  </code></pre>