Fix “Syntax ‘*’ is not allowed in schema-bound objects” in SQL Server (Error 1054)

If you’re getting an error that reads “Syntax ‘*’ is not allowed in schema-bound objects” in SQL Server, it appears that you’re using the asterisk wildcard (*) to select all columns when trying to define a schema-bound object (like a schema-bound view).

As the error message states, this is not allowed.

To fix this issue, explicitly name each column.

Example of Error

Here’s an example of code that produces the error:

CREATE VIEW AllSales WITH SCHEMABINDING AS
SELECT * FROM dbo.Sales;

Output:

Msg 1054, Level 15, State 6, Procedure AllSales, Line 2
Syntax '*' is not allowed in schema-bound objects.

As the message tells us, the asterisk wildcard isn’t allowed in schema bound objects.

This is true even if we use column aliases and prefix the asterisk with the alias:

CREATE VIEW AllSales WITH SCHEMABINDING AS
SELECT s.* FROM dbo.Sales s;

Output:

Msg 1054, Level 15, State 7, Procedure AllSales, Line 3
Syntax '*' is not allowed in schema-bound objects.

Solution

The solution is to explicitly name each column. For example:

CREATE VIEW AllSales WITH SCHEMABINDING AS
SELECT
    SalesId,
    ProductId,
    SaleDate,
    Quantity,
    Price
FROM dbo.Sales;

Output:

Commands completed successfully.

This time it worked.