DF033: The SELECT TOP statement is used without the ORDER BY clause.
Last modified: May 28, 2025
The topic describes the DF033 T-SQL code analysis rule.
Category
BEST PRACTICE
Message
The SELECT TOP statement is used without the ORDER BY clause.
Description
It is recommended that you always use an ORDER BY clause in SELECT TOP statements to specify the order in which the rows are returned. This helps ensure that the result set is predictable and consistent.
Additional information
If the ORDER BY clause is not specified, the order of returned data will depend on different factors. These include the order and type of table joins (nested loop, hash join, merge join), whether indexes are used for data selection, whether parallelisation is used, whether intermediate data is stored in tempdb, etc.
Noncompliant code example
SELECT TOP (100) *
FROM dbo.DemoTable
Compliant solution
SELECT TOP (100) *
FROM dbo.DemoTable
ORDER BY FirstName ASC
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.