简体   繁体   English

如何在服务器资源管理器中将新的存储过程保存到正在使用的数据库中?

[英]How can I save a new Stored Procedure to the database I'm working with in Server Explorer?

In Server Explorer (within Visual Studio) I can expand a database, right click on the Stored Procedures folder, and select "Add New Stored Procedure" 在服务器资源管理器(在Visual Studio中)中,我可以展开数据库,右键单击“存储过程”文件夹,然后选择“添加新的存储过程”

I can then add an SP and try to execute it. 然后,我可以添加一个SP并尝试执行它。 However, when I try to save the Stored Procedure (so that it will be subsequently available in the list of Stored Procedures for that database), it gives it the generic name "dbo.Procedure.sql*", even though I gave it another name, such as: 但是,当我尝试保存存储过程(以便以后可以在该数据库的存储过程列表中使用)时,即使我给了它另一个名称,它也给它提供了通用名称“ dbo.Procedure.sql *”。名称,例如:

CREATE PROCEDURE [dbo].[duckbilledPlatypiOfIowa]

When the save dialog displays (wanting to save the .sql file to my Documents folder), I can rename it what I want, but it is not available in the list of Stored Procedures in the database. 当显示保存对话框时(希望将.sql文件保存到我的Documents文件夹中),我可以将其重命名为所需名称,但是在数据库的存储过程列表中不可用。

How can I get it to be available there? 我如何才能在那里找到它?

Note: If I right-click the Stored Procedure pane and select "copy path" (or some such), I do get what seems valid, namely: 注意:如果我右键单击“存储过程”窗格,然后选择“复制路径”(或某些类似路径),则可以得到看起来有效的内容,即:

MSSQL::/PROSQL42/PlatypusData/sa/SqlProcedure/dbo.Procedure.sql

But again, you see the generic "dbo.Procedure.sql" name. 但是,您再次看到通用的“ dbo.Procedure.sql”名称。 Yet no "dbo.Procedure.sql" displays in the list of Stored Procedures after saving, either. 保存后,“ dbo.Procedure.sql”也不会显示在存储过程列表中。

So again, what do I need to do to save my new Stored Procedure into the database I'm working with? 因此,再次需要做些什么来将新的存储过程保存到正在使用的数据库中?

   CREATE PROCEDURE [dbo].[duckbilledPlatypiOfIowa]

and the definition that follows is the TSQL which will 'save' it to the database. 然后是TSQL,它将“保存”到数据库中。

If you run that line again, you should get an error saying that it already exists. 如果再次运行该行,则应该得到一条错误消息,表明它已经存在。

To verify that it does, right-click the 'Stored Procedures' node and choose 'Refresh'. 要验证它是否正确,请右键单击“存储过程”节点,然后选择“刷新”。

If it doesn't appear in the database you think you're working with, check the connection of the window you're in. 如果它没有出现在您认为正在使用的数据库中,请检查您所在窗口的连接。

To be sure, add 可以肯定的是,添加

USE [DatabaseName]
GO

Before executing your CREATE PROCEDURE [dbo].[duckbilledPlatypiOfIowa] 在执行CREATE PROCEDURE [dbo].[duckbilledPlatypiOfIowa]

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

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