SQL SERVER - View

Thursday, 10 November 2011

SQL SERVER - View


View is a virtual table whose contents (columns and rows) are defined by a query.In SQL Server, a view is a pre-written query that is stored on the database. A view consists of a SELECT statement, and when you run the view, you see the results of it like you would when opening a table.


Benefits of Views
A view can be useful when there are multiple users with different levels of access, who all need to see portions of the data in the database (but not necessarily all of the data). Views can do the following:

* Restrict access to specific rows and columns in a table.
* Join columns from multiple tables and present them as though they are part of a single table.

Creating a View
You create a view by using the CREATE VIEW statement, followed by the SELECT statement.

 CREATE VIEW ViewName
   AS
SELECT query

Modifing a View
You can modify an existing view by using using ALTER instead or CREATE.

 ALTER VIEW ViewName
   AS
SELECT query

Running a View
You run a view by using a SELECT statement.

 SELECT *  FROM ViewName

No comments:

Post a comment