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

Related posts

Also in Hub

How to Customize Schema Comparisons using Auto Map in SQL Compare

It's a tedious task to have to compare two versions of a SQL script, side by side, for example to find differences between the version of the script on Production, and the one on the Test system. As a...

Also in Product learning

SQL Prompt Hidden Gem: Auto-fill the GROUP BY clause

"Have you seen this new feature that auto-fills the GROUP BY with non-aggregated columns!" exclaimed my co-worker, soon after she had installed a new version of SSMS. I hadn't, but I was intrigued. I ...

Also in SQL Prompt

A day in the life of a developer with SQL Prompt

I've a a busy day ahead of me, working on a new reporting query, plus reviewing some initial database designs for the team. We've done the morning stand-up meeting, I've had my morning coffee, SQL Ser...

Also about SQL Prompt

Templates and Snippets in SSMS and SQL Prompt

In SSMS, we have access to templates that provide building blocks for creating various types of query, common routines to create various schema objects, or to do common DBA tasks such as running backu...