I have a trigger that will be dynamically created, as it will be attached to a view that is also dynamically generated. I don't want my stored procedure to have the entire trigger within it, so I would like to move most of it to a stored procedure, but I won't know the fields in the inserted and deleted tables.
The trigger is about 90 lines long, and the only part I really need to be different between triggers is:
DECLARE @DEBUG bit = 1
DECLARE @EntityName nvarchar(128) = 'Lot'
SELECT * INTO #MYINSERTED FROM INSERTED
SELECT * INTO #MYDELETED FROM DELETED
If I could move the rest of it to a stored procedure then that would be great.
The problem with just passing in the @DEBUG and @EntityName and using #MYINSERTED and #MYDELETED in the stored procedure then I would have a problem if two people are inserting or updating the same view at the same time.
The best bet would be to pass a table variable to remove any concurrency issues but I am not certain the best way to do that.
Thank you.