去年写了个新闻发布系统.今年发现有些新闻条目显示不出来.
检查半天,发现set rowcount出问题.
新闻分类是树状结构的,用个自定义函数返回表,得到新闻子类id.我是让用户设置每个分类在首页上显示最新闻条目数量.
所以图方便用了
set rowcount @n
select * from dbo.f() A,news B where A.id=B.id结果,set rowcount @n会先影响dbo.f() 返回的数目,再连接表.很多大于@n的分类ID出不来了.示例如下:create function f()
returns @a table(id int)
as
begin
insert @a select 1 
union all select 3
union all select 4
union all select 5
union all select 6
union all select 7
union all select 8
......
union all select 10000
return
endset rowcount 6
select * from dbo.f() A,sysobjects B where a.id=b.id结果:只返回id<=6的记录.不足6条.