#tempTable是
dbo.deleteStuff
)游标是否按照这些行加载到临时表的顺序处理临时表的行,还是随机/非确定地处理? BOL没有具体回答这个问题(我最接近的是KEYSET
),我没有看到直接回答或暗示引擎如何解析这个特定场景的博客文章/等。
正在加载和处理临时表的列只有三列:
dbo.tblWhatGotDeleted
)。其他事实:
tblFoo EXCEPT vwFoo
。)如果行没有
在目标表中的源视图中存在的时间更长
目标表中的行将被删除并写入
临时表。这个过程重复了大约二十几个表格。临时表加载顺序,由动态SQL驱动:
DELETE from tblFoo where thisidentifer = '1';
DELETE from tblFoo where thisidentifier = '5';
DELETE from tblFoo where thisidentifier = '7';
DELETE from tblBar where thatidentifier = 'Apple';
DELETE from tblBar where thatidentifier = 'Orange';
DELETE from tblBar where thatIdentifier = 'Pear';
DELETE from tblBlargh where otheridentifier = 'Alpha';
DELETE from tblBlargh where otheridentifier = 'Beta';
DELETE from tblBlargh where otheridentifier = 'Gamma';
我可以指望光标以相同的顺序处理这些语句吗?
DELETE from tblFoo where thisidentifer = '1';
DELETE from tblFoo where thisidentifier = '5';
DELETE from tblFoo where thisidentifier = '7';
DELETE from tblBar where thatidentifier = 'Apple';
DELETE from tblBar where thatidentifier = 'Orange';
DELETE from tblBar where thatIdentifier = 'Pear';
DELETE from tblBlargh where otheridentifier = 'Alpha';
DELETE from tblBlargh where otheridentifier = 'Beta';
DELETE from tblBlargh where otheridentifier = 'Gamma';
此proc的过去行为暗示行按INSERT的顺序处理,但我可能还没有被引擎烧毁。
这是光标代码:
DECLARE deleteRows CURSOR FOR
select deleteList.* from #stuffToDelete as deleteList
OPEN deleteRows
FETCH next FROM deleteRows INTO @summaryOfWhatsGettingNuked, @theIdentifierForWhatsGettingNuked, @theSqlThatDoesTheNuking
WHILE (@@Fetch_Status = 0)
BEGIN
EXEC (@theSqlThatDoesTheNuking)
FETCH next FROM deleteRows INTO @summaryOfWhatsGettingNuked, @theIdentifierForWhatsGettingNuked, @theSqlThatDoesTheNuking
END
CLOSE deleteRows
DEALLOCATE deleteRows