Use the order by clause in the view

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.