Friday, October 1, 2010

Create view and force source tables to stay valid

In this example I have a table called dbo.customers with (FN,LN, address, Phone) columns

--creates the view
Create view vw_customers

as
--only two columns are selected (FN,LN)
Select FN, LN
from customers

with Schemabinding

So. If you attempt to drop the the customers table , SQL will return " can not drop table with reference."