Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7970953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:31:28+00:00 2026-06-04T07:31:28+00:00

I realise this is a very similar question to Stop SSMS from scripting SPs

  • 0

I realise this is a very similar question to Stop SSMS from scripting SPs using sp_executesql?

However, they seem to have changed the behaviour with SSMS 2012.

If you have the ‘Check for existence’ option selected, as in:

enter image description here

… it now generates an IF NOT EXISTS for the proc about to be created, as well as an IF EXISTS for the previous drop proc, if, as I usually do, I select the DROP and CREATE option:

enter image description here

This forces it to script the CREATE using sp_executesql. It’s pointless, since you don’t need the IF NOT EXISTS check on the CREATE, if the DROP has just dropped it.

It doesn’t seem possible to have the one without the other.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:31:29+00:00Added an answer on June 4, 2026 at 7:31 am

    You can’t do this without the dynamic SQL because a stored procedure has to be in its own batch. Therefore you can’t say:

    IF <some condition>
      <start a new batch>
    

    The only way to keep that in the same batch is to use sp_executesql.

    If you’re going to script the DROP and CREATE simultaneously, just do it without the check for object existence. This will give you:

    DROP PROCEDURE ...;
    GO
    CREATE PROCEDURE ...;
    GO
    

    Who cares if the DROP fails? (It shouldn’t, because you just scripted from it!)

    If you’re scripting this for another system that might have the object, you’ll get an error message for the DROP when it doesn’t, but the CREATE will still happen, so you can ignore the DROP errors. If you really want you can manually wrap the DROP statements in TRY/CATCH but I don’t think it’s necessary.

    If you need to do this for a lot of procedures, or if you really need the process to not generate benign errors, I suggest you abandon Management Studio’s primitive scripting options and use a 3rd party tool for this. They’ll have already dealt with many of the issues you haven’t yet come across, but will. I blogged about this:

    http://bertrandaaron.wordpress.com/2012/04/20/re-blog-the-cost-of-reinventing-the-wheel/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, I realise that this is a very similar question to this one: Which
This question may seem blindingly obvious and I realise I am putting myself up
Very similar to this question , I'd like to be able to drag and
I realize this is very similar to this question: how to set windows service
I realize this is more of a hardware question, but this is also very
I realise this might be hard to explain, so let me start by using
This is a bit of a vague question I realise, but I've been looking
Greeting to the community. This is my very first question. I had in mind
I can't seem to find the answer to this question anywhere. I realize that
I realise this is very basic but i need a quick way of referencing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.