, . , ...
(#temp) , (@temp), , . (, .)
SELECT INTO, .
, - ?
DECLARE @temp TABLE (id AS INT, val as INT)
IF @ChangeType = 'D'
INSERT INTO @temp SELECT * FROM DELETED
ELSE
INSERT INTO @temp SELECT * FROM INSERTED
Personally, I even avoid using * if possible. Your subsequent queries will only use certain fields, so I would only copy the fields that I used. This has an additional advantage: if fields are added to the table, the code is not interrupted ...
DECLARE @temp TABLE (id AS INT, val as INT)
IF @ChangeType = 'D'
INSERT INTO @temp SELECT id, val FROM DELETED
ELSE
INSERT INTO @temp SELECT id, val FROM INSERTED
In my opinion, the advantage of specifying fields (which you want to avoid) is that you can guarantee that you always copy only what you need.
source
share