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.
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
SELECT column1, column2.....
FROM table_name
WHERE condition;
- Creating View from a single table
SELECT NAME, ADDRESS
FROM Student_Details
WHERE STU_ID < 4;
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.
SELECT Student_Detail.NAME, Student_Detail.ADDRESS, Student_Marks.MARKS
FROM Student_Detail, Student_Mark WHERE Student_Detail.NAME = student_Marks.NAME;
DROP VIEW view_name;
Comments
Post a Comment