How to format a SQL query automatically with a free online service?
Format a SQL query automatically can be time-consuming and tedious, especially on existing projects that are not developed according to the rules of the art. There is a useful website that allows you to format SQL queries. Indeed, it is aimed at SQL development engineers, DBAs, and in general all SQL developers. It supports various SQL languages.
How to format a SQL Server query automatically?
It also allows you to format the SQL code of many database management system (DBMS) editors. Indeed, the site does not only manage SQL Server, but other editors. Here is the current list:
- Microsoft Transact-SQL
- Microsoft ACCESS
- Oracle PL/SQL
- The MDX language
- And also Generic SQL
Also, be aware that your code may contain sensitive information or intellectual property secrets.
Use only with knowledge or with queries that do not require very expensive engineering. The site does save a lot of time with automatic formatting, but could record all the requests sent.
Using the DPRiver site to format SQL queries
Use the dpriver site and its Instant SQL Formatter tool to format SQL code for free. An interesting option is that it offers formatting with many output formats, such as HTML to highlight the code. But also several programming languages like PHP, C#, Java, Delphi, VB among others and even XML output.
For non-SQL programming languages, these are variables instantiated with the query code. For example, this SQL Server code for inserting and selecting customers, written in T-SQL.
-- insert data for manipulation examples insert into dbo.clients ( name, city ) values ( n'mammadou', 'lyon'); insert into dbo.clients ( name, city ) values ( n'sergei', 'lyon'); insert into dbo.clients ( name, city ) values ( n'christophe', 'paris'); -- check inserted rows select [noclient],[name],[city] from dbo.clients;
Will become the output of the automatic formatting site for this query, with some options enabled such as capitalization of table, column and keyword names.
-- insert data for manipulation examples INSERT INTO dbo.CLIENTS (NAME, CITY) VALUES ( n'Mammadou', 'Lyon'); INSERT INTO dbo.CLIENTS (NAME, CITY) VALUES ( n'Sergei', 'Lyon'); INSERT INTO dbo.CLIENTS (NAME, CITY) VALUES ( n'Christophe', 'Paris'); -- check inserted rows SELECT [NOCLIENT], [NAME], [CITY] FROM dbo.CLIENTS;
If the conditions are not satisfactory in terms of security, then formatting the code by hand and with the open source software Notepad++ for example is a very good alternative.
A paid Add-In for SSMS is also available
SQL Pretty Printer is an Add-In for SQL Server Management Studio. The license costs 50$ and allows to integrate automatic formatting directly into the SSMS menu. It is therefore possible to standardize your SQL code in one click.