Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

sql server - Get data from large table in chunks

I have a large table having millions of records. I am binding this table to gridview in my application. Since data is large, we are retrieving data using paging concepts. like if i set the gridview page size to 2000, then i am fetching only 2000 records from table. i am using following Query for this

Select * from (select *, Row_Number() over (order by id) as Row_Index) a 
where
Row_Index > @start_index and Row_Index < @End_Index

This query run fast for first few millions of records but as the start and end index increases performace degrades drastically. How can i improve this query

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Make your unique column be index (either clustered of non-clustered) like your ID column in table is a good candidate if it has no duplicate..

Or add an AutoIncremented Column ID.

You may also use query like this

Select  top 2000 *
from    t
where ID >= @start_index
order by ID

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...