简体   繁体   English

是否可以在SSMS中修改“变更程序”模板?

[英]Is it possible to modify the “alter procedure” template in SSMS?

I know how to modify " CREATE PROC " templates in SSMS, and I wonder if I can modify the " ALTER PROC " template, which shows when I right-click on an existing stored procedure and click "Modify". 我知道如何在SSMS中修改“ CREATE PROC ”模板,并且我想知道是否可以修改“ ALTER PROC ”模板,该模板在我右键单击现有存储过程并单击“修改”时显示。 When I click "Modify", a script "ALTER PROC ..." will be generated, I hope I can modify this so it can generate 当我单击“修改”时,将生成脚本“ ALTER PROC ...”,希望我可以对其进行修改以便生成

IF EXISTS ()... DROP PROC ... CREATE PROC ...

instead of 代替

ALTER PROC

Alternatively, if I can create a new template to achieve the same goal, that would be good too. 另外,如果我可以创建一个新模板来实现相同的目标,那也很好。

Thanks. 谢谢。

I don't think there is, but you can get pretty close to faking it. 我认为没有,但是您可以接近于伪造它。 Create a snippet (in my version of SSMS, there's a Code Snippet Manager in the Tools menu) for the "if exists... drop" part. 为“如果存在...删除”部分创建一个代码段(在我的SSMS版本中,“工具”菜单中有一个代码段管理器)。 Now, script your procedure, insert your snippet at the top and you should be good to go. 现在,编写您的过程的脚本,在您的代码段的顶部插入,您应该一切顺利。

I would be remiss if I didn't mention that dropping a procedure drops any explicit permissions that have been granted or denied on it. 如果我没有提到删除过程会丢弃任何已授予或拒绝的明确权限,那我将是失职。 If you're doing this so that you get an idempotent script, I've adopted this idiom to avoid that problem: 如果您这样做是为了获得幂等脚本,那么我采用了这个惯用法来避免该问题:

if object_id('someSchema.yourProc') is not null
   set noexec on;
go
create procedure someSchema.yourProc
as
   print 'not yet implemented'
go
set noexec off;
go
alter procedure someSchema.yourProc as
begin
   -- your actual proc
end

Yes, In modify option, you can directly modify or alter prc as 是的,在修改选项中,您可以直接将prc修改或更改

ALTER PROCEDURE [dbo].[sp_name]
  @paramater INT , .... other
AS
BEGIN
   .... statement
END

What the good thing in below option, is when you give to some one or deploy on server. 下面的选项中的优点是,当您同意某个选项或在服务器上进行部署时。 Its good to give below type of statement. 在下面给出声明的类型很好。

Which first verefiy that Procedure exist or not, if exist then it first drop and then create. Procedure是否存在哪个第一个验证,如果存在,则首先删除然后创建。

IF EXISTS ()... DROP PROC ... CREATE PROC ...

Modify option means right-click and modify which directly give, alter option which is good for development purpose. 修改选项是指右键单击并直接修改,即给出适合开发目的的修改选项。 You know while development like alter table or change sp parameter name. 您知道在开发诸如alter table或更改sp参数名称时。 that also include when you give to someone with current sp. 这还包括当您向具有当前sp。

While to give some one , good to drop and create with exist option, so third party easily execute without error. 在给某一个选项时,最好使用存在选项拖放创建,因此第三方可以轻松执行而不会出错。

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

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