SCHEMABINDING

SCHEMABINDING is a property that very useful for safety in views. If anyone wanna to change the table column that our view use it, “SCHEMABINDING” do not allow that chang. In some cases such as “Indexed views”, using “SCHEMABINDING” in view creation script is mandatory.

if object_id('test_vw') is not null
   drop view test_vw ;
go

-- This is just an example to show how to use "SCHEMABINDING"
-- Don't worry about OrderDetails structure

create view test_vw
     with SCHEMABINDING
     as
     select a.orderid id
          , a.productid pid
          , a.qty qtty
          , max(a.qty) over ( partition by a.orderid ) maxy
          from Sales.OrderDetails a ;
go

select *
     from test_vw ;
Advertisements