Tutorial by Examples

CREATE VIEW view_EmployeeInfo AS SELECT EmployeeID, FirstName, LastName, HireDate FROM Employee GO Rows from views can be selected much like tables: SELECT FirstName FROM view_EmployeeInfo You may also create a view with a calculated column. We can...
CREATE VIEW view_EmployeeInfo WITH ENCRYPTION AS SELECT EmployeeID, FirstName, LastName, HireDate FROM Employee GO
CREATE VIEW view_PersonEmployee AS SELECT P.LastName, P.FirstName, E.JobTitle FROM Employee AS E INNER JOIN Person AS P ON P.BusinessEntityID = E.BusinessEntityID GO Views can use joins to select data from numerous sources like tables, table functio...
To create a view with an index, the view must be created using the WITH SCHEMABINDING keywords: CREATE VIEW view_EmployeeInfo WITH SCHEMABINDING AS SELECT EmployeeID, FirstName, LastName, HireDate FROM [dbo].Employee GO Any clustered or non-clustered ...
A grouped VIEW is based on a query with a GROUP BY clause. Since each of the groups may have more than one row in the base from which it was built, these are necessarily read-only VIEWs. Such VIEWs usually have one or more aggregate functions and they are used for reporting purposes. They are also h...
VIEWs based on a UNION or UNION ALL operation are read-only because there is no single way to map a change onto just one row in one of the base tables. The UNION operator will remove duplicate rows from the results. Both the UNION and UNION ALL operators hide which table the rows came from. Such VIE...

Page 1 of 1