XPost: microsoft.public.sqlserver.programming   
   From: hugo@perFact.REMOVETHIS.info.INVALID   
      
   On Wed, 05 Jan 2011 14:55:30 -0800, Gene Wirchenko    
   wrote:   
      
   (snip)   
   > What gives? Why is WITH SCHEMABINDING required?   
      
   Hi Gene,   
      
   Consider this simple example:   
      
   CREATE VIEW dbo.v1 WITH SCHEMABINDING   
   AS SELECT CAST(1 AS int) AS a;   
   go   
   CREATE FUNCTION dbo.f2()   
   RETURNS TABLE --WITH SCHEMABINDING   
   AS RETURN (SELECT a FROM dbo.v1) ;   
   go   
   SELECT * FROM dbo.f2();   
   SELECT * FROM dbo.f2();   
   go   
   SELECT OBJECTPROPERTYEX(OBJECT_ID('dbo.f2'), 'IsDeterministic')   
   SELECT OBJECTPROPERTYEX(OBJECT_ID('dbo.f2'), 'IsPrecise')   
   go   
   ALTER VIEW dbo.v1   
   AS SELECT CAST(CURRENT_TIMESTAMP AS float) AS a;   
   go   
   SELECT * FROM dbo.f2();   
   SELECT * FROM dbo.f2();   
   go   
   DROP FUNCTION dbo.f2;   
   DROP VIEW dbo.v1;   
   go   
      
   Without schemabinding, there is no link between the function and the   
   underlying view. When the view changes, the properties of the function   
   would not change, but they would no longer be correct.   
   --   
   Hugo Kornelis, SQL Server MVP   
   My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|