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 ;

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

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

select *
     from test_vw ;
This entry was posted in Joy of T-SQL. Bookmark the permalink.

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s