SQL VIEWS Statement

A VIEW is nothing more than a SQL statement that is stored in the database with an associated name.

VIEW is a virtual table, through which a selective portion of the data from one or more tables can be seen. Views do not contain data of their own. It used to restrict access to the database or to hide data complexity.

CREATE VIEW Syntax

CREATE VIEW view_name AS
SELECT column1, column2, column3, ....
FROM table_name
WHERE [condition];

SQL CREATE VIEW Statement

  • You can add SQL FUNCTIONS, WHERE Condition, and JOIN Statements to a view and present the data as if the data were coming from one single table.
  • A VIEW always shows up-to-date data.
  • The database engine recreates the data, using the view's SQL statement, every time a user queries a view.
  • A VIEW in SQL is a logical subset of data from one or more tables.

CREATE or REPLACE VIEW Syntax

A VIEW can be UPDATED with the CREATE OR REPLACE VIEW Command Syntax:

CREATE OR REPLACE VIEW view_name AS
SELECT column1, column2, column3, ....
FROM table_name
WHERE [condition];

UPDATING A VIEW Condition

  • The SELECT statement should not include GROUP BY or ORDER BY or HAVING clause.
  • The SELECT statement may not contain the keyword DISTINCT, SUMMARY functions, SET functions, and SET operators.
  • The FROM clause should not contain multiple tables.
  • The View should have all NOT NULL values.

INSERT a ROW in a VIEW Syntax

INSERT INTO VIEW view_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

DROP A VIEW Syntax

If you want to delete a VIEW use DROP VIEW Command Syntax:

DROP VIEW view_name;

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

© 2023 GDATAMART.COM (All Rights Reserved)