1. OUTPUT ... INTO
用於將一條記錄從表一移動到表二時非常好用,常見於備份記錄的應用
例一:
DELETE [TableUseing]
OUTPUT *
INTO [TableBak]
例二:(用於移動時修改某字段的值)
DELETE [TableUseing]
OUTPUT Field1, Field2, GETDATE()
INTO [TableBak]
2.表變量
用於存儲臨時的查詢結果
DECLARE @tmp TABLE (ID INT, CITY NVARCHAR(50))
INSERT INTO @tmp
SELECT MIN(ID), CITY
FROM [TableTest] WITH(NOCLOCK)
GROUP BY CITY