IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact

Format SQL Using Redgate SQL Prompt

As a follow-up of the post String Literals as Column Aliases are Deprecated, this one feature from Redgate’s SQL Prompt is quite handy to correct any existing SQL scripts quickly.

Using the SQL from How to Find All References to an Object in a SQL Server Database as an example, here’s what we originally have:

SELECT DISTINCT OBJECT_NAME(m.object_id) AS 'object name', m.*
FROM sys.sql_modules m
WHERE m.definition LIKE '%Customer_Name%'

Pay attention to the object name within the single quotes as a column alias.

If this is only a one-off such as this one, it’s no sweat to fix it manually, but what happens if you have a long query with multiple lines of column aliases that you want to fix?

If you have Redgate SQL Prompt, you just need to set it once in the Options as shown below:

  1. In SSMS, go to SQL Prompt on the top menu, and select Options.

    Redgate SQL Prompt Options from SSMS menu

  2. In the Options window, go to Format, Styles. Under Actions, check Apply column alias style and select column AS “alias”, then click OK.

    Redgate SQL Prompt Format Styles column as alias

You’re done with the configuration.

How do you use it?

The best way to use it is by using a keyboard shortcut.

If you click on the SQL Prompt from the menu again, you’ll see an option for Format SQL with a shortcut CTRL+K, CTRL+Y.

Redgate SQL Prompt Options from SSMS menu

In your query window where you have the SQL you want to fix, just use the keyboard shortcut (or you can do that from the menu as well) and right away, it will reformat the query with the fix:

SELECT DISTINCT
       OBJECT_NAME(m.object_id) AS "object name",
       m.*
FROM sys.sql_modules m
WHERE m.definition LIKE '%Customer_Name%';

This is one of the useful features in SQL Prompt to make your life easier. If you notice from the screenshots above, the top bar also has a red color to indicate that it is a production database. It’s a nice way to color code different database environment that can also be configured in SQL Prompt.

Further Reading

How to Use Custom Color in SSMS Using Redgate SQL Prompt

Download

Redgate SQL Prompt (FREE Trial)

December 14, 2022 Filed Under: How To Tagged With: Microsoft SQL Server, SQL, SQL Server

Buy me a coffee?

Buy me a coffee If you find any of the articles or demos helpful, please consider supporting my work here, you'll have my big thanks!

Buy me a coffee Support this site
Buy Me a Coffee?

Categories

  • .NET
  • Coding
  • Cybersecurity
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Programming
  • Resources
  • Review
  • Tips and Tricks
  • Uncategorized
  • Use Case
  • WordPress
  • Writing

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Tags

.NET .NET Core AdSense ASP.NET Cdonts Dll Classic ASP Code Editor ETL FSharp Genesis Framework Git Google HP Asset Manager HTML5 Hugo IIS Information Security Internet Internet Information Services iOS JAMStack Linux macOS Microsoft Microsoft SQL Server MVC PHP PowerShell Python Simple Mail Transfer Protocol Smtp Server SQL SQL Server SSIS SSMS SSRS Sublime Text Visual Studio Visual Studio Code VPN Windows Windows 8 Windows 10 Windows 2012 Windows Server

Copyright © 2011-2025 IT Nota. All rights reserved. Terms of Use | Privacy Policy | Disclosure