articles

Home / DeveloperSection / Articles / What Are Views?

What Are Views?

Anonymous User 3078 10-Jul-2017

A view in a database is a "virtual" table. It is created using scripts and stored in a structural form, but they are not stored as a data in any part of the database. It can be part or whole of an existing table.

Simply, Views is a query’s code saved under a name,

Basically, every time you call a view, the view’s code which is query is being executed and you are querying the result set of that code. It is like an identifier which contains data or stored information as a query.

Technically there might be all kind of performance optimizations involved.

For e.g.:- Let say You want to access marks of those student having marks
between 40 to 50 in different section of your project then ,

SELECT * 
FROM student
WHERE marks BETWEEN 40 AND 50

Every time you'll have to write this query to make it possible. So, to make this job easy, we have views. Create a view in the database that stores the above query with condition of marks between 40 and 50.
So let’s create a view for the above query:


CREATE VIEW marksanalyzer
AS
SELECT *
FROM student
WHERE marks BETWEEN 40 AND 50

(this will stored in the database)

So, from now, you can simply write the query SELECT * FROM marksanalyzer. This gives you the illusion of the existence of a table containing data of student marks 40-50, but there's no such table -- just a "view."

It also gives you the benefits of specifying just the necessary fields. Say, you need only two fields student_id and student_name columns from student table for those marks between 45-60, You can go with this:

CREATE VIEW marksanalyzer45to60
AS
  SELECT student_id, student_name
  FROM student
  WHERE marks BETWEEN 45 AND 60
(resides in the dB)

And later use the simple query SELECT * FROM marksanalyzer45to60

This will give you just the two columns for those student having marks between 45 and 60.

 

 


Updated 26-Dec-2017
I am a content writter !

Leave Comment

Comments

Liked By