A view is quite easy to define, but a lot more difficult to create, use and manage. It\u2019s not anymore than a named SELECT statement, or a virtual table. You can select data, alter data, remove data and all other things you can do with a table (with some limitations). But there is a difference between a view and a table. The data accessible through a view is not stored in the database as its own object. It\u2019s stored in the underlying tables that make up the view. The only thing that is stored in the database is the SELECT statement that forms the virtual table . Once you have defined a view, you can reference it like any other table in a database.
A view serves as a security mechanism. This ensures that users are able to retrieve and
modify only the data seen by them. Users cannot see or access the remaining data in the
underlying tables. A view also serves as a mechanism to simplify query execution.
Complex queries can be stored in the form as a view, and data from the view can be
extracted using simple queries.
A view can be used to limit the user to only use a few columns in a table. For
example if we do not want a user to be able to access all columns because of
security. But it could also be because not all columns are interesting for the user.
It is also possible to limit access to rows, using a WHERE clause. If we use
USER_ID(), we can even find out who is using the view, and return only data that
is relevant for this user. Furthermore, a view can join several tables, in several
databases on several servers, but all the user use is the view\u2019s name. Simple, but
We can also use a view to manipulate data. Often with a relational database
design, this means that many tables must be joined together. Using a view can
simplify this, and the users do not need to know all tables involved.
A so called Partition View can be used to merge data from multiple tables in
multiple databases, so it appears as one table only, but it is in fact several tables.
This can be accomplished by using the UNION operator.
Consider the Publishers table below. If you want users to see only two columns in the
table, you can create a view called vwPublishers that will refer to the Publishers table and
the two columns required. You can grant Permissions to users to use the view and revoke
Permissions from the base Publishers table. This way, users will be able to view only the
two columns referred to by the view. They will not be able to query on the Publishers
AS select_statement [WITH CHECK OPTION]
view_name specifies the name of the view and must follow the rules for identifiers.
column_name specifies the name of the column to be used in view. If the column_name
WITH ENCRYPTION encrypts the text for the view in the syscomments table.
AS specifies the actions that will be performed by the view.
select_statement specifies the SELECT Statement that defines a view. The view may use
WITH CHECK OPTION forces the data modification statements to fulfill the criteria
given in the SELECT statement defining the view. It also ensures that the data is visible
after the modifications are made permanent.
This action might not be possible to undo. Are you sure you want to continue?