SQL Getting Started Tutorial: SQL CREATE VIEW

Source: Internet
Author: User

SQL Getting Started Tutorial: SQL CREATE VIEW

There is an opinion that is a view.

SQL declaration for creation period
In SQL, there is an opinion that is a virtual basis for the statement of the result set on the table.

There is a view that contains rows and columns, just like a real table. The field of view, field, from one or more real tables in the database.

You can add SQL functions, where, and add declarations to the current data, if the data is coming from a single table.

The SQL CREATE view syntax

CREATE VIEW View_name as
SELECT column_name (s)
From table_name
WHERE condition
Let's look at an example of a CREATE view.
If you have a Northwind database you can see that it has a few ideas for default installation. Think "Current Product List" lists all active products (product does not stop) from the "Products" table. The view is to create the following sql:create view [current Product List] as
SELECT Productid,productname
From Products
Where Discontinued=no we can query the above view as follows: SELECT * FROM [current product List] Another view is that the "product" for each product is selected in the Northwind sample database The unit price of the table is higher than the average unit price: CREATE VIEW [Products Above Average Price] As
SELECT Productname,unitprice
From Products
WHERE unitprice> (SELECT AVG (UnitPrice) from products) is queried as. SELECT * FROM [Products Above Average Price]sql Dropping a view you can delete in order to view commands with the drop view. In view of the falling SQL syntax drop view view_name

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.