SQL 对象名称包含超过最大数量的前缀。最大值为 3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26119343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 02:43:20  来源:igfitidea点击:

The object name contains more than the maximum number of prefixes. The maximum is 3

sqlsql-servertsql

提问by guyh92

My stored procedure is trying to write a record in to a database on another Server. The statement is here:

我的存储过程正在尝试将记录写入另一台服务器上的数据库。声明在这里:

IF @Builds > 0
   BEGIN
        SET @DPU = @Failures / @Builds
        INSERT INTO SQL05.ManufacturingPortal.dbo.OPC.WriteRequests (ID, RegisterID, Value, RequestedDate, IsCompleted)
        VALUES(@PLCID, 'F8:10' , CAST(@DPU AS NUMERIC(10,2)), GETDATE(), 0)    
    END 

However when I try to create the stored procedure - I get the following error:

但是,当我尝试创建存储过程时 - 我收到以下错误:

The object name 'SQL05.ManufacturingPortal.dbo.OPC.WriteRequests' contains more than 
the maximum number of prefixes. The maximum is 3.

I have tried creating an alias of Server.DB.DBO to shorten the number of prefixes however seem to be implementing this wrong.

我曾尝试创建 Server.DB.DBO 的别名来缩短前缀的数量,但似乎实现了这个错误。

I cannot change my database schema on the target DB. Any suggestions on how I can get around this?

我无法更改目标数据库上的数据库架构。关于如何解决这个问题的任何建议?

Thanks Guy

哥们,谢啦

采纳答案by Arvo

Correct four-part table name is server.database.schema.tablename - you have some excess parts there.

正确的四部分表名称是 server.database.schema.tablename - 你有一些多余的部分。

Looks like table name is OPC.WriteRequests? If yes, then you have to use brackets: SQL05.ManufacturingPortal.dbo.[OPC.WriteRequests]

看起来表名是 OPC.WriteRequests?如果是,那么您必须使用括号:SQL05.ManufacturingPortal.dbo.[OPC.WriteRequests]

But maybe you just have some part of name incorrect?

但也许您只是名称的某些部分不正确?

回答by Taylor Buchanan

The reason you are receiving the error is because you are not using a valid name. You appear to be referencing two schemata, dboand OPC.

您收到错误的原因是您没有使用有效的名称。您似乎在引用两个模式,dboOPC.

The valid syntax is server_name.database_name.schema_name.object_nameas referenced on the MSDN articlefor INSERT.

有效的语法是server_name.database_name.schema_name.object_name对作为参考MSDN的文章INSERT

Remove the incorrect schema and try again.

删除不正确的架构并重试。

回答by sree

I was using everything correct still the issue persisted. My command was like below

我使用的一切都是正确的,但问题仍然存在。我的命令如下

select * into server.database.schema.table from table2

I resolved it by creating the table in the server first and then used the insert into statement which executed without issues

我通过首先在服务器中创建表来解决它,然后使用插入到没有问题的语句执行

Create Table...........
Insert into server.database.schema.table  select * from table2

Thanks, Sree

谢谢,斯里

回答by undrline

In my case, it actually wanted to be run on the server where the INTO table would live:

就我而言,它实际上希望在 INTO 表所在的服务器上运行:

SELECT * 
INTO [database].[schema].[table] 
FROM [server].[database].[schema].[table]

回答by Arashtala

use with braket "[]" for name and remote database server like this. [87.247.678.80,1666].[danesfe].[admin1].[homefarsi]

使用刹车“[]”作为名称和远程数据库服务器,就像这样。[87.247.678.80,1666].[danesfe].[admin1].[homefarsi]

回答by praloy

I had similar issues where I was getting the message when I was trying to execute the following code(make table)

我在尝试执行以下代码(制作表)时收到消息时遇到了类似的问题

"into SalesCube_temp.SalesCube_temp.dbo.ALL_SUPPLIER_SALES_METRICS_I"

"into SalesCube_temp.SalesCube_temp.dbo.ALL_SUPPLIER_SALES_METRICS_I"

I then Realized that I was using the incorrect Syntax and then rectified as

然后我意识到我使用了不正确的语法,然后更正为

"into SalesCube_temp.dbo.ALL_SUPPLIER_SALES_METRICS_I"

"into SalesCube_temp.dbo.ALL_SUPPLIER_SALES_METRICS_I"

IT WORKED, END OF MY STORY. But I spent nearly 10 to 15 minutes tr

成功了,我的故事到此结束。但我花了将近 10 到 15 分钟 tr

Hope it will help somebody.

希望它会帮助某人。

回答by Raghav sharma

Please change the tables from the start and try to insert with the normal way

请从一开始就更改表格并尝试以正常方式插入

Use ManufacturingPortal 

IF @Builds > 0

   BEGIN

       SET @DPU = @Failures / @Builds

       INSERT INTO OPC.WriteRequests (ID, RegisterID, Value, RequestedDate, IsCompleted)
       VALUES(@PLCID, 'F8:10' , CAST(@DPU AS NUMERIC(10,2)), GETDATE(), 0)    

   END 

回答by Balaram tej

I had the same issue. The problem was due to the following mistake: instead of passing textbox1.textas argument to the query being called from code-behind i passed textbox1.

我遇到过同样的问题。问题是由于以下错误:而不是textbox1.text作为参数传递给从代码隐藏调用的查询,我传递了textbox1.

Hope it helps

希望能帮助到你