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

SQL SQL Views

A view is a virtual table created by a SQL query on one or more tables. Views can be created using the CREATE VIEW statement, specifying a view name and SELECT query. Views behave like tables but do not store data physically. Views can be updated using CREATE OR REPLACE VIEW and dropped using DROP VIEW.

Uploaded by

anamikahs
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

SQL SQL Views

A view is a virtual table created by a SQL query on one or more tables. Views can be created using the CREATE VIEW statement, specifying a view name and SELECT query. Views behave like tables but do not store data physically. Views can be updated using CREATE OR REPLACE VIEW and dropped using DROP VIEW.

Uploaded by

anamikahs
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

SQL: VIEWS

A view is, in essence, a virtual table. It does not physically exist. Rather, it is created by a query joining one or more
tables.

Creating a VIEW

The syntax for creating a VIEW is:

CREATE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

For example:

CREATE VIEW sup_orders AS


SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id
and suppliers.supplier_name = 'IBM';

This would create a virtual table based on the result set of the select statement. You can now query the view as
follows:

SELECT *
FROM sup_orders;

Updating a VIEW

You can update a VIEW without dropping it by using the following syntax:

CREATE OR REPLACE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

SQL: VIEWS

A view is, in essence, a virtual table. It does not physically exist. Rather, it is created by a query joining one or more
tables.

Creating a VIEW

The syntax for creating a VIEW is:


SQL: VIEWS

A view is, in essence, a virtual table. It does not physically exist. Rather, it is created by a query joining one or more
tables.

Creating a VIEW

The syntax for creating a VIEW is:

CREATE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

For example:

CREATE VIEW sup_orders AS


SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id
and suppliers.supplier_name = 'IBM';

This would create a virtual table based on the result set of the select statement. You can now query the view as
follows:

SELECT *
FROM sup_orders;

Updating a VIEW

You can update a VIEW without dropping it by using the following syntax:

CREATE OR REPLACE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

CREATE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

For example:

CREATE VIEW sup_orders AS


SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers, orders
SQL: VIEWS

A view is, in essence, a virtual table. It does not physically exist. Rather, it is created by a query joining one or more
tables.

Creating a VIEW

The syntax for creating a VIEW is:

CREATE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

For example:

CREATE VIEW sup_orders AS


SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id
and suppliers.supplier_name = 'IBM';

This would create a virtual table based on the result set of the select statement. You can now query the view as
follows:

SELECT *
FROM sup_orders;

Updating a VIEW

You can update a VIEW without dropping it by using the following syntax:

CREATE OR REPLACE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

WHERE suppliers.supplier_id = orders.supplier_id


and suppliers.supplier_name = 'IBM';

This would create a virtual table based on the result set of the select statement. You can now query the view as
follows:

SELECT *
FROM sup_orders;
SQL: VIEWS

A view is, in essence, a virtual table. It does not physically exist. Rather, it is created by a query joining one or more
tables.

Creating a VIEW

The syntax for creating a VIEW is:

CREATE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

For example:

CREATE VIEW sup_orders AS


SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id
and suppliers.supplier_name = 'IBM';

This would create a virtual table based on the result set of the select statement. You can now query the view as
follows:

SELECT *
FROM sup_orders;

Updating a VIEW

You can update a VIEW without dropping it by using the following syntax:

CREATE OR REPLACE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

Updating a VIEW

You can update a VIEW without dropping it by using the following syntax:

CREATE OR REPLACE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;
SQL: VIEWS

A view is, in essence, a virtual table. It does not physically exist. Rather, it is created by a query joining one or more
tables.

Creating a VIEW

The syntax for creating a VIEW is:

CREATE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

For example:

CREATE VIEW sup_orders AS


SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id
and suppliers.supplier_name = 'IBM';

This would create a virtual table based on the result set of the select statement. You can now query the view as
follows:

SELECT *
FROM sup_orders;

Updating a VIEW

You can update a VIEW without dropping it by using the following syntax:

CREATE OR REPLACE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

For example:

CREATE or REPLACE VIEW sup_orders AS


SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id
and suppliers.supplier_name = 'Microsoft';

Dropping a VIEW
SQL: VIEWS

A view is, in essence, a virtual table. It does not physically exist. Rather, it is created by a query joining one or more
tables.

Creating a VIEW

The syntax for creating a VIEW is:

CREATE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

For example:

CREATE VIEW sup_orders AS


SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id
and suppliers.supplier_name = 'IBM';

This would create a virtual table based on the result set of the select statement. You can now query the view as
follows:

SELECT *
FROM sup_orders;

Updating a VIEW

You can update a VIEW without dropping it by using the following syntax:

CREATE OR REPLACE VIEW view_name AS


SELECT columns
FROM table
WHERE predicates;

The syntax for dropping a VIEW is:

DROP VIEW view_name;

For example:

DROP VIEW sup_orders;

You might also like