<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'SQL Server 2012' and 'management studio'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=SQL+Server+2012,management+studio&amp;orTags=0</link><description>Search results matching tags 'SQL Server 2012' and 'management studio'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Why people think some SQL Server 2000 behaviors live on... 12 years later</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2012/02/28/why-people-think-some-sql-server-2000-behaviors-live-on-12-years-later.aspx</link><pubDate>Tue, 28 Feb 2012 16:57:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:41958</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;A long, long time ago in a galaxy you can reach out and touch right now, ORDER BY in a VIEW meant something. If you had a view like the following:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE VIEW &lt;/font&gt;&lt;font color="black"&gt;dbo.Rubbish&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT TOP &lt;/font&gt;&lt;font color="black"&gt;100 &lt;/font&gt;&lt;font color="blue"&gt;PERCENT &lt;/font&gt;&lt;font color="black"&gt;Trash&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;dbo.Garbage&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ORDER BY &lt;/font&gt;&lt;font color="black"&gt;Trash&lt;/font&gt;&lt;font color="gray"&gt;; &lt;br&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;

&lt;p&gt;And then you ran a query such as:&lt;/p&gt;
&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="black"&gt;Trash &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;dbo.Rubbish&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;

&lt;p&gt;You could reliably expect the rows to come back ordered by Trash in ascending order, even though it is relatively clear that the ORDER BY here serves a completely different and overloaded purpose - to dictate which rows should be filtered by TOP.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;When SQL Server 2005 came around, changes to the optimizer meant that this behavior - which was never documented, by the way, hence never guaranteed - ceased to work as reliably as it had in previous versions. In fact in this case the optimizer sees TOP 100 PERCENT and simply throws out both TOP and ORDER BY. Compare the differences in the plan from the view with and without the ORDER BY:'&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2012/02/12y_plans.png" border="1" height="581" width="538"&gt;&amp;nbsp;&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Notice how there is no sort operator in the query without ORDER BY? Because we didn't tell SQL Server what order we want, it's free to make its own choice. In this case it is choosing a clustered index scan which is not based on the Trash column. You can see the end result of the difference in these plans by comparing the results from the select:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2012/02/12y_results.png" border="1" height="352" width="330"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Obviously only the latter result honors the outer ORDER BY, and in fact both cases have discarded the inner TOP/ORDER BY combination.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;People are surprised by this change, and in fact &lt;a href="http://stackoverflow.com/questions/9445957/after-upgrade-of-sql-server-2000-database-to-sql-server-2008-the-view-is-not-sor/" title="http://stackoverflow.com/questions/9445957/after-upgrade-of-sql-server-2000-database-to-sql-server-2008-the-view-is-not-sor/" target="_blank"&gt;variations on the symptom&lt;/a&gt; come up in forum discussions all the time. Further to the confusion, that still exists today, early on there were some very vocal customers who screamed bloody murder and were very stubborn about changing their code to put the ORDER BY on the outermost query where it belongs. After upgrading to SQL Server 2005 they cried foul until Microsoft finally submitted - &lt;a href="http://support.microsoft.com/kb/926292" title="http://support.microsoft.com/kb/926292" target="_blank"&gt;creating a trace flag that forced the optimizer to behave the old way&lt;/a&gt;. Note that this trace flag is only valid in SQL Server 2005 and SQL Server 2008 - in SQL Server 2008 R2 and SQL Server 2012, the trace flag seems to be a no-op (at least in every case that I've tried). Even if you are still on 2005/2008, I highly recommend using this option as a last resort only, because it changes the way the optimizer works and this can have other undesirable impacts on your entire workload.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Hopefully none of this is news, as it has been discussed at length both online in general, and more specifically on Connect. Where it gets more interesting is that there have been several bugs reported that tools within Management Studio, such as the view designer, actually encourage this behavior and help perpetuate the myth. The issue I noticed this weekend is that, while most bugs have been closed as won't fix, &lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/249248/management-studio-generates-invalid-top-100-percent-order-by-in-views#tabs" title="http://connect.microsoft.com/SQLServer/feedback/details/249248/management-studio-generates-invalid-top-100-percent-order-by-in-views#tabs" target="_blank"&gt;one (#249248) has been closed as fixed&lt;/a&gt;. So I immediately fired up the latest build of Management Studio I have, right-clicked the views node, and selected New View. Once I added a table, what I saw was not very promising, as I was able to choose Sort Order and Sort Type:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2012/02/12y_view_designer.png" border="1" height="161" width="330"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So Management Studio for SQL Server 2012 still allows me to specify a sort order and sort direction for any column in the view! And what does it do to the SQL? It injects TOP 100 PERCENT / ORDER BY! Bad, bad, bad!&lt;/p&gt;

&lt;p&gt;On the plus side, if I try to *save* this view, I at least get some kind of warning:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2012/02/12y_dialog.png" border="0" height="244" width="497"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For Google/Bing-fu:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;Warning:  The ORDER BY clause is used only to determine the rows that
  are returned by the TOP clause in the view  definition. The ORDER BY
  clause does not guarantee ordered results when the view is queried,
  unless ORDER BY is also  specified in the query itself.   &lt;br&gt;Click CANCEL
  to discard your modifications.  &lt;br&gt;Click OK to save the view.&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's great that they're finally trying to stop people from believing that ORDER BY in a view means anything about ordering the result. But the problem that's being overlooked here is that not everyone uses the view designer to create and save a view in a single session. They may be generating code for a view that they're going to cut &amp;amp; paste into a CREATE/ALTER view script elsewhere, to use in a CTE or derived query in a more complicated script, or to send to a colleague. In a lot of cases they are never going to see this warning, because this won't magically pop up when they try to use the syntax in other scenarios.&lt;/p&gt;So I left a comment on the Connect item with a little detail about that, because I'm unfortunately going to have to disagree that this issue has been "fixed." I'm not sure why the Sort options in the view designer can't just be hidden without changing the behavior of the tool in general - can't it just always behave as if I hadn't changed those options at all?&lt;br&gt;&lt;p&gt;I do acknowledge that there are some edge cases here, where someone really does want to create a view that selects the top (n) rows ordered by some criteria. So perhaps my suggestion to remove the columns altogether is a bit harsh. But when I choose a Sort Order for one or more columns, it should not just throw TOP 100 PERCENT into my query; the query that's produced at this point shouldn't be valid. Instead it should prompt me with a similar warning to what I get now when I click Save, with additional wording that implies, "If you really do mean to take some subset of the rows in the table, please add a TOP (n) clause to indicate the number or percentage of rows you want to return."&lt;br&gt;
&lt;/p&gt;



&lt;p&gt;Agree with me? Please go &lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/249248/management-studio-generates-invalid-top-100-percent-order-by-in-views#tabs" title="http://connect.microsoft.com/SQLServer/feedback/details/249248/management-studio-generates-invalid-top-100-percent-order-by-in-views#tabs" target="_blank"&gt;comment and vote&lt;/a&gt;! &lt;br&gt;&amp;nbsp;&lt;br&gt;&lt;/p&gt;</description></item><item><title>T-SQL Tuesday #25 : T-SQL Tips 'n' Tricks</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2011/12/13/t-sql-tuesday-25-t-sql-tips-n-tricks.aspx</link><pubDate>Tue, 13 Dec 2011 18:50:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:40359</guid><dc:creator>AaronBertrand</dc:creator><description>
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/allen_white/archive/2011/12/05/t-sql-tuesday-025-invitation-to-share-your-tricks.aspx" title="http://sqlblog.com/blogs/allen_white/archive/2011/12/05/t-sql-tuesday-025-invitation-to-share-your-tricks.aspx" target="_blank"&gt;&lt;img src="http://sqlblog.com/files/folders/36686/download.aspx" style="padding:0px 30px 12px 30px;" align="right" border="0" height="135" width="135"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This month's T-SQL Tuesday is being hosted by Allen White (&lt;a href="http://twitter.com/SQLRunr" title="http://twitter.com/SQLRunr" target="_blank"&gt;@SQLRunr&lt;/a&gt;) and is about &lt;a href="http://sqlblog.com/blogs/allen_white/archive/2011/12/05/t-sql-tuesday-025-invitation-to-share-your-tricks.aspx" title="http://sqlblog.com/blogs/allen_white/archive/2011/12/05/t-sql-tuesday-025-invitation-to-share-your-tricks.aspx" target="_blank"&gt;sharing your T-SQL tips and tricks&lt;/a&gt;. Since I know many people will share their T-SQL magic and wizardry, I thought I would share a couple of productivity tips - so still T-SQL related, but more how to take advantage of some features in SSMS.&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="4"&gt;Drag column list onto your query window&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;Whenever I give my Bad Habits to Kick presentation, I remind people that - even if they're not using 3rd party code completion tools (many of which offer SELECT * expansion) - there's little excuse to use SELECT *. This is because Management Studio makes it very easy to list out all of your columns in one motion. I'm always amazed when I ask how many people didn't already know about this - and most times it's more than half the room. &lt;br&gt;&lt;/p&gt;
&lt;div&gt;The process is quite simple - expand your table, click on the Columns node, drag it onto your query window and let go:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/12/tst-1.png" border="0" height="284" width="721"&gt; &lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&lt;br&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/12/tst-2.png"&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;Now, it's probably not in the exact format you want, it won't properly delimit any [keyword] or [reserved word] you use for a column name, and you'll have to do this multiple times when you're performing a join (and you'll have to add your own table/alias prefixes to each column as well). But I'd rather spend time using TAB and ENTER to correct formatting than to try and type out all the column names individually.&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;&lt;font size="4"&gt;Use snippets&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;If you find yourself writing the same type of code over and over again, the new snippets feature in SQL Server 2012 will likely be very useful for you. What does this have over templates? For one, I find it much easier to use once you have your snippets created. There is no hokey VB6-style dialog to perform token replacements, and you can actually store all your custom snippets in a network location - so if you want to enforce coding standards you have a fighting chance by pointing everyone's SSMS at the same snippet location. I'll be honest, though, setting up the template is a bit of a pain - you need to hand-massage XML manually because as of yet there is no easy way to generate these from within Management Studio. But once they're in place, they're very easy to work with. Just right-click within the query window, choose "Insert Snippet", and follow the rabbit:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/12/tnt-3.png" border="0" height="148" width="697"&gt;&lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&amp;nbsp; &lt;br&gt;&lt;/div&gt;&lt;div&gt;One of the pieces of code I write a lot for administrative tasks (or for helping folks out in the wild) is a cursor. I tend to have a hard time memorizing the options I always try to use to make a cursor as efficient as possible (something else I cover in my Bad Habits to Kick presentation). The snippet eliminates this problem. Once I've selected the "Declare Cursor" snippet I've saved, I get the following in my query window:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/12/tnt-4.png" border="0" height="544" width="444"&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;You'll notice in the diagram that "c" is currently highlighted and the cursor is there; all other instances of "c" are lightly outlined. I can type any name I want to overwrite "c" and, once I hit tab (which moves me to the next token), it will replace all instances of that token with the new name I've typed. So this is a little easier to work with than the floating window in templates, though you lose this easy editing capability if you start doing other things with the script first (need to remind myself to file a bug or suggestion about that). Changing "c" to "x" throughout this code sample took two keystrokes, and I'm ready to add the actual query:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&lt;span style="text-decoration:line-through;"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/12/tnt-5.png" border="0" height="544" width="444"&gt;&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;

I plan to write a much more thorough blog post on the snippets feature, because I think it will become a pretty popular time saver once the latest version of Management Studio becomes more common on the desktop. In the meantime, if you're already playing with SQL Server 2012 RC0, I highly recommend you check this feature out!&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;font size="4"&gt;Avoid dynamic SQL in generated scripts&lt;/font&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;I see a lot of people complain that when they script objects from Management Studio the object text ends up in dynamic SQL. I don't blame them - this makes it very cumbersome to read, never mind modify, the object text before copying, running or saving the script.&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;In SQL Server 2008 R2, this is controlled by the option Tools &amp;gt; Options &amp;gt; SQL Server Object Explorer&amp;gt; Scripting &amp;gt; Include IF NOT EXISTS clause:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;div style="margin-left:40px;"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/12/tnt-6a.png" border="0" height="440" width="610"&gt;&lt;br&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;In SQL Server 2012, the option has changed slightly to Tools &amp;gt; Options &amp;gt; SQL Server Object Explorer &amp;gt; Scripting &amp;gt; Check for Object Existence:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/12/tnt-7a.png" border="0" height="440" width="636"&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br&gt;Why did it change? Because, depending on the action, it actually performs an IF EXISTS check (e.g. for a DROP or ALTER), not always an IF NOT EXISTS check (for a CREATE). Some background in the following Connect items:&lt;br&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/242799" title="http://connect.microsoft.com/SQLServer/feedback/details/242799" target="_blank"&gt;http://connect.microsoft.com/SQLServer/feedback/details/242799&lt;/a&gt; &lt;br&gt;&lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/264310" title="http://connect.microsoft.com/SQLServer/feedback/details/264310" target="_blank"&gt;http://connect.microsoft.com/SQLServer/feedback/details/264310&lt;/a&gt;&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="margin-left:40px;"&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/624075" title="http://connect.microsoft.com/SQLServer/feedback/details/624075" target="_blank"&gt;http://connect.microsoft.com/SQLServer/feedback/details/624075&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;(As an aside, I think it's funny that they call the options category "SQL Server Object Explorer" - good thing they're specific, because you might get it confused with the Lego Object Explorer, Oracle Object Explorer or Windows Explorer Object Explorer.)&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;In any case, when these options are set to True, the scripts you generate often yield dynamic SQL, and even when they're set to false they still sometimes perform the check for existence (specifically in 2008 R2). Here is a brief wireframe of the options and how they affect each scripting method:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;div style="margin-left:40px;"&gt;&lt;img src="http://bertrandaaron.files.wordpress.com/2011/12/tnt-8.png" border="1" height="243" width="784"&gt;&amp;nbsp;&lt;br&gt;&lt;/div&gt;
&lt;p&gt;Note that with the "DROP and CREATE" option, the existence check for the CREATE is unnecessary - after all, if the object already exists, the script should have just dropped the object (though both checks may have failed if there is an object with the same name that is *not* a procedure). In general, most people won't want to perform a DROP and CREATE anyway - they lose dependencies and permissions when they do this (though permissions can be scripted with a different option in the same category). Until they develop "CREATE or REPLACE" functionality (&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/127219/create-or-replace" title="Connect #127219 : Create or Replace" target="_blank"&gt;please vote and comment!&lt;/a&gt;), ideally you should have a script that creates a stub for the object only if it doesn't already exist, then runs an ALTER - then you don't have to re-apply permissions, you don't have to worry about whether the object already exists, and as an added bonus you retain dependency chains. So your scripts can look like this (still using dynamic SQL, but it's very simple and doesn't present parsing or reading issues):&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;IF &lt;/font&gt;&lt;font color="magenta"&gt;OBJECT_ID&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="red"&gt;'dbo.proc_name'&lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font color="gray"&gt;IS NULL&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;EXEC &lt;/font&gt;&lt;font color="darkred"&gt;sp_executesql &lt;/font&gt;&lt;font color="red"&gt;N'CREATE PROCEDURE dbo.proc_name AS SELECT 1;'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;br&gt;GO&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;ALTER PROCEDURE &lt;/font&gt;&lt;font color="black"&gt;dbo.proc_name&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;/font&gt;&lt;font color="green"&gt;&lt;br&gt;... -- actual script body from source control or elsewhere goes here&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Unfortunately there is no way to train SSMS to do this today, unless you write a scripting add-in.&lt;br&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;&lt;font size="4"&gt;Wrapping up&lt;/font&gt;&lt;br&gt;&lt;br&gt;I hope that at least one of these little tricks helps you in some way. It's always fun participating in T-SQL Tuesday, even if I'm often trying to bend the rules a little bit.&lt;br&gt;&amp;nbsp;&lt;br&gt;&lt;/p&gt;</description></item></channel></rss>