CREATE VIEW view_EmployeeInfo AS SELECT EmployeeID, FirstName, LastName, HireDate FROM Employee GO
可以像表一样选择视图中的行:
SELECT FirstName FROM view_EmployeeInfo
您也可以创建带有计算列的视图。我们可以通过添加计算列来修改上面的视图,如下所示:
CREATE VIEW view_EmployeeReport AS SELECT EmployeeID, FirstName, LastName, Coalesce(FirstName,'') + ' ' + Coalesce(LastName,'') as FullName, HireDate FROM Employee GO
此视图添加了另外一列,当您SELECT从该行中行时将出现该列。此附加列中的值将取决于字段FirstName和LastName表中的值,并且在Employee更新这些字段时将自动更新后台信息。