简体   繁体   English

无法执行存储过程

[英]Can't execute stored procedure

I have created a stored procedure and can see it under the stored procedure node, but when trying to execute it doesn't find the procedure.我已经创建了一个存储过程并且可以在存储过程节点下看到它,但是在尝试执行时它没有找到该过程。

Under stored procedure node it is called dbo.CopyTable在存储过程节点下,它被称为 dbo.CopyTable

exec CopyTable 

CopyTable is undefined in red saying it does not exist. CopyTable 未定义为红色,表示它不存在。 Why?为什么?

Even if I right-click on the procedure and say script stored procedure as execute to - the code it generates is underlined in red and cant find stored procedure either.即使我右键单击该过程并说脚本存储过程作为执行 - 它生成的代码用红色下划线标出并且也找不到存储过程。

Ensure that the database selected contains the stored procedure CopyTable确保选择的数据库包含存储过程CopyTable

USE YourDatabase
EXEC CopyTable

Try adding dbo and selecting the right database,尝试添加dbo并选择正确的数据库,

USE databaseName
GO

EXEC dbo.CopyTable
GO

Most likely you are just in the wrong database in the query window, you can specify the database like this:很可能您只是在查询窗口中错误的数据库中,您可以像这样指定数据库:

EXEC [yourDBName].dbo.CopyTable

Reading on how to Execute a Stored Procedure阅读如何执行存储过程

Considering your updated question:考虑到您更新的问题:

Even if i rightclick on the procedure and say script stored procedure as execute to - the code it generates is underlined in red and cant find stored procedure either.即使我右键单击该过程并说脚本存储过程作为执行 - 它生成的代码用红色下划线标出并且也找不到存储过程。

This could happen if your stored procedure is invalid.如果您的存储过程无效,则可能会发生这种情况。 Please double-check the validity of the SPROC and ensure the tables it references exist, etc.请仔细检查 SPROC 的有效性并确保它引用的表存在等。

Try running your CREATE PROCEDURE.尝试运行您的 CREATE PROCEDURE。 Highlight it, f5 it, and then make sure it runs before you call it elsewhere.突出显示它,按 f5 键,然后确保它在其他地方调用之前运行。

Maybe in your procedure you've accidentally cut-pasted your script name (dbo.CopyTable), say something like...也许在您的程序中您不小心剪切了您的脚本名称 (dbo.CopyTable),请说类似...

SELECT * FROM dbo.CopyTable
WHERE ClientId = @ClientId
RETURN

Then when you call your proc you get 'invalid object name dbo.CopyTable' and assume sql is having trouble finding the stored-proc ... which isn't the problem, its finding and running the proc but its actually a problem within the proc.然后,当您调用您的 proc 时,您会得到“无效的对象名称 dbo.CopyTable”,并假设 sql 无法找到存储的 proc ……这不是问题,它找到并运行了 proc,但实际上是过程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM