0% found this document useful (0 votes)
0 views

CSDL_Ch9_View

This document provides an overview of SQL views, which are virtual tables based on the result-set of SQL statements. It includes instructions on creating, querying, and deleting views, along with examples of SQL syntax for each operation. The document serves as a guide for understanding and utilizing views in SQL databases.

Uploaded by

daominhnhut2017
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

CSDL_Ch9_View

This document provides an overview of SQL views, which are virtual tables based on the result-set of SQL statements. It includes instructions on creating, querying, and deleting views, along with examples of SQL syntax for each operation. The document serves as a guide for understanding and utilizing views in SQL databases.

Uploaded by

daominhnhut2017
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

10/11/2019

Contents
 Introduction
View  Creating a view
 A view from two tables
NGUYEN HongPhuong  Dropping a view
Email: [email protected]
 Updating a table from a view
Site: http://is.hust.edu.vn/~phuongnh
Face: https://www.facebook.com/phuongnhbk
Hanoi University of Science and Technology

1 2

Introduction Creating a view


 In SQL, a view is a virtual table based  Syntax
on the result-set of an SQL statement.
CREATE VIEW view_name AS
 A view contains rows and columns, just
SELECT column1, column2, ...
like a real table. The fields in a view are
FROM table_name
fields from one or more real tables in WHERE condition;
the database.
 You can add SQL functions, WHERE,
and JOIN statements to a view and
present the data as if the data were
coming from one single table.
3 4

1
10/11/2019

Creating a view Querying on a view


 Examples
CREATE VIEW vCompany1 AS
SELECT Name, Address, Telephone
FROM Company SELECT * FROM vCompany1
WHERE Address LIKE'%Germany%';
CREATE VIEW vCompany2 AS
SELECT Name, Address, Telephone
SELECT * FROM vCompany2;
FROM Company
WHERE Address LIKE '%Japan%'

CREATE VIEW vComSupPro1(ComName, ProdName, Qty) AS


SELECT Company.Name, Product.Name, Quantity
FROM Company INNER JOIN Supply ON Company.CompanyID
= Supply.CompanyID
INNER JOIN Product ON Supply.ProductID = Product.ProductID
5 6

Deleting a view
 Syntax
DROP VIEW view_name;

 Example
DROP VIEW vCompany1;
DROP VIEW vCompany2;
DROP VIEW vComSupPro1;

7 8

You might also like