Back to results for “Security”
SQL Server › Views

How would you design a layered set of views to progressively simplify a complex data model for different types of users, such as analysts versus casual business users?

Advanced

Answer

You might create a base set of views that join and clean up the raw underlying tables for analysts who need reasonably detailed access, and then build additional views on top of those base views that further aggregate or simplify the data specifically for casual business users, creating a layered structure where each group interacts with a view appropriately suited to their specific needs and technical comfort level.
-- Base view for analysts
CREATE VIEW dbo.OrderDetails AS SELECT * FROM Orders o JOIN Customers c ON o.CustomerId = c.CustomerId;

-- Simplified view built on top, for business users
CREATE VIEW dbo.MonthlySalesSummary AS
SELECT YEAR(OrderDate) AS SalesYear, MONTH(OrderDate) AS SalesMonth, SUM(Amount) AS TotalSales
FROM dbo.OrderDetails GROUP BY YEAR(OrderDate), MONTH(OrderDate);
Real-world example A company builds a layered set of views, giving their data analysts access to detailed order level views while giving executives a much simpler monthly summary view built directly on top, each seeing exactly the level of detail appropriate for their needs.

Common follow-ups: Does building views on top of other views introduce any performance concerns?;How do you manage permissions differently across these layered views for different user groups?