i have an orders table that has a userID column
i have a user table that has id, name,
i would like to have a database trigger that shows the insert, update or delete by name.
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?
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, . . .