SQL Error 117 : The %S_MSG name '%.*ls' contains more than the maximum number of prefixes. The maximum is %d
The SQL Server error message 117 typically occurs when a table or column name includes more prefixes than SQL Server allows. In SQL Server, you can only have up to three parts in a qualified name: server.database.schema.object
. If you exceed this limit, you will encounter error 117.
Example Scenario
Consider the following query:
SELECT * FROM server.database.schema.table.column
server.database.schema.table.column
has five parts, which exceeds the maximum allowed number of four (including the server name).Explanation
In SQL Server, the fully qualified names can have the following structure:
server.database.schema.object
For example:
MyServer.MyDatabase.dbo.MyTable
MyDatabase.dbo.MyTable
dbo.MyTable
MyTable
The error occurs when you try to use more than the allowed number of parts.
Solution
Ensure you are not exceeding the four-part naming convention. Here are a few ways to correct the issue:
Option 1: Correct the Naming Convention
Adjust your query to use the correct number of parts:
-- Correct way with four parts
SELECT * FROM MyServer.MyDatabase.dbo.MyTable
-- Correct way with three parts
SELECT * FROM MyDatabase.dbo.MyTable
-- Correct way with two parts
SELECT * FROM dbo.MyTable
-- Correct way with one part
SELECT * FROM MyTable
Sometimes, you may include extra prefixes by mistake. Simplify your query to use the correct qualified names.
Example
If you have the following incorrect query:
SELECT * FROM server.database.schema.table.column
SELECT column FROM server.database.schema.table
SELECT column FROM database.schema.table
To resolve SQL Server error 117, ensure your object names do not exceed the four-part naming convention: server.database.schema.object
. If you find yourself using more than four parts, revise your query to fit within this structure.