我用了以下一个方法(大于一页时): select top n fields from table where fieldid not in(select top n*(page-1) fieldid from table order by fieldid desc) order by fieldid desc 这样的话记录越多,翻页显示记录的速度会越来越慢.不过我测试在查询分析器里面运行速度还可以. 还有就是表必须是一个关键字否则很容易将同一ID的记录覆盖掉.不知道 arhui2003(阿辉)兄有何良策?
mssql_data_seek ( int result_identifier, int row_number) mssql_data_seek() moves the internal row pointer of the MS SQL result associated with the specified result identifier to point to the specified row number. The next call to mssql_fetch_row() would return that row. 用这个是不是有效。我没有试过。
我认为: 首先,用not in 或者用in会破坏数据库的索引,不如直接查快.这在大数据量的时候很明显,但对于小数据量,其实平时也不必考虑这些问题了。 其次,一般情况下,建表的时候需要一个唯一的索引或者说关键字,比如ID。当然有些表确实可以不用建唯一的,但我建议也加上一个,这是没有害处的。,而如果出现“记录被覆盖掉”的情况,那就是应该建唯一索引而没有建,是建表结构时的失误!
其次是SQL写法要合理,能好好用上索引,就能提高速度!
至于限定返回的条数,方法不可取,那样取到的数据会有问题!限定条数是数据存储的物理上的概念,但实际上取数是逻辑上的取法,两者结合用的时候要谨慎,容易出错!
select top n fields from table where fieldid not in(select top n*(page-1) fieldid from table order by fieldid desc) order by fieldid desc
这样的话记录越多,翻页显示记录的速度会越来越慢.不过我测试在查询分析器里面运行速度还可以.
还有就是表必须是一个关键字否则很容易将同一ID的记录覆盖掉.不知道 arhui2003(阿辉)兄有何良策?
mssql_data_seek() moves the internal row pointer of the MS SQL result associated with the specified result identifier to point to the specified row number. The next call to mssql_fetch_row() would return that row.
用这个是不是有效。我没有试过。
首先,用not in 或者用in会破坏数据库的索引,不如直接查快.这在大数据量的时候很明显,但对于小数据量,其实平时也不必考虑这些问题了。
其次,一般情况下,建表的时候需要一个唯一的索引或者说关键字,比如ID。当然有些表确实可以不用建唯一的,但我建议也加上一个,这是没有害处的。,而如果出现“记录被覆盖掉”的情况,那就是应该建唯一索引而没有建,是建表结构时的失误!