简体   繁体   English

SQL Server Management Studio中未显示带有可选参数的存储过程“执行存储过程”或“脚本存储过程”

[英]Stored procedure with optional parameter that doesn't show in SQL Server Management Studio “execute stored procedure” or “script stored procedure”

In SQL Server Management Studio (SSMS), you can execute a stored procedure using the GUI for assistance. 在SQL Server Management Studio(SSMS)中,可以使用GUI执行存储过程以获得帮助。 This can done by right-clicking on the stored procedure in the Object Explorer and selecting either "Execute Stored Procedure" or "Script Stored Procedure as > CREATE to > New Query Editor Window". 可以通过在对象资源管理器中右键单击存储过程,然后选择“执行存储过程”或“脚本存储过程为>创建为>新建查询编辑器窗口”来完成此操作。

Both of these result in a pre-built SQL query to execute the SP, and both of them include optional parameters from the SP. 两者都导致执行SQL的预构建SQL查询,并且两者都包含来自SP的可选参数。 Is there a way to make it so the optional parameters are "hidden"? 有没有一种方法可以使可选参数“隐藏”?

I have some user support folks who use SSMS to run certain SPs, and I don't want them providing values for certain optional parameters. 我有一些使用SSMS来运行某些SP的用户支持人员,但我不希望他们为某些可选参数提供值。 I want to be able to provide them myself, if needed, when I run the SP, but not the user support people. 如果需要,我希望能够在运行SP时自己提供它们,但不能提供用户支持人员。

I've tagged SQL Server 2014 and 2008 R2 in case there's some option I can set in the SP itself. 我已经标记了SQL Server 2014和2008 R2,以防SP本身可以设置某些选项。

You could wrap your stored procedure with another: 您可以将存储过程与另一个包装在一起:

CREATE PROCEDURE dbo.my_orig_proc
    @id INT
   ,@some_param_default INT = 10

AS
BEGIN
...
END

Wrapper: 包装:

CREATE PROCEDURE dbo.my_wrapper_proc
   @id INT
 AS
 BEGIN
     EXEC dbo.my_orig_proc @id;
 END

I would also restrict access to orignal procedures if necessary. 如有必要,我还将限制使用原始程序。


Another way is to add check and don't allow specific user to override value: 另一种方法是添加检查,不允许特定用户覆盖值:

CREATE PROCEDRUE dbo.my_orig_proc
   @id INT,
   ,@some_param_default INT = 10
AS
BEGIN
   IF USER_NAME() = 'user_name' AND @some_param_default <> 10
      RAISERROR('You cannot change @some_param_default value' ,16,1);
END

Drawback: You need to change parameter value in two places and if user has impersonate privilige he still can execute it. 缺点:您需要在两个位置更改参数值,并且如果用户具有模拟权限,他仍然可以执行它。

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

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