SQL views are virtual tables created by the user. SQL views can also be considered as a subset of tables.
SQL views provide security features to users as they can be used to keep the main table safe or inaccessible to others.
Syntax of Views:
CREATE VIEWS view_name AS < SQL STATEMENTS > ;
CREATE OR REPLACE VIEW view_name AS < UPDATED sql COMMANDS > ;
DROP VIEW view_name ;
We will use the following table to show the SQL views use:
Now lets create a view that stores rows with subject = ‘Subject1’
CREATE VIEW SUB1_DATA AS SELECT * FROM STUDENTS WHERE SUBJECT = 'Subject1' ;
After executing the above code, you can check it in Views folder.
You can execute the newly created views just like tables.
SELECT * FROM SUB1_DATA ;
You can also use SQL VIEWS WITH SQL JOINS and combine two tables into one table.
Thanks For Reading!
SOURCE: Microsoft T-SQL Documentation