Create a view with ORDER BY clause

前端 未结 9 1626
轻奢々
轻奢々 2020-11-30 04:42

I\'m trying to create a view with an ORDER BY clause. I have create it successfully on SQL Server 2012 SP1, but when I try to re-create it on SQL Server 2008 R2

9条回答
  •  我在风中等你
    2020-11-30 04:56

    From Sql 2012 you can force ordering in views and subqueries with OFFSET

    SELECT      C.CustomerID,
                C.CustomerName,
                C.CustomerAge
    FROM        dbo.Customer C
    ORDER BY    CustomerAge OFFSET 0 ROWS;
    

    Warning: this should only be used on small lists because OFFSET forces the full view to be evaluated even if further joins or filters on the view reduce its size!

    There is no good way to force ordering in a view without a side effect really and for good reason.

提交回复
热议问题