"Creates a virtual table whose contents (columns and rows) are defined by a query. Use this statement to create a view of the data in one or more tables in the database. For example, a view can be used for the following purposes:
- To focus, simplify, and customize the perception each user has of the database.
- As a security mechanism by allowing users to access data through the view, without granting the users permissions to directly access the underlying base tables.
- To provide a backward compatible interface to emulate a table whose schema has changed." [1]
Beside that, our team used view in order to improve the performance of our web apps when a database has a very complicated relationship between its tables by using ORM Frameworks such as Hibernate.
Example code:
--create
CREATE VIEW placeholders
AS
SELECT EMPKEY AS empkey, CONNUMB AS connumb, EMPNBR AS empNbr, ACEEMPN AS empFirstName, ACEEMPFN AS empLastName, EMPNAM AS empFullName,
EMPSIGN AS empSign, AECSALUT AS empSalutation, AECTITLE AS empTitle
FROM dbo.HRMAEC
--update
ALTER VIEW placeholders AS
SELECT EMPKEY AS empkey, CONNUMB AS connumb, EMPNBR AS empNbr, ACEEMPN AS empFirstName, ACEEMPFN AS empLastName, EMPNAM AS empFullName1,
EMPSIGN AS empSign, AECSALUT AS empSalutation, AECTITLE AS empTitle,AECEMAIL As empEmail
FROM HRMAEC
-- drop
DROP VIEW placeholders
--select
SELECT * FROM placeholders
WHERE empkey = 1 AND connumb = 1
Reference:
[1]. https://msdn.microsoft.com/en-us/library/ms187956.aspx