30 November 2016
30 November 2016

Quickly rename variables all at once with SQL Prompt

You’re going to run into situations where someone has made poor choices in naming objects, or maybe the business logic has changed and the object name no longer makes sense. Either way, easily and quickly taking care of renaming the objects within scripts can be a pain.

Let’s take this code as an example:

SQL Prompt renaming objects 1

The table variable @a is a poor choice, so I want to replace it. Yes, I can do a search and replace to try to find it and replace it within the code, but SQL Prompt offers an alternative that is both easier and, depending on if you want to review the code as you change it, faster.

I can highlight any use of the variable @a and press the function key F2. This then highlights every use of that variable:

SQL Prompt renaming objects 2

If I start typing, I can rename the object, quickly and easily, and it renames everywhere at the same time:

SQL Prompt renaming objects 3

If I hit the Enter key, that gets committed to the code. However, if I hit the escape key, ESC, the changes are removed from script and it reverts back to what it was originally.

That’s it – a quick tip to help you make your code cleaner and more readable in a couple of clicks with SQL Prompt.

Take a look at my video below, or browse the rest of the handy #SuperSQLTips videos from other Data Platform MVPs and SQL Server experts, helping you get the most out of SQL Prompt:

If you’re new to SQL Prompt check it out for yourself with a free 28-day trial and see how much more productive you can be writing code every day.

Like this? Share it with other SQL professionals using the social sharing buttons below – and don’t forget to give me a shoutout @GFritchey. Thanks for reading.

 

Tools in this post

SQL Prompt

Write, format, and refactor SQL effortlessly in SQL Server Management Studio and Visual Studio.

Find out more

Share this post.

Share on FacebookShare on Google+Share on LinkedInTweet about this on Twitter

You may also like

  • Article

    Quick extended properties with SQL Prompt

    I’ve been experimenting with Extended Properties, and I found myself slightly annoyed by the syntax of adding and updating Extended Properties. I decided to take advantage of SQL Prompt to store the commonly used code for adding and updating properties. Adding Properties I’m a big fan of naming the snippets the first thing that comes to mind.

  • Article

    Avoid use of the MONEY and SMALLMONEY datatypes

    The MONEY data type confuses the storage of data values with their display, though its name clearly suggests the sort of data it holds. It is proprietary to SQL Server and allows you to specify monetary values preceded by a currency symbol, but SQL Server doesn’t store any currency information at all with the actual

  • Article

    How to Test SQL Server Functions and Procedures using SQL Prompt

    When writing functions or procedures, a common chore is to devise and implement the tests that ensure that the routine always works as expected. The best way to do this is to define the tests in a batch that is attached to the CREATE or ALTER script. This isn’t just to prevent you from making

  • Article

    Cleaning up common T-SQL coding issues with SQL Prompt

    Some SQL coding habits are just annoying. Commas in front of column names? No way! Others are actively harmful; they’ll make your code error prone, harder for others to read and understand, and even harder to edit without making mistakes. This article covers five harmful problems that I see regularly in T-SQL code, and shows

  • Article

    3 Results Grid features SQL Prompt brings to SSMS

    You may not have heard about it yet, but three helpful features were recently added to SQL Prompt that are activated when you right-click on the Results Grid in SQL Server Management Studio (SSMS). 1. Copy as IN clause This feature is available when you have values from a single column selected. You can select

  • Forums

    SQL Prompt Forum

    Write, format, and refactor SQL effortlessly