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
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:

WordPress.com Logo

You are commenting using your WordPress.com 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