开发者

TSQL to ensure the rows arrive in order of date, when rows are fetched using a cursor?

I'm wonde开发者_开发知识库ring if its possible to put a constraint on the "date" column in a table, so that when data is fetched using a cursor, it always arrives with the dates in order?


The only way to guarantee the ordering of data returned by a query is to use an ORDER BY clause.


Why not simply query the rows in order by date?


declare Cur cursor for select Col1 from YourTable order by DateCol


Use ORDER BY. You should also consider using a set-based approach without a cursor where possible. Cursors generally speaking are more complex to develop and maintain and frequently perform poorly compared to a set-based solution.


Why not set a ascending clustered index on the date column? This means that the rows can only be returned in one order, and selects are a lot faster. This is excellent for time series.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜