1. OUTPUT ... INTO

用于将一条记录从表一移动到表二时非常好用,常见于备份记录的应用

例一:

DELETE [TableUseing] 
OUTPUT Deleted.* 
INTO [TableBak]

例二:(用于移动时修改某字段的值)

DELETE [TableUseing] 
OUTPUT Deleted.Field1, Deleted.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
Posted on 2007-11-22 14:01 Clark Zheng 阅读(...) 评论(...) 编辑 收藏