Ad
AACSB-accredited MBA
University of Adelaide Apply Now
Home DBMS SQL PL/SQL SQLite MongoDB Cassandra MySQL Oracle CouchDB Neo4j DB2 C Java Projects Interview Q
⇧ SCROLL TO TOP
Views in SQL
Views in SQL are considered as a virtual table. A view also contains rows and
columns.
To create the view, we can select the fields from one or more tables present in the
database.
A view can either have specific rows based on certain condition or all the rows of a
table.
Sample table:
Student_Detail
STU_ID NAME ADDRESS
1 Stephan Delhi
2 Kathrin Noida
3 David Ghaziabad
4 Alina Gurugram
Student_Marks
ADVERTISEMENT
ADVERTISEMENT
STU_ID NAME MARKS AGE
1 Stephan 97 19
2 Kathrin 86 21
3 David 74 18
4 Alina 90 20
5 John 96 18
1. Creating view
A view can be created using the CREATE VIEW statement. We can create a view from
a single table or multiple tables.
Syntax:
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE condition;
2. Creating View from a single table
Earn $2.5
per answer
Make money from answering
simple questions. We pay you
in cash. Simple and fun.
MetroOpinion
In this example, we create a View named DetailsView from the table Student_Detail.
Query:
CREATE VIEW DetailsView AS
SELECT NAME, ADDRESS
FROM Student_Details
WHERE STU_ID < 4;
Just like table query, we can query the view to view the data.
SELECT * FROM DetailsView;
Output:
NAME ADDRESS
Stephan Delhi
Kathrin Noida
David Ghaziabad
3. Creating View from multiple tables
View from multiple tables can be created by simply include multiple tables in the
SELECT statement.
In the given example, a view is created named MarksView from two tables
Student_Detail and Student_Marks.
Query:
CREATE VIEW MarksView AS
SELECT Student_Detail.NAME, Student_Detail.ADDRESS, Student_Marks.MARKS
FROM Student_Detail, Student_Mark
WHERE Student_Detail.NAME = Student_Marks.NAME;
To display data of View MarksView:
SELECT * FROM MarksView;
NAME ADDRESS MARKS
Stephan Delhi 97
Kathrin Noida 86
David Ghaziabad 74
Alina Gurugram 90
4. Deleting View
A view can be deleted using the Drop View statement.
Syntax
DROP VIEW view_name;
Example:
If we want to delete the View MarksView, we can do this as:
DROP VIEW MarksView;
← Prev Next →
Youtube For Videos Join Our Youtube Channel: Join Now
Feedback
Send your Feedback to feedback@javatpoint.com
Help Others, Please Share
Learn Latest Tutorials
Splunk SPSS tutorial Swagger T-SQL Tumblr
tutorial SPSS
tutorial tutorial tutorial
Splunk Swagger Transact-SQL Tumblr
React tutorial Regex
tutorial
ReactJS
Regex
R RxJS tutorial
Reinforcement Programming RxJS
learning tutorial
tutorial
R Programming
Reinforcement
Learning
React Native Python Python Python Keras
tutorial Design Patterns Pillow tutorial Turtle tutorial tutorial
React Native Python Design Python Pillow Python Turtle Keras
Patterns
Preparation
Aptitude Logical Verbal Interview Company
Aptitude
Reasoning Ability Questions Interview
Reasoning Verbal Ability Interview
Questions
Questions Company
Questions
Trending Technologies
Artificial AWS Tutorial Selenium Cloud Hadoop
Intelligence AWS
tutorial Computing tutorial
Artificial Selenium Cloud Computing Hadoop
Intelligence
ReactJS Data Science Angular 7 Blockchain Git Tutorial
Tutorial Tutorial Tutorial Tutorial Git
ReactJS Data Science Angular 7 Blockchain
Machine DevOps
Learning Tutorial
Tutorial
DevOps
Machine
Learning
B.Tech / MCA
DBMS Data DAA tutorial Operating Computer
tutorial Structures DAA
System Network
DBMS
tutorial Operating
tutorial
Data Structures System Computer
Network
Compiler Computer Discrete Ethical Computer
Design tutorial Organization Mathematics Hacking Graphics
Compiler Design
and Tutorial Ethical Hacking
Tutorial
Architecture Discrete Computer
Computer Mathematics Graphics
Organization
Software html tutorial Cyber Automata C Language
Engineering Web Technology
Security Tutorial tutorial
Software
tutorial Automata C Programming
Engineering Cyber Security
C++ tutorial Java tutorial .Net Python List of
C++ Java
Framework tutorial Programs
tutorial
Python Programs
.Net
Control Data Mining Data
Systems Tutorial Warehouse
tutorial Data Mining
Tutorial
Control System Data Warehouse