What are the differences between the older row_number() and the newer OFFSET + FETCH based pagination in SQL Server?
Using ROW_NUMBER()
works fine - it's just more work than necessary; you need to write a "skeleton" CTE around your actual query, add the ROW_NUMBER()
column to your output set, and then filter on that.
Using the new OFFSET / FETCH
is simpler - and yes, it's also better for performance, as these two links can show you:
- New T-SQL features in SQL Server 2012
- Comparing performance for different SQL Server paging
So overall: if you're using SQL Server 2012 - then you should definitely use OFFSET/FETCH
rather than ROW_NUMBER()
for paging