SQL Server Interview Question #101
What is a view in SQL Server?
Views, Stored Procedures & User-Defined Functions Mid-Level Intermediate
Detailed Explanation
A view is a named, stored SELECT definition that presents data as a virtual table. A regular view normally stores the query definition rather than a separate copy of the result data.
Views are useful for abstraction, simplifying complex joins, presenting a stable interface to consumers, and restricting access to selected columns or rows. Performance still depends on the underlying tables, indexes, predicates, and execution plan.
Code Example
CREATE VIEW dbo.vw_ActiveProducts
AS
SELECT Id, Name, Price, CategoryId
FROM dbo.Products
WHERE IsActive = 1;
GO
SELECT *
FROM dbo.vw_ActiveProducts;