Provide a Built-in Function for Sequential Row Numbers in Query Output
还没有人认领这个 Issue。
评估
调研方向
issue 中没有指定文件、测试或入口点。首先检查此 samples repository 是否包含适用的 SQL Server 示例或 feature-request 流程;要完成这项工作,需要为所提议的函数提供实现路径,而 payload 未对此进行说明。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- PowerShell
- 星标
- 11.2k
- 派生
- 9.1k
- 平均合并
- 2 天 7 小时
- 30 天内合并 PR
- 14
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/sql-server-samples 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 85/100
microsoft/sql-server-samples#1499 ·
-
难度 1/5 1-3 小时 新手友好度 76/100
microsoft/sql-server-samples#1495 · 3 个 reaction ·
-
难度 1/5 1 小时以内 新手友好度 62/100
microsoft/sql-server-samples#1341 ·
-
难度 1/5 1 小时以内 新手友好度 64/100
microsoft/sql-server-samples#276 ·
-
难度 1/5 1 小时以内 新手友好度 35/100
microsoft/sql-server-samples#1497 ·
查看 microsoft/sql-server-samples 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
community-scripts/ProxmoxVE#17396 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
BasedHardware/omi#15274 · 3 条评论 ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist 未关闭bug
难度 2/5 1-3 小时 新手友好度 90/100
-
难度 1/5 1 小时以内 新手友好度 90/100
-
[BUG] A column whose default is the empty string is drawn in the ER diagram as having no default 未关闭bug database-provider good first issue hacktoberfest
难度 2/5 1-3 小时 新手友好度 90/100
libredb/libredb-studio#1030 · 6 条评论 ·