Why use Select Top 100 Percent?

后端 未结 10 2311
花落未央
花落未央 2020-11-27 15:41

I understand that prior to SQL Server 2005, you could \"trick\" SQL Server to allow use of an order by in a view definition, by also include TOP 100 PERCENT

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 16:04

    TOP (100) PERCENT is completely meaningless in recent versions of SQL Server, and it (along with the corresponding ORDER BY, in the case of a view definition or derived table) is ignored by the query processor.

    You're correct that once upon a time, it could be used as a trick, but even then it wasn't reliable. Sadly, some of Microsoft's graphical tools put this meaningless clause in.

    As for why this might appear in dynamic SQL, I have no idea. You're correct that there's no reason for it, and the result is the same without it (and again, in the case of a view definition or derived table, without both the TOP and ORDER BY clauses).

提交回复
热议问题