SQL Server Interview Question #105

What is WITH SCHEMABINDING in a view?

Views, Stored Procedures & User-Defined Functions Mid-Level Intermediate

Detailed Explanation

WITH SCHEMABINDING binds the view definition to referenced objects so changes that would invalidate the view cannot be made without first addressing the schema-bound dependency.

Schema-bound object references must follow SQL Server's required naming rules, including two-part names such as dbo.Products. SCHEMABINDING is required for indexed views and can also be used for other schema-bound modules.

Code Example

CREATE VIEW dbo.vw_ProductBase
WITH SCHEMABINDING
AS
SELECT Id, Name, Price
FROM dbo.Products;
GO