Views in SQL
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
Student_Marks
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:
Query:
Just like table query, we can query the view to view the data.
Output:
NAME ADDRESS
Stephan Delhi
Kathrin Noida
David Ghaziabad
In the given example, a view is created named MarksView from two tables Student_Detail and
Student_Marks.
Query:
4. Deleting View
A view can be deleted using the Drop View statement.
Syntax
Example:
Index
Indexes are special lookup tables. It is used to retrieve data from the database very fast.
An Index is used to speed up select queries and where clauses. But it shows down the
data input with insert and update statements. Indexes can be created or dropped without
affecting the data.
An index in a database is just like an index in the back of a book.
For example: When you reference all pages in a book that discusses a certain topic,
you first have to refer to the index, which alphabetically lists all the topics and then
referred to one or more specific page numbers.
Syntax
Example
Syntax
Example
Syntax
Example