Provide a Built-in Function for Sequential Row Numbers in Query Output
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 20/100
Research direction
No files, tests, or entry points are named in the issue. First check whether this samples repository contains an applicable SQL Server sample or feature-request process; completion would require an implementation path for the proposed function, which the payload does not identify.
Written by the indexing model from the issue text.
Description
Description:
SQL Server should introduce a robust built-in function to generate a sequential row number for any query output, without requiring an explicit ORDER BY or window functions like ROW_NUMBER().
Currently, SQL Server users often rely on:
- ROW_NUMBER() OVER (ORDER BY (SELECT 1)) – which is not always stable due to execution plan optimizations and parallelism.
- Manually assigning row numbers in loops – which is inefficient for large datasets.
- SSMS automatically assigning row numbers in result sets – but this behavior is unavailable in T-SQL queries.
Proposed Solution:
Introduce a built-in, lightweight function like:
SELECT SEQ_NUMBER(), * FROM MyQuery;
Where SEQ_NUMBER() assigns a sequential number based on the final result set order, similar to how SSMS automatically numbers rows in its output.
Benefits:
✅ Works without needing an explicit ORDER BY.
✅ Eliminates reliance on ROW_NUMBER() OVER (ORDER BY (SELECT 1)), which can be unstable in parallel execution.
✅ Reduces unnecessary sorting overhead when users only need a sequence number.
✅ Aligns with SSMS behaviour, where query results are always displayed with row numbers.
This feature would greatly simplify reporting queries, temporary data processing, and procedural workflows where a sequence is needed without an ordering constraint.
Example Use Case:
SELECT SEQ_NUMBER(), CustomerName, OrderAmount
FROM Orders
WHERE OrderDate > '2024-01-01';
Expected Output:
SEQ_NUMBER() | CustomerName | OrderAmount
1 | John Doe | 500.00
2 | Jane Smith | 700.00
3 | Mike Ross | 300.00
Would love to hear thoughts from the SQL Server team and the community on this!
Jagdish M
- Dominant language
- PowerShell
- Stars
- 11.2k
- Forks
- 9.1k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 14
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/sql-server-samples
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
microsoft/sql-server-samples#1499 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 76/100
microsoft/sql-server-samples#1495 · 3 reactions ·
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
microsoft/sql-server-samples#1341 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 64/100
microsoft/sql-server-samples#276 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
microsoft/sql-server-samples#1497 ·
All issues in microsoft/sql-server-samples
Similar issues
-
Add: BuyPass TV Openchannels:add check:passed
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
use-agent-os/agent-os#3312 ·
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
HarperFast/documentation#677 ·