1 OUTPUT 应用场景 :
1.1.对于INSERT,可以引用inserted表以查询新行的属性.
insert into [表名] (a) OUTPUT Inserted.a values ('a')
1.2.对于DELETE,可以引用deleted表以查询旧行的属性.
delete [表名] OUTPUT deleted.a where links = 'a'
1.3.对于UPDATE,使用deleted表查询被更新行在更改前的属性,用inserted表标识被更新行在更改后的值.
update [表名] set a = 'b' OUTPUT Inserted.a where a = 'a'(返回修改后的值)
update [表名] set a = 'b' OUTPUT deleted.a where a = 'a' (返回修改前的值)
2 With (nolock) 和 With (rowlock) 详见 http://wenku.baidu.com/link?url=UZNJ7zrsnZsXO4k7Njg8V-zED7VQY2DwjT5qm7PvEoR2LkrqvWkcyENsYs1lBZ1if3rfsicJfVlXkwCrd3RL3KfJW3MeDLHSNeEmjYROngy
它们的使用方法如下:
SELECT COUNT(UserID) FROM Users WITH (NOLOCK) WHERE Username LIKE '%foobar' 和
UPDATE Users WITH (ROWLOCK) SET Username = 'fred' WHERE Username = 'foobar