Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I'm trying to create a view with schemabinding. For I got the error:
Cannot schema bind view 'nameOfMyTable.vSomethingAddedHere' because name 'nameOfMyTable' is invalid for schema binding.


In order to avoid the error, I tried to use the two-part name (schema.object) but it didn't work.


I previously crated a schema for the table
nameOfMyTable
in order to create the view.

What I have tried:

CREATE VIEW nameOfMyTable.vSomethingAddedHereWITH Schemabinding
AS
SELECT b.Name
FROM [dbo.][nameOfMyTable][n]
INNER JOIN Tickets t ON [n].ID = t.ID
INNER JOIN Peple p ON p.ID = t.ID
Posted
Updated 6-Nov-20 1:37am

1 solution

Quote:
SQL
FROM [dbo.][nameOfMyTable][n]
That's a syntax error. You've put the separator (.) inside the square brackets.

Try:
SQL
CREATE VIEW nameOfMyTable.vSomethingAddedHere
WITH Schemabinding
AS
    SELECT b.Name
    FROM [dbo].[nameOfMyTable] [n]
    INNER JOIN Tickets t ON [n].ID = t.ID
    INNER JOIN Peple p ON p.ID = t.ID
 
Share this answer
 
Comments
xhon 6-Nov-20 8:00am    
thank you very much!
xhon 9-Nov-20 12:30pm    
I have a doubt: can we call a view by using a variable or it's not allowed because it doesn't output a scalar value?
Given that I can't write the following code because I should provide a data type for the variable and the table doesn't have a datatype, is there any other way to provide a variabile?

DECLARE @myView = name_Of_the_View;
S£LECT * FROM @myView

I suppose I should
Richard Deeming 9-Nov-20 13:09pm    
No, you can't use a variable to refer to a table or view name. You'd have to use dynamic SQL for that, which would potentially leave you open to a SQL injection vulnerability.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900