tags:

views:

71

answers:

5

Possible Duplicate:
What are views good for?

hi, i have a doubt what is a view. where should we use and what is the use of view. is there any good reference for views. thank you

+2  A: 

See Views in SQL Server for a good overview.

A view is a virtual table that consists of columns from one or more tables. Though it is similar to a table, it is not stored in the database. It is a query stored as an object. Hence, a view is an object that derives its data from one or more tables. These tables are referred to as base or underlying tables.

Galwegian
if i delete one of the column of base table then what about the view
Surya sasidhar
@Surya - your view won't work if you delete an underlying column... you'll have to edit your view to match the new schema.
Galwegian
ya ok Mr.s Galwegian
Surya sasidhar
can we write insert query on views?
Surya sasidhar
+1  A: 

Views are essentially "Queries" that you can select from without touching the main tables.

Any select query that you normally do (multiple tables, functions, etc.) could be a view.

There are two main advantages of views.

The first is that they allow you to reuse common ways of looking at the data without having to write the same complex SQL over and over (ie, modularization).

The second is that you can tighten security on the source tables for the particular user while allowing them to see the data through the views.

Tom Hubbard
if i write the view on emp table. suppose if the emp table consist 5 rows and i create a view. and i inserted a new row in emp table then the newly created row will display in the view?
Surya sasidhar
Yes. Behind the scenes the view will always be run on the source table every time you use it.
Tom Hubbard
ok, so views are used for security of the base table
Surya sasidhar
can we apply update query for the views
Surya sasidhar
RE: "the view will always be run on the source table every time you use it" There are Materialised/Indexed Views in some implementations that muddy the waters a bit here.
Martin Smith
Yes. Materialized views are a different beast. I do believe some views can be updated but I'm not sure to what extent.
Tom Hubbard
if we changse the base table structure it will reflect on the views
Surya sasidhar
It's not automatic, you might have to adapt the view.In postgreSQL you can get the effect of an updatable view by creating rules that rewrite inserts, etc. on the view into appropriate actions on other tables.Information is found on the following links:http://www.postgresql.org/docs/8.2/static/sql-createview.htmlhttp://www.postgresql.org/docs/8.2/static/sql-createrule.html
pcent
A: 

In addition to the other answers another advantage of Views can be data independence. It is sometimes possible to change the structure of the database without altering existing applications by providing a View simulating the old structure.

(Following your comment to another answer) If the View does not itself meet the criteria for an Updatable View then this may require the use of INSTEAD OF triggers.

Martin Smith
A: 

Here you can see advantages/disadvantages of views sql views

Bakhtiyor
ya nice one Mr. Bakhtiyor
Surya sasidhar
A: 
Will Marcouiller