Mar 15, 2012

Cannot schema bind view '' because name '' is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.


When we create view with SCHEMABINDING it is necessary to specify the schema name in objects name of SELECT statement. If we will execute following query:

CREATE VIEW view_StuInfo WITH SCHEMABINDING
AS
SELECT Age,Name FROM Student

We will get error message:

Cannot schema bind view 'view_StuInfo' because name 'Student' is invalid for schema binding. Names must be in two-part format and an object cannot reference itself.

Solution:

CREATE VIEW view_StuInfo WITH SCHEMABINDING
AS
SELECT Age,Name FROM dbo.Student

7 comments:

  1. Anonymous7/19/2012

    Thanks a lot..
    You saved my day !!

    ReplyDelete
  2. Anonymous8/07/2012

    mine too :)

    thanx

    ReplyDelete
  3. Anonymous6/01/2013

    Simple and helpful. Thanks! :D

    ReplyDelete
  4. Anonymous7/19/2013

    Thanks!!

    ReplyDelete
  5. Anonymous8/07/2013

    Muchas Gracias..!!! :D me ha funciona magnifico

    ReplyDelete
  6. hi.. how about [MYDB].[dbo].[MAINT_PASSDOWN]?
    I need to query with DBname. Here is teh error:
    Cannot schema bind view 'view_StuInfo' because name MYDB.dbo.MAINT_PASSDOWN' is invalid for schema binding.

    ReplyDelete
    Replies
    1. It is limitation of schema binding. You cannot bind the tables of different databases. You must have to specify only two part name of object like "Schema Name"."Table Name"

      If all the tables are in the same database then you should create view in that database and then you can reference it in any database.

      Delete