|
Q
Why doesn't SQL Server permit an ORDER BY
clause in the definition of a view?
A
SQL
Server excludes an ORDER BY clause from a view to
comply with the ANSI SQL-92 standard. Because analyzing
the rationale for this standard requires a discussion
of the underlying structure of the structured query
language (SQL) and the mathematics upon which it is
based, we can't fully explain the restriction here.
However, if you need to be able to specify an ORDER
BY clause in a view, consider using the following
workaround:
USE
pubs
GO
CREATE VIEW AuthorsByName
AS
SELECT TOP 100 PERCENT *
FROM authors
ORDER BY au_lname, au_fname
GO
The TOP construct, which Microsoft introduced in SQL
Server 7.0, is most useful when you combine it with
the ORDER BY clause. The only time that SQL Server
supports an ORDER BY clause in a view is when it is
used in conjunction with the TOP keyword.
Note
that the TOP keyword is a SQL Server extension to
the ANSI SQL-92 standard.
|