下面的代码在sql2008和sql2000上的运行方式是有区别的。在sql 2000中,结果是正确的(从第一行到最后一行的提取是正常的),而在sql 2008中,提取显示出奇怪的行为(从最后一个插入行开始,直到第一个行,下面是问题的代码其中, '区域' 是任何表:sql 2008光标与sql2000的区别?
create trigger tr on area for insert as
declare @id int
select @id = id from inserted
print 'trigger: ' + convert(varchar(50), @id)
declare c cursor scroll for select id from inserted order by id
open c
fetch next from c into @id
while @@FETCH_STATUS = 0
begin
print 'cursor id: ' + convert(varchar(50), @id)
fetch next from c into @id
end
close c
deallocate c
下面
是在SQL 2008的结果showig:
trigger: 1828
cursor id: 1837
cursor id: 1836
cursor id: 1835
cursor id: 1834
cursor id: 1833
cursor id: 1832
cursor id: 1831
cursor id: 1830
cursor id: 1829
cursor id: 1828
和SQL 2000中显示的结果是:
trigger: 1837
cursor id: 1828
cursor id: 1829
cursor id: 1830
cursor id: 1831
cursor id: 1832
cursor id: 1833
cursor id: 1834
cursor id: 1835
cursor id: 1836
cursor id: 1837
有没有一个选项,我可以设置使用它像SQL 2000的正常方式? – 2010-01-29 10:01:58
我知道如何为您的选择语句添加“order by”。它适用于sql2000和sql2008。 – NetSide 2010-01-29 10:21:15