Q: Why is the order by clause not allowed in the view definition of SQL Server?
A: SQL Server does not allow the ORDER BY clause in view definitions to comply with ANSI SQL-92 standards. The theoretical analysis of this standard requires the discussion of the underlying structure of the Structured Query Language (SQL) and the mathematical theory it is based on. We cannot fully explain it here. However, if you need to specify the order by clause in the view, consider using the following methods:
USE pubs
GO
Create view AuthorsByName
AS
Select top 100 PERCENT *
FROM authors
Order by au_lname, au_fname
GO
The TOP structure introduced BY Microsoft in SQL Server 7.0 is useful when combined with the ORDER BY clause. SQL Server supports the use of the ORDER BY clause in the view only when used in conjunction with the TOP keyword.
Note: TOP keywords are SQL Server Extensions to ANSI SQL-92 standards.