Studies show that good grammar leads to more promotions and higher salaries. Write with Grammarly

SQL Server Error Msg 107 – The column prefix does not match with a table name or alias name used in the query

SQL Server Error Message

Msg 107, Level 15, State 1, Line 1
The column prefix ‘STD’ does not match with a table name or alias name used in the query.

Reason for the Error

The actual Error message varies with the Alias being used. The usual message is as shown below.

The column prefix ‘%.*ls’ does not match with a table name or alias name used in the query.

The % in the above can be replaced with the alias that was used and caused the issue.

For example, below are 2 scenarios that will lead to the error msg 107.

  1. When the Column Prefix doesnot correspond to the table or alias name that is used in the SQL query. The below query leads to the error.
SELECT STD.*
FROM [dbo].[Students]

In this query, the alias STD cannot be identified and will result with the “The column prefix ‘STD’ does not match with a table name or alias name used in the query.”.

  1. The table name is specified as a column prefix where as the alias name is supplied in the FROM clause. The below query will result with the error “The column prefix ‘Students’ does not match with a table name or alias name used in the query.”.
SELECT [Students].*
FROM [dbo].[Students] AS STD

Solution

Ensure that the column prefixes matches against the table names in the FROM clause of the query. The above queries that resulted with the error can be fixed as shown below.

SELECT STD.*
FROM [dbo].[Students] AS STD