简体   繁体   中英

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". When I click "Modify", a script "ALTER PROC ..." will be generated, I hope I can modify this so it can generate

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. 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

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.

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. that also include when you give to someone with current sp.

While to give some one , good to drop and create with exist option, so third party easily execute without error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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